> 백엔드 개발 > PHP 튜토리얼 > Linux下php+mysql+nginx编译搭建(三)

Linux下php+mysql+nginx编译搭建(三)

WBOY
풀어 주다: 2016-06-23 13:44:52
원래의
788명이 탐색했습니다.

之前一直都是一键搭建的web服务器,但是一键搭建的环境相对来说都是比较老的。如果要用比较新的环境,特别是正式服务器,就必须自己手动编译搭建了(以下搭建基于linux centos6.5 32位服务器)。

三、安装php
进入安装目录:

          <ol>              <li>cd /opt</li>          </ol>
로그인 후 복사

下载并解压:

          <ol>              <li>Wget http://am1.php.net/get/php-5.4.34.tar.gz/from/this/mirror</li>              <li>tar -zxf php-5.4.34.tar.gz</li>          </ol>
로그인 후 복사

进入目录编译:

          <ol>              <li>cd php-5.4.34</li>              <li>./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --with-mysql --with-mysqli=/usr/bin/mysql_config --with-iconv-dir --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir --enable-xml --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --with-curl --with-curlwrappers --enable-mbregex --enable-fpm --enable-mbstring --with-mcrypt=/usr/local/mcrypt --with-gd --enable-gd-native-ttf --with-openssl --with-mhash --enable-pcntl --enable-sockets --with-ldap --with-ldap-sasl --with-xmlrpc --enable-zip --enable-soap --with-pear --enable-pdo --with-pdo-mysql --with-gettext --enable-exif --enable-wddx --enable-calendar --enable-ftp --enable-dba --enable-sysvmsg --enable-sysvshm --enable-debug --enable-maintainer-zts --enable-embed --with-pcre-regex --enable-gd-jis-conv --with-fpm-user=www --with-fpm-group=www --enable-sockets</li>          </ol>
로그인 후 복사

报错:configure: error: mcrypt.h not found. Please reinstall libmcrypt.
在http://sourceforge.net/projects/mcrypt/files/下载libmcrypt和mcrypt编译(其中编译mcrypt需要mhash的支持,所以编译完libmcrypt后需要下载mhash,编译完mhash后才编译mcrypt)

          <ol>              <li>wget http://sourceforge.net/projects/mcrypt/files/Libmcrypt/2.5.8/libmcrypt-2.5.8.tar.gz/download</li>              <li>tar -zxvf libmcrypt-2.5.8.tar.gz </li>              <li>cd libmcrypt-2.5.8</li>              <li>./configure</li>              <li>Make && Make install</li>              <li> </li>              <li>Wget http://sourceforge.net/projects/mhash/files/mhash/0.9.9.9/mhash-0.9.9.9.tar.gz/download</li>              <li>tar -zxvf mhash-0.9.9.9.tar.gz</li>              <li>cd mhash-0.9.9.9.tar.gz</li>              <li>./configure</li>              <li>Make && Make install</li>              <li> </li>              <li>wget http://sourceforge.net/projects/mcrypt/files/MCrypt/2.6.8/mcrypt-2.6.8.tar.gz/download</li>              <li>tar -zxvf mcrypt-2.6.8.tar.gz</li>              <li>cd mcrypt-2.6.8</li>              <li>./configure</li>              <li>Make && Make install</li>          </ol>
로그인 후 복사

此时再编译(命令不copy了),报错:mysql_config not found
执行:find / -name mysql_config
发现/opt/mysql-5.5.30/scripts/mysql_config
于是:cp /opt/mysql-5.5.30/scripts/mysql_config /usr/bin/mysql_config
再次编译,通过。

          <ol>              <li>make && make install</li>          </ol>
로그인 후 복사

由于php5.4已经集成了php-fpm,所以我们不需要再额外下载php-fpm。
直接运行:

          <ol>              <li>/usr/local/php/sbin/php-fpm</li>          </ol>
로그인 후 복사

报错:ERROR: failed to open configuration file '/usr/local/php/etc/php-fpm.conf': No such file or directory (2)

          <ol>              <li>Cp /usr/local/etc/php-fpm.conf.default /usr/local/etc/php-fpm.conf</li>          </ol>
로그인 후 복사

解决。ps aux | grep php 查看,已经启动。

此时新建一个php文件访问,是不是还不支持?哈[坏笑]。
修改nginx.conf

          <ol>              <li>location ~ \.php$ {</li>              <li> root html;</li>              <li> fastcgi_pass 127.0.0.1:9000;</li>              <li> fastcgi_index index.php;</li>              <li> fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;</li>              <li> include fastcgi_params;</li>              <li> }</li>          </ol>
로그인 후 복사

重启nginx,至此,所有完结。

