Professional Documents
Culture Documents
Menu
Menu
Ad
AD
台灣中華電信服務器 - 中華電信Hinet獨服
host.dler.org
造訪網站
RedHat RHCSA and RHCE Certi cation Preparation Guide - Get This Book
Sometimes PHP developers want to build and run different websites/applications using
different versions of PHP on the same web server. As a Linux system administrator, you
are required to setup a environment where you can run multiple websites using different
PHP version on a single web server i.e. Nginx.
In this tutorial, we will explain you how to install multiple versions of PHP and con gure
the web server Nginx to work with them via the server blocks (virtual hosts in Apache) in
CentOS/RHEL 7 distributions using LEMP stack.
https://www.tecmint.com/run-multiple-websites-with-different-php-versions-in-nginx/ 1/36
2/1/2021 How to Run Multiple Websites with Different PHP Versions in Nginx
Read Also: Pyenv – Install Multiple Python Versions for Speci c Project
Nginx uses PHP-FPM (stands for FastCGI Process Manager), which is an alternative
PHP FastCGI implementation with some extra, useful features for heavily loaded
websites.
2. Next install the yum-utils package, which extends yum’s native functionalities and
provides yum-con g-manager command, which is used to enable or disable Yum
repositories on the system.
# yum install yum-utils
https://www.tecmint.com/run-multiple-websites-with-different-php-versions-in-nginx/ 2/36
2/1/2021 How to Run Multiple Websites with Different PHP Versions in Nginx
Note: On RHEL 7 you can enable the optional channel for some dependencies using the
following command.
# vi /etc/yum.repos.d/nginx.repo
https://www.tecmint.com/run-multiple-websites-with-different-php-versions-in-nginx/ 3/36
2/1/2021 How to Run Multiple Websites with Different PHP Versions in Nginx
4. Once nginx repo has been added, you can install Nginx using yum package manager
tool as shown.
# vi /etc/yum.repos.d/mariadb.repo
6. Once MariaDB repo has been added, you can install MariaDB using yum package
manager tool as shown.
https://www.tecmint.com/run-multiple-websites-with-different-php-versions-in-nginx/ 4/36
2/1/2021 How to Run Multiple Websites with Different PHP Versions in Nginx
7. Afterwards, secure the database server installation using the script below. Set a root
password and answer y and press [Enter] for the rest of the subsequent questions to
disable remote root user login, remove anonymous-user accounts and test database
which by default can be accessed by all users, even anonymous users.
# mysql_secure_installation
https://www.tecmint.com/run-multiple-websites-with-different-php-versions-in-nginx/ 5/36
2/1/2021 How to Run Multiple Websites with Different PHP Versions in Nginx
9. Once installed PHP, you can use following command to check the default version of
PHP used on your server.
# php -v
https://www.tecmint.com/run-multiple-websites-with-different-php-versions-in-nginx/ 6/36
2/1/2021 How to Run Multiple Websites with Different PHP Versions in Nginx
10. This is the most interesting part of this tutorial, it explains how you can actually run
multiple PHP versions on your server. Here, you will con gure the different versions of
php-fpm that Nginx will work with. You should de ne the user/group of the FastCGI
processes as well as the ports they will listen on.
These are the following two con guration les that you will going to edit.
user = nginx
group = nginx
11. Next, nd the listen parameters, and de ne the address:port on which FastCGI
requests will be received.
12. Once all the above con guration done, you need to start and enable Nginx, MariaDB
and PHP-FPM to auto-start at system boot.
https://www.tecmint.com/run-multiple-websites-with-different-php-versions-in-nginx/ 7/36
2/1/2021 How to Run Multiple Websites with Different PHP Versions in Nginx
Attention: In case you get any errors while starting the second instance of PHP, php56-
php-fpm, a SELinux policy could be blocking it from starting. If SELinux is in enforcing
mode, set it to permissive mode, then try starting the service once again.
# getenforce
# setenforce 0
---------------- Website 2 ----------------
https://www.tecmint.com/run-multiple-websites-with-different-php-versions-in-nginx/ 8/36
2/1/2021 How to Run Multiple Websites with Different PHP Versions in Nginx
# mkdir -p /var/www/html/example2.com/
# mkdir -p /var/log/nginx/example2.com/
Create the con guration les for your websites ending with .conf extension.
# vi /etc/nginx/conf.d/example1.com.conf
# vi /etc/nginx/conf.d/example2.com.conf
Then paste the following server block con gurations in the respective les.
Website 1
https://www.tecmint.com/run-multiple-websites-with-different-php-versions-in-nginx/ 9/36
2/1/2021 How to Run Multiple Websites with Different PHP Versions in Nginx
server {
listen 80;
server_name example1.com www.example1.com;
root /var/www/html/example1.com/;
index index.php index.html index.htm;
#charset koi8-r;
access_log /var/log/nginx/example1.com/example1_access_log;
error_log /var/log/nginx/example1.com/example1_error_log er
location / {
try_files $uri $uri/ /index.php?$query_string;
}
root /var/www/html/example1.com/;
fastcgi_pass 127.0.0.1:9000; #set port for php-fpm t
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_
include fastcgi_params;
include /etc/nginx/fastcgi_params;
}
}
Website 2
https://www.tecmint.com/run-multiple-websites-with-different-php-versions-in-nginx/ 10/36
2/1/2021 How to Run Multiple Websites with Different PHP Versions in Nginx
server {
listen 80;
server_name example2.com www.example2.com;
root /var/www/html/example2.com/;
index index.php index.html index.htm;
#charset koi8-r;
access_log /var/log/nginx/example2.com/example2_access_log;
error_log /var/log/nginx/example2.com/example2_error_log err
location / {
try_files $uri $uri/ /index.php?$query_string;
}
root /var/www/html/example2.com/;
fastcgi_pass 127.0.0.1:9001; #set port for php56-php
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_
include fastcgi_params;
include /etc/nginx/fastcgi_params;
}
}
16. Make sure that you have the following line in the closing part of the http block in
/etc/nginx/nginx.conf. It helps to include all con guration les inside the
/etc/nginx/conf.d/ directory when Nginx is running.
include /etc/nginx/conf.d/*.conf;
https://www.tecmint.com/run-multiple-websites-with-different-php-versions-in-nginx/ 11/36
2/1/2021 How to Run Multiple Websites with Different PHP Versions in Nginx
18. To apply all the changes you have made above, you need to restart Nginx, php-fpm
and php56-php-fpm. But you can rst of all check that the Nginx con guration les for
any syntax errors before doing so.
# nginx -t
# systemctl restart nginx php-fpm php56-php-fpm
https://www.tecmint.com/run-multiple-websites-with-different-php-versions-in-nginx/ 12/36
2/1/2021 How to Run Multiple Websites with Different PHP Versions in Nginx
19. There is one other last thing to do, especially if you are running your server locally,
you need to setup local DNS using /etc/hosts le as shown in the screen shot below.
https://www.tecmint.com/run-multiple-websites-with-different-php-versions-in-nginx/ 13/36
2/1/2021 How to Run Multiple Websites with Different PHP Versions in Nginx
20. Finally, open a web browser and type the following addresses to verify the versions
of PHP installed on the system.
http://example1.com/index.php
http://example2.com/index.php
https://www.tecmint.com/run-multiple-websites-with-different-php-versions-in-nginx/ 14/36
2/1/2021 How to Run Multiple Websites with Different PHP Versions in Nginx
https://www.tecmint.com/run-multiple-websites-with-different-php-versions-in-nginx/ 15/36
2/1/2021 How to Run Multiple Websites with Different PHP Versions in Nginx
That’s It! Now you can deploy les and test websites with different PHP versions. If you
have any additions to make or questions to put forward, make use of the comment form
below.
How to Find a Speci c String or Word ccat – Show ‘cat Command’ Output with
in Files and Directories Syntax Highlighting or Colorizing
If you liked this article, then do subscribe to email alerts for Linux tutorials. If you have
any questions or doubts? do ask for help in the comments section.
https://www.tecmint.com/run-multiple-websites-with-different-php-versions-in-nginx/ 16/36
2/1/2021 How to Run Multiple Websites with Different PHP Versions in Nginx
TecMint is the fastest growing and most trusted community site for
any kind of Linux Articles, Guides and Books on the web. Millions of
people visit TecMint! to search or browse the thousands of published
articles available FREELY to all.
If you like what you are reading, please consider buying us a coffee (
or 2 ) as a token of appreciation.
Related Posts
https://www.tecmint.com/run-multiple-websites-with-different-php-versions-in-nginx/ 17/36
2/1/2021 How to Run Multiple Websites with Different PHP Versions in Nginx
https://www.tecmint.com/run-multiple-websites-with-different-php-versions-in-nginx/ 18/36
2/1/2021 How to Run Multiple Websites with Different PHP Versions in Nginx
How to Install, Run and Delete Applications Inside Docker Containers – Part 2
https://www.tecmint.com/run-multiple-websites-with-different-php-versions-in-nginx/ 19/36
2/1/2021 How to Run Multiple Websites with Different PHP Versions in Nginx
https://www.tecmint.com/run-multiple-websites-with-different-php-versions-in-nginx/ 20/36
2/1/2021 How to Run Multiple Websites with Different PHP Versions in Nginx
https://www.tecmint.com/run-multiple-websites-with-different-php-versions-in-nginx/ 21/36
2/1/2021 How to Run Multiple Websites with Different PHP Versions in Nginx
https://www.tecmint.com/run-multiple-websites-with-different-php-versions-in-nginx/ 22/36
2/1/2021 How to Run Multiple Websites with Different PHP Versions in Nginx
https://www.tecmint.com/run-multiple-websites-with-different-php-versions-in-nginx/ 23/36
2/1/2021 How to Run Multiple Websites with Different PHP Versions in Nginx
Maria
January 15, 2021 at 8:44 pm
https://www.tecmint.com/run-multiple-websites-with-different-php-versions-in-nginx/ 24/36
2/1/2021 How to Run Multiple Websites with Different PHP Versions in Nginx
Hello,
I wonder if you have done the post related to multiple domains in Apache
running different PHP versions on CentOS 7.
Thanks,
Reply
markonah
December 7, 2018 at 8:05 am
How to implement this to active for both PHP 5.6 and 7.2 in Apache virtual host?
thanks in advanced
Reply
Aaron Kili
December 7, 2018 at 1:46 pm
@markonah
Okay, we will prepare a guide for running multiple websites with different PHP
versions in Apache. Thanks for the feedback.
Reply
https://www.tecmint.com/run-multiple-websites-with-different-php-versions-in-nginx/ 25/36
2/1/2021 How to Run Multiple Websites with Different PHP Versions in Nginx
JJ
June 26, 2019 at 9:15 pm
Yes please, I really need to know how to do this using the Apache webserver.
Reply
CTrace
November 12, 2018 at 4:31 pm
$ php -v
Reply
Aaron Kili
November 13, 2018 at 11:58 pm
@CTrace
In your case, you need to install PHP5.6 as the default version. Refer to the
steps for installing PHP, shown above.
https://www.tecmint.com/run-multiple-websites-with-different-php-versions-in-nginx/ 26/36
2/1/2021 How to Run Multiple Websites with Different PHP Versions in Nginx
Reply
Aaron Smith
October 11, 2018 at 9:39 pm
Is there a known way to switch this process? I have several machines that have
PHP 5.6 running and I want to add php 7 to those machines. Let me know.
Reply
Aaron Kili
October 12, 2018 at 12:56 pm
@Aaron
Change the value of the fastcgi_pass directive in to the TCP socket or Unix
socket for the particular PHP-FPM you want.
Reply
Natka
July 23, 2018 at 10:20 pm
Thanks in advance.
https://www.tecmint.com/run-multiple-websites-with-different-php-versions-in-nginx/ 27/36
2/1/2021 How to Run Multiple Websites with Different PHP Versions in Nginx
Reply
Aaron Kili
July 25, 2018 at 8:37 pm
@Natka
In Apache, server blocks are referred to as virtual hosts, see this guide for more
information and how to con gure them: https://www.tecmint.com/apache-ip-
based-and-name-based-virtual-hosting/
Reply
liam.wang
June 28, 2018 at 2:20 pm
good job!
Reply
Aaron Kili
June 29, 2018 at 11:37 am
@liam.wang
Many thanks for mentioning, we will correct the typo.
https://www.tecmint.com/run-multiple-websites-with-different-php-versions-in-nginx/ 28/36
2/1/2021 How to Run Multiple Websites with Different PHP Versions in Nginx
Reply
Ravi Saive
June 29, 2018 at 11:52 am
@Liam,
Reply
Zulmi
June 27, 2018 at 1:15 pm
Reply
Aaron Kili
June 28, 2018 at 1:16 pm
@Zulmi
This is great, we are glad that you found this guide helpful. Thanks for the
feedback.
Reply
https://www.tecmint.com/run-multiple-websites-with-different-php-versions-in-nginx/ 29/36
2/1/2021 How to Run Multiple Websites with Different PHP Versions in Nginx
Grace
May 29, 2018 at 11:33 am
How to x that?
Reply
Hank Cape
April 4, 2018 at 3:34 pm
Just for those (others) running these on automaton, there might be a good reason
to add instructions starting database in Step 3 between 6. and 7. :) I knew it but
some others might not get it and they might get frustrated.
Reply
Hank Cape
April 4, 2018 at 4:42 pm
https://www.tecmint.com/run-multiple-websites-with-different-php-versions-in-nginx/ 30/36
2/1/2021 How to Run Multiple Websites with Different PHP Versions in Nginx
Also, Step 5 point 12. The second to last line is incorrect, systemctl enable
php56-fpm should be systemctl enable php56-php-fpm.
I don’t need these comments to be published, just to inform you about these
two things in otherwise excellent article.
hank
Reply
Aaron Kili
April 5, 2018 at 10:57 am
@Hank
Many thanks for the heads up. We will correct this as soon as possible.
However, the comments have to be published, because this is useful info you
have shared. Thanks once more.
Reply
Simon
January 22, 2019 at 4:16 am
Reply
https://www.tecmint.com/run-multiple-websites-with-different-php-versions-in-nginx/ 31/36
2/1/2021 How to Run Multiple Websites with Different PHP Versions in Nginx
Ravi Saive
January 22, 2019 at 12:24 pm
@Simon,
Name *
Email *
Website
Save my name, email, and website in this browser for the next time I comment.
Notify me of followup comments via e-mail. You can also subscribe without
commenting.
https://www.tecmint.com/run-multiple-websites-with-different-php-versions-in-nginx/ 32/36
2/1/2021 How to Run Multiple Websites with Different PHP Versions in Nginx
Post Comment
This site uses Akismet to reduce spam. Learn how your comment data is processed.
Ad
AD
Linux Foundation LFCS and LFCE Certi cation Study Guide [eBooks]
https://www.tecmint.com/run-multiple-websites-with-different-php-versions-in-nginx/ 33/36
2/1/2021 How to Run Multiple Websites with Different PHP Versions in Nginx
Dtrx – An Intelligent Archive Extraction (tar, zip, cpio, rpm, deb, rar) Tool for Linux
12 Useful Commands For Filtering Text for Effective File Operations in Linux
If You Appreciate What We Do Here On TecMint, You Should Consider:
https://www.tecmint.com/run-multiple-websites-with-different-php-versions-in-nginx/ 34/36
2/1/2021 How to Run Multiple Websites with Different PHP Versions in Nginx
How to Install and Con gure ‘Collectd’ and ‘Collectd-Web’ to Monitor Server
Resources in Linux
How to Install and Con gure Zabbix Agents on Remote Linux Systems – Part 3
How to Record and Replay Linux Terminal Sessions using ‘script’ and ‘scriptreplay’
Commands
How to Find Out Top Directories and Files (Disk Space) in Linux
https://www.tecmint.com/run-multiple-websites-with-different-php-versions-in-nginx/ 35/36
2/1/2021 How to Run Multiple Websites with Different PHP Versions in Nginx
Tecmint: Linux Howtos, Tutorials & Guides © 2021. All Rights Reserved.
The material in this site cannot be republished either online or of ine, without our permission.
https://www.tecmint.com/run-multiple-websites-with-different-php-versions-in-nginx/ 36/36