Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save mberneti/04c39f59ba7acf0b3e618e767e971559 to your computer and use it in GitHub Desktop.
Save mberneti/04c39f59ba7acf0b3e618e767e971559 to your computer and use it in GitHub Desktop.
PHP Version Manager On Ubuntu 20.04 and nginx
Get the information of PHP
==========================
sudo apt-get install software-properties-common -y
sudo add-apt-repository ppa:ondrej/nginx
sudo add-apt-repository ppa:ondrej/php
// The installation of php on Ubuntu configures Apache.
// For users interested in running Nginx and PHP, you need to stop and disable Apache service.
sudo systemctl disable --now apache2
sudo apt install php5.6 php5.6-fpm
sudo apt install php7.4 php7.4-fpm
// nginx installation
sudo apt install nginx
// nginx configuration
sudo mkdir /var/www/php56
sudo mkdir /var/www/php74
echo "<?php phpinfo(); ?>" | sudo tee /var/www/php56/index.php
echo "<?php phpinfo(); ?>" | sudo tee /var/www/php74/index.php
// 5.6 sample
sudo vim /etc/nginx/sites-available/php56.example.com
# Application with PHP 5.6
#
server {
listen 80;
root /var/www/php56;
index index.php;
server_name php56.example.com;
location ~* \.php$ {
# With php-fpm unix sockets
fastcgi_pass unix:/var/run/php/php5.6-fpm.sock;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param SCRIPT_NAME $fastcgi_script_name;
}
}
// 74 sample
sudo vim /etc/nginx/sites-available/php74.example.com
# Application with PHP 7.4
#
server {
listen 80;
root /var/www/php74;
index index.php;
server_name php74.example.com;
location ~* \.php$ {
# With php-fpm unix sockets
fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param SCRIPT_NAME $fastcgi_script_name;
}
}
sudo ln -s /etc/nginx/sites-available/php56.example.com /etc/nginx/sites-enabled/
sudo ln -s /etc/nginx/sites-available/php74.example.com /etc/nginx/sites-enabled/
sudo systemctl restart nginx.service
// Test Setup
// All done. You can access both sites in your favirote web browser.
// You will see that php56.example.com shows the version PHP 5.6 and
// php74.example.com is showing the PHP 7.4 as the configuration.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment