×
Home > Blog > How to set up a WAMP server

How to set up a WAMP server

written March 05 2024

The premise must be stated: Windows is not the most suitable OS for an Apache-MariaDB/MySQL-PHP stack.
With the same sincerity, we can state that it is possible to configure it with satisfactory results.

To get an idea of how common this practice is, downloads of software such as XAMPP, WampServer and Laragon range from 500,000 to 1,000,000 each week! from SourceForge


In our case study, we will proceed with simplicity, awareness and transparency, to the configuration of a solid development environment, avoiding reliance on generic preset solutions, sometimes insidious to security.


Software


Let's proceed step by step starting with downloading the software.

To make easy installation and updating we recommend the use of Scoop, below are the Powershell commands to install it.


Alternatively, we will link to the sources that Scoop itself uses.


Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser
Invoke-RestMethod -Uri https://get.scoop.sh | Invoke-Expression

Right afterwards we will launch the terminal as administrator and install a tool typical of Unix systems


scoop install -g main/sudo

For convenience we will define a path to be used as the basis for software, a kind of Program folder created by us:



  • C:\env\


For software downloaded with Scoop -g (global), the folder will be:



  • C:\ProgramData\scoop\


Certificates will be needed to use the web server with ssl, as we recommend below.

It's possible to create them with openssl or write a selfsigned version from here


1a. Apache


The website Apache Lounge offers compiled binaries of the web server and several modules.

We need:




Scoop command:



sudo scoop install -g main/apache

# installiamo il service
sudo C:\ProgramData\scoop\apps\apache\current\bin\httpd.exe -k install -n "Apache2"

We extract the FastCGI module in:



  • C:\env\lib\apache\mod_fcgid.so


2a. MariaDB


Born as a fork of the famous MySQL, it has gradually replaced it in Linux based systems due to its more 'community driven' nature.

While retaining backward compatibility, its features have grown exponentially and to date it is our choice.
In any case, you are free to install MySQL, the next steps should be fine.




Scoop command:



sudo scoop install -g main/mariadb

# if it does not happen automatically:
sudo mysql_install_db --service=MariaDB --password=PASSWORD

3a. PHP


If for previous software we deliberately decided to use the latest version, with PHP we will go further!

We will use two versions at the same time, differentiating them in the Apache .conf. For older web-apps we will use PHP 7.4, for newer ones PHP 8.1.
In this case we recommend to NOT using Scoop and proceeding manually.centi PHP 8.1 .

Scoop uses the variable PHP_INI_SCAN_DIR which compromises the correct use of multiple PHP versions in development IDEs.



As you may have noticed, two different versions of PHP are compiled: TS and NTS.

The main difference is that the TS ( Thread-safe ) version works natively in a multi-threaded web server context but is a more resource-intensive approach.

We do not have this need because we are going to use PHP via FastCGI, making code execution visibly faster!

This is a valuable advantage not always present in preconfigured packages (see XAMPP).
Another important implementation concerns the php_ssh2 library. We can download the appropriate version from:



We extract the PHP archives respectively in:



  • C:\env\bin\php74nts

  • C:\env\bin\php81nts


And the libraries in:



  • C:\env\lib\php74nts

  • C:\env\lib\php81nts


Same operation if you want to use Xdebug. Find the appropriate version here:



Configuration


The necessary software is ready but the trickiest part will be the configuration of Apache + PHP + FastCGI.


1b. Apache


Having downloaded the web server with Scoop -g, we will find the conf files in:



  • C:\ProgramData\scoop\apps\apache\current\conf


The following is the list of lines to be edited/uncommented



httpd.conf



...
Define SRVROOT "C:/ProgramData/scoop/apps/apache/current"
Define SRVCONF "C:/ProgramData/scoop/persist/apache/conf"
Define SRVBIN "C:/env/bin"
Define SRVETC "C:/env/etc"
Define SRVLIB "C:/env/lib"
Define SRVPOSTMASTER "MAIL@PROVIDER.com"
define SRVSSL "C:/env/etc/ssl"

ServerRoot "${SRVROOT}"
...
LoadModule access_compat_module modules/mod_access_compat.so
LoadModule http2_module modules/mod_http2.so
LoadModule headers_module modules/mod_headers.so
LoadModule rewrite_module modules/mod_rewrite.so
LoadModule setenvif_module modules/mod_setenvif.so
LoadModule socache_shmcb_module modules/mod_socache_shmcb.so
LoadModule ssl_module modules/mod_ssl.so
...
ServerAdmin ${SRVPOSTMASTER}
...
# optional
ServerName www.server.test:80
...
Options Indexes FollowSymLinks Includes ExecCGI
...
DirectoryIndex index.html index.php
...
Include conf/extra/httpd-mpm.conf
...
Include conf/extra/httpd-default.conf
...
Include conf/extra/httpd-ssl.conf

# end of the file

AcceptFilter http none
AcceptFilter https none
EnableSendfile Off
EnableMMAP Off

IncludeOptional "${SRVCONF}/sites-enabled/*.conf"

LoadModule fcgid_module "${SRVLIB}/apache/mod_fcgid.so"


extra/httpd-ssl.conf



# optional
ServerName www.server.test:443
ServerAdmin ${SRVPOSTMASTER}
...
SSLCertificateFile "${SRVSSL}/www.server.test.pem"
SSLCertificateKeyFile "${SRVSSL}/www.server.test.key"

The following conf is a template that will be loaded from the virtualhost in sites-enabled.

Each web-app may have differences, but they will work.



vhost_template.conf




DocumentRoot "${ROOT}"
ServerName ${SITE}
ServerAlias ${ALIAS}


FcgidInitialEnv PATH "${SRVBIN}/${PHP};C:/Windows/system32;C:/Windows;C:/Windows/System32/Wbem;"
FcgidInitialEnv SystemRoot "C:/Windows"
FcgidInitialEnv SystemDrive "C:"
FcgidInitialEnv TEMP "C:/Windows/Temp"
FcgidInitialEnv TMP "C:/Windows/Temp"
FcgidInitialEnv windir "C:/Windows"
FcgidIOTimeout 3600
FcgidConnectTimeout 16
FcgidMaxRequestsPerProcess 0
FcgidMaxProcesses 50
FcgidMaxRequestLen 8131072
FcgidInitialEnv PHPRC "${SRVBIN}/${PHP}"
FcgidInitialEnv PHP_FCGI_MAX_REQUESTS 0



AllowOverride All
Require all granted

"
AddHandler fcgid-script .php
Options +ExecCGI
FcgidWrapper "${SRVBIN}/${PHP}/php-cgi.exe" .php





DocumentRoot "${ROOT}"
ServerName ${SITE}
ServerAlias ${ALIAS}


FcgidInitialEnv PATH "${SRVBIN}/${PHP};C:/Windows/system32;C:/Windows;C:/Windows/System32/Wbem;"
FcgidInitialEnv SystemRoot "C:/Windows"
FcgidInitialEnv SystemDrive "C:"
FcgidInitialEnv TEMP "C:/Windows/Temp"
FcgidInitialEnv TMP "C:/Windows/Temp"
FcgidInitialEnv windir "C:/Windows"
FcgidIOTimeout 3600
FcgidConnectTimeout 16
FcgidMaxRequestsPerProcess 0
FcgidMaxProcesses 50
FcgidMaxRequestLen 81310720
FcgidInitialEnv PHPRC "${SRVBIN}/${PHP}"
FcgidInitialEnv PHP_FCGI_MAX_REQUESTS 0



AllowOverride All
Require all granted

"
AddHandler fcgid-script .php
Options +ExecCGI
FcgidWrapper "${SRVBIN}/${PHP}/php-cgi.exe" .php



SSLEngine on
SSLCertificateFile ${SSL}.pem
SSLCertificateKeyFile ${SSL}.key



Following an example of virtualhost.conf

Having isolated the common directives in the template, a few lines of define will have to be specified for each site, and it will be possible to use the desired PHP version:



  • define PHP "php74nts"

  • define PHP "php81nts"



sites-enabled/www.app.test.conf



define ROOT "C:/env/www/app/public"
define SITE "www.app.test"
define ALIAS "app.test"
define PHP "php81nts"
define SSL "${SRVSSL}/www.app.test"

Include "${SRVCONF}/vhost_template.conf"

1b. PHP


In the php81nts directory there are 2 configuration templates, one for production and the other development-oriented.

Siete liberi di scegliere su quale delle 2 effetturare le modifiche.

Let's copy php.ini-development or php.ini-production in php.ini and edit the following variables:



php.ini



max_execution_time = 3600
...
max_input_vars = 5000
...
memory_limit = 256M
...
post_max_size = 512M
...
# on Windows we must specify the full path of the extensions
extension_dir = "C:/env/bin/php81nts/ext"
...
upload_max_filesize = 256M
...
extension=bz2
extension=curl
;extension=ffi
extension=ftp
extension=fileinfo
extension=gd
extension=gettext
extension=gmp
extension=intl
extension=imap
;extension=ldap
extension=mbstring
extension=exif ; Must be after mbstring as it depends on it
extension=mysqli
;extension=oci8_12c ; Use with Oracle Database 12c Instant Client
;extension=oci8_19 ; Use with Oracle Database 19 Instant Client
extension=odbc
extension=openssl
;extension=pdo_firebird
extension=pdo_mysql
;extension=pdo_oci
extension=pdo_odbc
;extension=pdo_pgsql
extension=pdo_sqlite
;extension=pgsql
;extension=shmop

; The MIBS data available in the PHP distribution must be installed.
; See https://www.php.net/manual/en/snmp.installation.php
;extension=snmp

extension=soap
;extension=sockets
extension=sodium
extension=sqlite3
;extension=tidy
extension=xsl

zend_extension=opcache

extension=C:/env/lib/php81nts/php_ssh2.dll
...
date.timezone = "Europe/Rome"
...
session.gc_maxlifetime = 7200

Similar modifications will also work for PHP 7.4.


In conclusion


Having used the 'www.app.test' domain, we will have to update our C:\Windows\System32\drivers\c\hosts file manually or with software such as PowerToys.

Alternatively, you can use a local DNS server such as Pi-Hole.


In addition, tools such as Composer and testing frameworks such as PHPUnit

after adding on the Windows environment variable path the directory C:\env\bin\php81nts

This site use cookies. By navigating in this site you accept our cookie policy. Click here for more information. Accept cookies from this site