然后是不是又有点淡淡的忧伤?觉得/usr/local/php/sbin/php-fpm太长?习惯了/etc/init.d/php-fpm start?
Vim /etc/init.d/php-fpm

          <ol>              <li>#! /bin/sh</li>              <li>### BEGIN INIT INFO</li>              <li># Provides: php-fpm</li>              <li># Required-Start: $remote_fs $network</li>              <li># Required-Stop: $remote_fs $network</li>              <li># Default-Start: 2 3 4 5</li>              <li># Default-Stop: 0 1 6</li>              <li># Short-Description: starts php-fpm</li>              <li># Description: starts the PHP FastCGI Process Manager daemon</li>              <li>### END INIT INFO</li>              <li>prefix=/usr/local/php</li>              <li>exec_prefix=${prefix}</li>              <li> </li>              <li>php_fpm_BIN=${exec_prefix}/sbin/php-fpm</li>              <li>php_fpm_CONF=${prefix}/etc/php-fpm.conf</li>              <li>php_fpm_PID=${prefix}/var/run/php-fpm.pid</li>              <li>php_opts="--fpm-config $php_fpm_CONF --pid $php_fpm_PID"</li>              <li>wait_for_pid () {</li>              <li> try=0</li>              <li> while test $try -lt 35 ; do</li>              <li> case "$1" in</li>              <li> 'created')</li>              <li> if [ -f "$2" ] ; then</li>              <li> try=''</li>              <li> break</li>              <li> fi</li>              <li> ;;</li>              <li> 'removed')</li>              <li> if [ ! -f "$2" ] ; then</li>              <li> try=''</li>              <li> break</li>              <li> fi</li>              <li> ;;</li>              <li> esac</li>              <li> echo -n .</li>              <li> try=`expr $try + 1`</li>              <li> sleep 1</li>              <li> done</li>              <li>}</li>              <li>case "$1" in</li>              <li> start)</li>              <li> echo -n "Starting php-fpm "</li>              <li> $php_fpm_BIN --daemonize $php_opts</li>              <li> if [ "$?" != 0 ] ; then</li>              <li> echo " failed"</li>              <li> exit 1</li>              <li> fi</li>              <li> wait_for_pid created $php_fpm_PID</li>              <li> if [ -n "$try" ] ; then</li>              <li> echo " failed"</li>              <li> exit 1</li>              <li> else</li>              <li> echo " done"</li>              <li> fi</li>              <li> ;;</li>              <li> stop)</li>              <li> echo -n "Gracefully shutting down php-fpm "</li>              <li> if [ ! -r $php_fpm_PID ] ; then</li>              <li> echo "warning, no pid file found - php-fpm is not running ?"</li>              <li> exit 1</li>              <li> fi</li>              <li> kill -QUIT `cat $php_fpm_PID`</li>              <li> wait_for_pid removed $php_fpm_PID</li>              <li> if [ -n "$try" ] ; then</li>              <li> echo " failed. Use force-quit"</li>              <li> exit 1</li>              <li> else</li>              <li> echo " done"</li>              <li> fi</li>              <li> ;;</li>              <li> force-quit)</li>              <li> echo -n "Terminating php-fpm "</li>              <li> if [ ! -r $php_fpm_PID ] ; then</li>              <li> echo "warning, no pid file found - php-fpm is not running ?"</li>              <li> exit 1</li>              <li> fi</li>              <li> kill -TERM `cat $php_fpm_PID`</li>              <li> wait_for_pid removed $php_fpm_PID</li>              <li> if [ -n "$try" ] ; then</li>              <li> echo " failed"</li>              <li> exit 1</li>              <li> else</li>              <li> echo " done"</li>              <li> fi</li>              <li> ;;</li>              <li> restart)</li>              <li> $0 stop</li>              <li> $0 start</li>              <li> ;;</li>              <li> reload)</li>              <li> echo -n "Reload service php-fpm "</li>              <li> if [ ! -r $php_fpm_PID ] ; then</li>              <li> echo "warning, no pid file found - php-fpm is not running ?"</li>              <li> exit 1</li>              <li> fi</li>              <li> kill -USR2 `cat $php_fpm_PID`</li>              <li> echo " done"</li>              <li> ;;</li>              <li> *)</li>              <li> echo "Usage: $0 {start|stop|force-quit|restart|reload}"</li>              <li> exit 1</li>              <li> ;;</li>              <li>esac</li>          </ol>
로그인 후 복사

保存,添加x权限。

如需开机启动:chkconfig php-fpm on


更多请支持:http://www.webyang.net/Html/web/article_129.html

원천:php.cn
본 웹사이트의 성명
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.
인기 튜토리얼
더>
최신 다운로드
더>
웹 효과
웹사이트 소스 코드
웹사이트 자료
프론트엔드 템플릿