This script allows you to switch between different versions of PHP for your Apache server on a Windows environment. It updates the system PATH and modifies the Apache configuration to use the specified PHP version.
- PHP 7.4
- PHP 8.0
- PHP 8.1
- PHP 8.2
- PHP 8.3
- PHP 8.4
- Apache installed and configured on your system.
- PHP versions installed in the specified directory.
-
PHP Installation:
- Download the desired PHP versions from the official PHP website.
- Extract each PHP version into its own directory under a common base directory. For example:
C:/Dev/php/ ├── php7.4/ ├── php8.0/ ├── php8.1/ ├── php8.2/ ├── php8.3/ └── php8.4 - Ensure that each PHP version folder contains the appropriate
php.inifiles and the SAPI DLL files (php7apache2_4.dllfor PHP 7 andphp8apache2_4.dllfor PHP 8).
-
Clone the Repository or download the script file.
-
Modify the Script:
- Open the
switch-php.batfile in a text editor. - Update the following paths according to your installation:
:: Define base paths for PHP installations and Apache configuration set "PHP_BASE_PATH=C:/Dev/php" set "APACHE_CONF=C:\Dev\Apache24\conf\httpd.conf" set "APACHE_BIN=C:\Dev\Apache24\bin\httpd.exe"
- Open the
-
Ensure Apache is Running as a Service:
- Open Command Prompt as Administrator.
- Run the following commands to stop and start Apache as a service:
net stop Apache2.4 net start Apache2.4
-
Admin Privileges and Permissions:
- Ensure you run the script as an Administrator. Right-click on Command Prompt and select "Run as administrator."
- The script modifies system PATH and Apache configuration files, which require administrative privileges.
-
Add
switch-php.batto System PATH:- To easily run the script from any command prompt, you can add the directory containing
switch-php.batto your system PATH. - Open Command Prompt as Administrator and run the following command, replacing
C:\Path\To\Scriptwith the actual path to your script:
setx PATH "%PATH%;C:\Path\To\Script" /M
- To easily run the script from any command prompt, you can add the directory containing
-
Run the Script:
- Open Command Prompt as Administrator.
- Navigate to the directory where the script is located (or ensure it is in your PATH).
- Run the script with the desired PHP version as an argument. For example, to switch to PHP 8.3, use:
switch-php.bat 8.3
-
Script Output:
- The script will update the system PATH, modify the Apache configuration, validate the configuration, and restart Apache.
- If successful, you will see a message indicating the PHP version has been switched, and the current PHP version will be displayed.
- Ensure you run the script as an Administrator.
- Verify the paths to your PHP installations and Apache configuration.
- Check the Apache error logs if the service fails to start.
This project is licensed under the MIT License - see the LICENSE file for details.
