ホームページ >バックエンド開発 >PHPチュートリアル >複数のバージョンの PHP を導入して Linux 上で共存させる
複数のバージョンの php を Linux に展開して共存させる
背景の説明
最新のバージョン管理として php7 の登場以来、早速アップグレードして体験してみましたが、サーバーの都合上古いプログラムが残っているため、PHPの多バージョン共存環境を導入する必要があります。
既存の環境はlnmpです
- CentOS 6.7
- nginx 1.10.1
-mariadb-10.0.26
- php 7.0.8
古い php プログラムとの互換性を高めるために、主に mysql 拡張機能と互換性のある 5.4.45 を使用することをお勧めします。
インストールを開始します
まず、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('事前番号付け').hide(); $(this).addClass('has-numbering').parent().append($numbering); for (i = 1; i ').text(i)); }; $numbering.fadeIn(1700); }); });chkconfig 機能説明: システムのさまざまなサービスを確認および設定します。
構文: chkconfig [–add][–del][–list][システムサービス]
chkconfig [–level <レベルコード>][システムサービス][オン/オフ/リセット]
上記では、Linux 上で展開される複数のバージョンの PHP の共存について、その側面も含めて紹介しました。PHP チュートリアルに興味のある友人に役立つことを願っています。