Linux下部署php多版本共存
背景说明
自php7问世,身为最新版本控的我马上升级体验,但是由于服务器上还有旧程序在运行,只好部署一个php多版本共存环境。
现有环境是lnmp
- CentOS 6.7
- nginx 1.10.1
- mariadb-10.0.26
- php 7.0.8
为了更好兼容旧的php程序,推荐使用5.4.45. 主要是兼容mysql扩展。
开始安装
首先要下载php-5.4.45.tar.gz源码包。
通过源码安装
<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 配置
<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 配置
<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>
注意:重点是配置监听端口和进程
启动 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>
修改nginx配置,对需要的服务配置使用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>
配置php-5.4.45 的php54-fpm 开机自动启动
<code><span># chkconfig --add php54-fpm</span><span># chkconfig php54-fpm on</span></code>
').addClass('pre-numbering').hide(); $(this).addClass('has-numbering').parent().append($numbering); for (i = 1; i ').text(i)); }; $numbering.fadeIn(1700); }); });chkconfig 功能说明:检查,设置系统的各种服务。
语法:chkconfig [–add][–del][–list][系统服务]
chkconfig [–level ][系统服务][on/off/reset]
以上就介绍了 Linux下部署php多版本共存,包括了方面的内容,希望对PHP教程有兴趣的朋友有所帮助。