Home >Backend Development >PHP Tutorial >Deploy multiple versions of PHP to coexist under Linux

Deploy multiple versions of PHP to coexist under Linux

WBOY
WBOYOriginal
2016-07-28 08:28:341231browse

Deploying multiple versions of php under Linux to coexist

  • Deploying multiple versions of php to coexist under Linux
    • Background description
    • Start the installation
    • phpini configuration
    • php-fpmconf configuration
    • Start php-fpm
    • Modify nginx configuration as needed The service configuration uses php-5445
    • Configure php-5445's php54-fpm to start automatically at boot

Background description

Since the advent of php7, as the latest version control, I immediately upgraded to experience it, but due to the server There are still old programs running on the computer, so we have to deploy a PHP multi-version coexistence environment.

The existing environment is lnmp
- CentOS 6.7
- nginx 1.10.1
-mariadb-10.0.26
- php 7.0.8

In order to be better compatible with old php programs, it is recommended to use 5.4.45. It is mainly compatible with the mysql extension.

Start the installation

First download the php-5.4.45.tar.gz source package.

Install through source code

<code><span>#</span><span>tar</span><span>xzvf</span><span>php</span><span>-</span><span>5</span><span>.</span><span>4</span><span>.</span><span>45</span><span>.</span><span>tar</span><span>.</span><span>gz</span><span>#</span><span>cd</span><span>php</span><span>-</span><span>5</span><span>.</span><span>4</span><span>.</span><span>45</span><span>#</span><span>.</span><span>/configure</span><span>-</span><span>-</span><span>prefix=/usr/local/php54</span><span>-</span><span>-</span><span>with</span><span>-</span><span>config</span><span>-</span><span>file</span><span>-</span><span>path=/usr/local/php54/etc</span><span>-</span><span>-</span><span>enable</span><span>-</span><span>fpm</span><span>-</span><span>-</span><span>with</span><span>-</span><span>fpm</span><span>-</span><span>user=www</span><span>-</span><span>-</span><span>with</span><span>-</span><span>fpm</span><span>-</span><span>group=www</span><span>-</span><span>-</span><span>with</span><span>-</span><span>mysql=mysqlnd</span><span>-</span><span>-</span><span>with</span><span>-</span><span>mysqli=mysqlnd</span><span>-</span><span>-</span><span>with</span><span>-</span><span>pdo</span><span>-</span><span>mysql=mysqlnd</span><span>-</span><span>-</span><span>with</span><span>-</span><span>iconv</span><span>-</span><span>dir</span><span>-</span><span>-</span><span>with</span><span>-</span><span>freetype</span><span>-</span><span>dir=/usr/local/freetype</span><span>-</span><span>-</span><span>with</span><span>-</span><span>jpeg</span><span>-</span><span>dir</span><span>-</span><span>-</span><span>with</span><span>-</span><span>png</span><span>-</span><span>dir</span><span>-</span><span>-</span><span>with</span><span>-</span><span>zlib</span><span>-</span><span>-</span><span>with</span><span>-</span><span>libxml</span><span>-</span><span>dir=/usr</span><span>-</span><span>-</span><span>enable</span><span>-</span><span>xml</span><span>-</span><span>-</span><span>disable</span><span>-</span><span>rpath</span><span>-</span><span>-</span><span>enable</span><span>-</span><span>bcmath</span><span>-</span><span>-</span><span>enable</span><span>-</span><span>shmop</span><span>-</span><span>-</span><span>enable</span><span>-</span><span>sysvsem</span><span>-</span><span>-</span><span>enable</span><span>-</span><span>inline</span><span>-</span><span>optimization</span><span>-</span><span>-</span><span>with</span><span>-</span><span>curl</span><span>-</span><span>-</span><span>enable</span><span>-</span><span>mbregex</span><span>-</span><span>-</span><span>enable</span><span>-</span><span>mbstring</span><span>-</span><span>-</span><span>with</span><span>-</span><span>mcrypt</span><span>-</span><span>-</span><span>enable</span><span>-</span><span>ftp</span><span>-</span><span>-</span><span>with</span><span>-</span><span>gd</span><span>-</span><span>-</span><span>enable</span><span>-</span><span>gd</span><span>-</span><span>native</span><span>-</span><span>ttf</span><span>-</span><span>-</span><span>with</span><span>-</span><span>openssl</span><span>-</span><span>-</span><span>with</span><span>-</span><span>mhash</span><span>-</span><span>-</span><span>enable</span><span>-</span><span>pcntl</span><span>-</span><span>-</span><span>enable</span><span>-</span><span>sockets</span><span>-</span><span>-</span><span>with</span><span>-</span><span>xmlrpc</span><span>-</span><span>-</span><span>enable</span><span>-</span><span>zip</span><span>-</span><span>-</span><span>enable</span><span>-</span><span>soap</span><span>-</span><span>-</span><span>with</span><span>-</span><span>gettext</span><span>-</span><span>-</span><span>disable</span><span>-</span><span>fileinfo</span><span>-</span><span>-</span><span>enable</span><span>-</span><span>intl</span><span>-</span><span>-</span><span>with</span><span>-</span><span>xsl</span><span>#</span><span>make</span><span>ZEND_EXTRA_LIBS='</span><span>-</span><span>liconv'</span><span>#</span><span>make</span><span>install</span><span>#</span><span>cp</span><span>php</span><span>.</span><span>ini</span><span>-</span><span>production</span><span>/usr/local/php/etc/php</span><span>.</span><span>ini</span></code>

