I usually use the portable version of XAMPP on Windows. Previously, I used to install the portable version of XAMPP for each PHP version separately, but since I don’t use the MySQL (MariaDB) or Perl (Strawberry Perl) bundled with XAMPP and instead install them separately, only Apache is launched from XAMPP.
However, with each PHP version upgrade, it became cumbersome to unzip and arrange XAMPP, leading to an accumulation of unused files and inconvenience in transferring or switching configurations. Moreover, recently, new PHP versions have been released less frequently.
Therefore, I researched and tried to see if a similar method could be applied on Windows, like using FastCGI to switch PHP versions as done on Ubuntu. As a result, I was able to achieve it, so this time I would like to share that method.
Installing Apache
Download Apache
https://www.apachelounge.com/download/
Copy the unzipped ZIP file to the folder where you want to run Apache.
(e.g. C:\localserver
)
Initial configuration of Apache
If you have expanded to C:\localserver\Apache24
, edit C:\localserver\Apache24\conf\httpd.conf
.
1 2 3 4 5 6 7 |
Define SRVROOT "c:/Apache24" ↓ Define SRVROOT "c:/localserver/Apache24" #ServerName www.example.com:80 ↓ ServerName localhost:80 |
Virtual host configuration
httpd.conf
1 2 3 |
#Include conf/extra/httpd-vhosts.conf ↓ Include conf/extra/httpd-vhosts.conf |
Edit conf/extra/httpd-vhosts.conf
to configure virtual hosts
(e.g. add localhost)
1 2 3 4 5 6 7 8 9 10 |
<VirtualHost *:80> ScriptInterpreterSource Registry-Strict DocumentRoot "htdocs" ServerName localhost <Directory "D:/ap/Apache24/htdocs"> DirectoryIndex index.html index.htm index.php index.cgi Options Indexes FollowSymLinks MultiViews Includes ExecCGI AllowOverride All Require all granted </Directory></VirtualHost> |
Enable HTTPS connections
httpd.conf
1 2 3 4 5 6 7 8 9 |
#LoadModule socache_shmcb_module modules/mod_socache_shmcb.so #LoadModule ssl_module modules/mod_ssl.so ↓ LoadModule socache_shmcb_module modules/mod_socache_shmcb.so LoadModule ssl_module modules/mod_ssl.so #Include conf/extra/httpd-ssl.conf ↓ Include conf/extra/httpd-ssl.conf |
If Apache does not start, check if there are any certificate-related files in the specified folder.
Enable PHP
Download the Thread Safe version of PHP in ZIP, unzip and extract to your location.
(e.g. C:\localserver\php8.2
)
conf/extra/httpd-php.conf
and create,
1 2 3 4 5 6 7 8 |
# PHP setting LoadModule php_module "C:/localserver/php8.2/php8apache2_4.dll" PHPIniDir "C:/localserver/php8.2" # Files with the extension "php" are handled as PHP. <FilesMatch "\.php$"> SetHandler application/x-httpd-php </FilesMatch> |
Add and save the file.
In httpd.conf
1 |
Include conf/extra/httpd-php.conf |
Add.
Install multiple versions of PHP and switching on each virtual host
Setting up multiple versions requires ‘mod_fcgid (FastCGI ASF module)’, download from Apache Lounge.
https://www.apachelounge.com/download
mod_fcgid
FastCGI ASF module
[mod_fcgid] mod_fcgid-2.3.10-win64-VS17.zip
Unzip the downloaded module ZIP package. Enter the mod_fcgid-*
(* is details such as version) folder. Open the mod_fcgid folder and copy the mod_fcgid.so file to your Apache module directory, such as C:∕localserver∕Apache24∕modules
.
Open httpd.conf
and
1 |
LoadModule fcgid_module modules/mod_fcgid.so |
Enable the FastCGI module.
VirtualHost configuration: for each virtual host, add a setting specifying the PHP version to be used. This is added to each VirtualHost section in the conf file.
FastCGI configuration: configure FastCGI settings. Start a FastCGI process for each PHP version and configure it to accept requests on the respective port.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# PHP 7.4 <VirtualHost *:80> ServerName example.com DocumentRoot "C:/path/to/your/document/root" # PHP 7.4 FastCGI configuration <FilesMatch \.php$> SetHandler fcgid-script FCGIWrapper "C:/localserver/php7.4/php-cgi.exe" .php Options +ExecCGI </FilesMatch> </VirtualHost> # PHP 8.0 <VirtualHost *:80> ServerName example2.com DocumentRoot "C:/path/to/your/other/document/root" # PHP 8.0 FastCGI configuration <FilesMatch \.php$> SetHandler fcgid-script FCGIWrapper "C:/localserver/php8.0/php-cgi.exe" .php Options +ExecCGI </FilesMatch> </VirtualHost> |
コメント