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 튜토리얼에 관심이 있는 친구들에게 도움이 되기를 바랍니다.