php.ini configuration

<code>post_max_size = <span>50</span>M
upload_max_filesize = <span>50</span>M
date.timezone = PRC
short_open_tag = On
cgi.fix_pathinfo=<span>0</span>
max_execution_time = <span>300</span>
disable_functi>exec,<span>system</span>,<span>chroot</span>,scandir,chgrp,<span>chown</span>,shell_exec,proc_open,proc_get_status,popen,ini_alter,ini_restore,dl,openlog,syslog,<span>readlink</span>,<span>symlink</span>,popepassthru,stream_socket_server</code>

php-fpm.conf configuration

<code><span># vim /usr/local/php/etc/php-fpm.conf</span></code>
<code>[global]
pid = /usr/local/php54/var/run/php-fpm<span>.pid</span>
error_log = /usr/local/php54/var/log/php-fpm<span>.log</span>
log_level = notice

[www]
listen = /tmp/php54-cgi<span>.sock</span>
listen<span>.backlog</span> = -<span>1</span>
listen<span>.allowed</span>_clients = <span>127.0</span><span>.0</span><span>.1</span>:<span>9001</span>
listen<span>.owner</span> = www
listen<span>.group</span> = www
listen<span>.mode</span> = <span>0666</span>
user = www
group = www
pm = dynamic
pm<span>.max</span>_children = <span>40</span>
pm<span>.start</span>_servers = <span>20</span>
pm<span>.min</span>_spare_servers = <span>20</span>
pm<span>.max</span>_spare_servers = <span>40</span>
request_terminate_timeout = <span>100</span>
request_slowlog_timeout = <span>0</span>
slowlog = var/log/slow<span>.log</span></code>

Note: The key is to configure the listening port and process

Start php-fpm

<code><span># cp sapi/fpm/init.d.php-fpm /etc/init.d/php54-fpm</span><span># chmod +x /etc/init.d/php54-fpm</span><span># /etc/init.d/php54-fpm start</span></code>

Modify nginx configuration as needed The service configuration uses php-5.4.45

<code>  location ~ [^<span>/]\.php(/</span>|<span>$)</span>
  {
      try_files <span>$uri</span> =<span>404</span>;
      fastcgi_pass  <span>unix:</span>/tmp/php54-cgi.sock;
      fastcgi_index index.php;
      <span>include</span> fastcgi.conf;
  }</code>

Configure php-5.4.45's php54-fpm to start automatically at boot

<code><span># chkconfig --add php54-fpm</span><span># chkconfig php54-fpm on</span></code>

chkconfig Function description: Check and set various services of the system.
Syntax: chkconfig [–add][–del][–list][system service]
chkconfig [–level ][system service][on/off/reset]

').addClass('pre-numbering').hide(); $(this).addClass('has-numbering').parent().append($numbering); for (i = 1; i ').text(i)); }; $numbering.fadeIn(1700); }); });

The above has introduced the coexistence of multiple versions of PHP deployed under Linux, including aspects of it. I hope it will be helpful to friends who are interested in PHP tutorials.

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn