Linux environment Nginx Install multiple versions of PHP

Source: Internet
Author: User

About Linux environment Nginx installation and debugging and PHP installation reference this article can be: http://blog.csdn.net/unix21/article/details/8544922


Linux version: 64-bit CentOS 6.4

Nginx Version: nginx1.8.0

PHP Version: php5.5.28 & php5.4.44

The so-called multiple versions of multiple versions of PHP are php5.4 and 5.5 as well as other versions on the same server.

If php5.5 is a major version already installed in the/usr/local/php directory, then install the other version of PHP and then specify a different installation directory.


Install a second version of PHP

# wget Http://cn2.php.net/get/php-5.4.44.tar.gz/from/this/mirror
# tar ZXVF php-5.4.44.tar.gz
# CD php-5.4.44
#./configure--prefix=/usr/local/php5.4.44 \
--with-curl \
--with-freetype-dir \
--WITH-GD \
--with-gettext \
--with-iconv-dir \
--with-kerberos \
--WITH-LIBDIR=LIB64 \
--with-libxml-dir \
--with-mysql \
--WITH-MYSQLI \
--WITH-OPENSSL \
--with-pcre-regex \
--with-pdo-mysql \
--with-pdo-sqlite \
--with-pear \
--with-png-dir \
--WITH-XMLRPC \
--with-xsl \
--with-zlib \
--ENABLE-FPM \
--enable-bcmath \
--enable-libxml \
--enable-inline-optimization \
--ENABLE-GD-NATIVE-TTF \
--enable-mbregex \
--enable-mbstring \
--ENABLE-PCNTL \
--ENABLE-SHMOP \
--ENABLE-SOAP \
--enable-sockets \
--enable-sysvsem \
--enable-xml \
--enable-zip
# Make && make install
# Cp-r/sapi/fpm/php-fpm.conf/usr/local/php5.4.44/etc/php-fpm.conf.
# CP Php.ini-development/usr/local/php5.4.44/lib/php.ini
# Cp-r/sapi/fpm/php-fpm/etc/init.d/php-fpm5.4.44.


Modify the php-fpm.conf listening port to 9001 because the main version 5.5.28 is listening for 9000.

; Note:this value is mandatory.
Listen = 127.0.0.1:9001

Start PHP-FPM
#/etc/init.d/php-fpm5.4.44


PHP installation successfully view process

#ps aux|grep PHP

So it's already php-fpm.


Configure Nginx

Add a new configuration of Port 8054 and point to 9001 and specify the directory:

server {
Listen 8054;
server_name localhost;


Location/{
#root html;
root/usr/www5.4.44;
Index index.html index.htm;
}


Error_page 502 503 504/50x.html;
Location =/50x.html {
root HTML;
}


Location ~ \.php$ {
root HTML;
Fastcgi_pass 127.0.0.1:9001;
Fastcgi_index index.php;
Include Fastcgi_params;
Fastcgi_param Script_filename/usr/www5.4.44$fastcgi_script_name;
}

}


Nginx's configuration file nginx.conf in

# cd/usr/local/nginx/conf

Complete Nginx configuration as shown in figure:

#user nobody;

Worker_processes 4;
#error_log Logs/error.log;
#error_log Logs/error.log Notice;

#error_log Logs/error.log Info;


#pid Logs/nginx.pid;


Events {worker_connections 1024;}
    HTTP {include mime.types;

    Default_type Application/octet-stream; #log_format Main ' $remote _addr-$remote _user [$time _local] "$request" ' # ' $status $body _bytes_sen

    T "$http _referer" "$http _user_agent" "$http _x_forwarded_for";

    #access_log Logs/access.log Main;
    Sendfile on;

    #tcp_nopush on;
    #keepalive_timeout 0;

    Keepalive_timeout 65;

    #gzip on;
        server {Listen 80;

        server_name localhost;

        #charset Koi8-r;

        #access_log Logs/host.access.log Main;
			Location/{#root html;
            root/usr/www;
        Index index.html index.htm;

        } #error_page 404/404.html; # REDIRECT Server error pages to the static page/50x.html # Error_page 502 503 504/50x.html;
        Location =/50x.html {root html;    # Proxy The PHP scripts to Apache listening on 127.0.0.1:80 # #location ~ \.php$ {#
        Proxy_pass http://127.0.0.1;
        # Pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000 # #location ~ \.php$ {
        # root HTML;
        # Fastcgi_pass 127.0.0.1:9000;
        # Fastcgi_index index.php;
        # Fastcgi_param Script_filename/scripts$fastcgi_script_name;
        # include Fastcgi_params;
		#} location ~ \.php$ {root html;
		Fastcgi_pass 127.0.0.1:9000;
		Fastcgi_index index.php;
		Include Fastcgi_params;
		Fastcgi_param Script_filename/usr/www$fastcgi_script_name;
        # Deny access to. htaccess files, if Apache ' s document Root # concurs with Nginx ' s one# #location ~/\.ht {# deny all;
        #} server {listen 8054;

        server_name localhost;
			Location/{#root html;
            root/usr/www5.4.44;
        Index index.html index.htm;
        } error_page 502 503 504/50x.html;
        Location =/50x.html {root html;
		} location ~ \.php$ {root html;
		Fastcgi_pass 127.0.0.1:9001;
		Fastcgi_index index.php;
		Include Fastcgi_params;
		Fastcgi_param Script_filename/usr/www5.4.44$fastcgi_script_name;    } # Another virtual host using mix of ip-, name-, and port-based configuration # #server {#
    Listen 8000;
    # Listen somename:8080;

    # server_name somename alias Another.alias;
    # location/{# root HTML;
    # index index.html index.htm;
    #} # HTTPS Server # #server {# listen 443 SSL; # serveR_name localhost;
    # ssl_certificate Cert.pem;

    # Ssl_certificate_key Cert.key;
    # Ssl_session_cache shared:ssl:1m;

    # ssl_session_timeout 5m; # ssl_ciphers high:!anull:!
    MD5;

    # ssl_prefer_server_ciphers on;
    # location/{# root HTML;
    # index index.html index.htm;
 #    }
    #}

}

Restart Nginx

#/usr/local/nginx/sbin/nginx-s Reload

Note that a firewall is required to increase the opening of a new port, otherwise it cannot be accessed:

Firewall Configuration

Note If you want to access the Web page of a virtual machine on a local machine such as XP, if it is centos6 need to modify the firewall boot 80 port

# Cd/etc/sysconfig

Modify the Iptables file, or edit it directly with Vim

# Vim/etc/sysconfig/iptables

Add the following line to open firewall port 80:

-A input-m state--state new-m tcp-p TCP--dport 8054-j ACCEPT

Reboot firewall
#/etc/init.d/iptables Restart

Test is successful, view Phpinfo ()


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.