1. Install Necessary Software:
Make sure you have Nginx and PHP installed on your CentOS server.
sudo yum install epel-release
sudo yum install nginx
sudo yum install php php-fpm
2. Install Additional PHP Versions:
You can use a repository like Remi to install multiple PHP versions. Install the repository and the desired PHP versions.
sudo yum install https://rpms.remirepo.net/enterprise/remi-release-7.rpm
sudo yum-config-manager --enable remi-php74 # Replace with the desired PHP version (e.g., remi-php73, remi-php72, etc.)
sudo yum install php php-fpm
3. Configure PHP-FPM Pools:
For each PHP version, create a separate PHP-FPM pool configuration. The pool configuration files are typically located in /etc/php-fpm.d/
. Create a new file for each PHP version, like php74-fpm.conf
, and configure the necessary settings.
sudo nano /etc/php-fpm.d/php74-fpm.conf
Sample php74-fpm.conf
:
[php74]
user = nginx
group = nginx
listen = /var/run/php74-fpm.sock
listen.owner = nginx
listen.group = nginx
pm = dynamic
pm.max_children = 50
pm.start_servers = 5
pm.min_spare_servers = 5
pm.max_spare_servers = 35
Repeat this step for each PHP version you have installed.
4. Configure Nginx to Use Multiple PHP Versions:
Edit your Nginx server block configuration to include different PHP-FPM sockets for each PHP version.
sudo nano /etc/nginx/conf.d/default.conf
Sample Nginx configuration:
server {
listen 80;
server_name yourdomain.com;
root /var/www/html;
location ~ \.php$ {
fastcgi_pass unix:/var/run/php74-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
# Add similar blocks for other PHP versions if needed
}
5. Restart Services:
Restart PHP-FPM and Nginx to apply the changes.
sudo systemctl restart php-fpm
sudo systemctl restart nginx
6. Test Configuration:
Create a simple PHP file (info.php
) in your web root with the following content:
<?php
phpinfo();
?>
Access this file in your browser (http://yourdomain.com/info.php
) to see the PHP version information.
Repeat these steps for each PHP version you want to run on your server. Adjust configurations based on your specific needs and security requirements.