Linux下php+mysql+nginx编译搭建(三)
三、安装php
进入安装目录:
- cd /opt
下载并解压:
- Wget http://am1.php.net/get/php-5.4.34.tar.gz/from/this/mirror
- tar -zxf php-5.4.34.tar.gz
进入目录编译:
- cd php-5.4.34
- ./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
报错:configure: error: mcrypt.h not found. Please reinstall libmcrypt.
在http://sourceforge.net/projects/mcrypt/files/下载libmcrypt和mcrypt编译(其中编译mcrypt需要mhash的支持,所以编译完libmcrypt后需要下载mhash,编译完mhash后才编译mcrypt)
- wget http://sourceforge.net/projects/mcrypt/files/Libmcrypt/2.5.8/libmcrypt-2.5.8.tar.gz/download
- tar -zxvf libmcrypt-2.5.8.tar.gz
- cd libmcrypt-2.5.8
- ./configure
- Make && Make install
- Wget http://sourceforge.net/projects/mhash/files/mhash/0.9.9.9/mhash-0.9.9.9.tar.gz/download
- tar -zxvf mhash-0.9.9.9.tar.gz
- cd mhash-0.9.9.9.tar.gz
- ./configure
- Make && Make install
- wget http://sourceforge.net/projects/mcrypt/files/MCrypt/2.6.8/mcrypt-2.6.8.tar.gz/download
- tar -zxvf mcrypt-2.6.8.tar.gz
- cd mcrypt-2.6.8
- ./configure
- Make && Make install
此时再编译(命令不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
再次编译,通过。
- make && make install
由于php5.4已经集成了php-fpm,所以我们不需要再额外下载php-fpm。
直接运行:
- /usr/local/php/sbin/php-fpm
报错:ERROR: failed to open configuration file '/usr/local/php/etc/php-fpm.conf': No such file or directory (2)
- Cp /usr/local/etc/php-fpm.conf.default /usr/local/etc/php-fpm.conf
解决。ps aux | grep php 查看,已经启动。
此时新建一个php文件访问,是不是还不支持?哈[坏笑]。
修改nginx.conf
- location ~ \.php$ {
- root html;
- fastcgi_pass 127.0.0.1:9000;
- fastcgi_index index.php;
- fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
- include fastcgi_params;
- }
重启nginx,至此,所有完结。
然后是不是又有点淡淡的忧伤?觉得/usr/local/php/sbin/php-fpm太长?习惯了/etc/init.d/php-fpm start?
Vim /etc/init.d/php-fpm
- #! /bin/sh
- ### BEGIN INIT INFO
- # Provides: php-fpm
- # Required-Start: $remote_fs $network
- # Required-Stop: $remote_fs $network
- # Default-Start: 2 3 4 5
- # Default-Stop: 0 1 6
- # Short-Description: starts php-fpm
- # Description: starts the PHP FastCGI Process Manager daemon
- ### END INIT INFO
- prefix=/usr/local/php
- exec_prefix=${prefix}
- php_fpm_BIN=${exec_prefix}/sbin/php-fpm
- php_fpm_CONF=${prefix}/etc/php-fpm.conf
- php_fpm_PID=${prefix}/var/run/php-fpm.pid
- php_opts="--fpm-config $php_fpm_CONF --pid $php_fpm_PID"
- wait_for_pid () {
- try=0
- while test $try -lt 35 ; do
- case "$1" in
- 'created')
- if [ -f "$2" ] ; then
- try=''
- break
- fi
- ;;
- 'removed')
- if [ ! -f "$2" ] ; then
- try=''
- break
- fi
- ;;
- esac
- echo -n .
- try=`expr $try + 1`
- sleep 1
- done
- }
- case "$1" in
- start)
- echo -n "Starting php-fpm "
- $php_fpm_BIN --daemonize $php_opts
- if [ "$?" != 0 ] ; then
- echo " failed"
- exit 1
- fi
- wait_for_pid created $php_fpm_PID
- if [ -n "$try" ] ; then
- echo " failed"
- exit 1
- else
- echo " done"
- fi
- ;;
- stop)
- echo -n "Gracefully shutting down php-fpm "
- if [ ! -r $php_fpm_PID ] ; then
- echo "warning, no pid file found - php-fpm is not running ?"
- exit 1
- fi
- kill -QUIT `cat $php_fpm_PID`
- wait_for_pid removed $php_fpm_PID
- if [ -n "$try" ] ; then
- echo " failed. Use force-quit"
- exit 1
- else
- echo " done"
- fi
- ;;
- force-quit)
- echo -n "Terminating php-fpm "
- if [ ! -r $php_fpm_PID ] ; then
- echo "warning, no pid file found - php-fpm is not running ?"
- exit 1
- fi
- kill -TERM `cat $php_fpm_PID`
- wait_for_pid removed $php_fpm_PID
- if [ -n "$try" ] ; then
- echo " failed"
- exit 1
- else
- echo " done"
- fi
- ;;
- restart)
- $0 stop
- $0 start
- ;;
- reload)
- echo -n "Reload service php-fpm "
- if [ ! -r $php_fpm_PID ] ; then
- echo "warning, no pid file found - php-fpm is not running ?"
- exit 1
- fi
- kill -USR2 `cat $php_fpm_PID`
- echo " done"
- ;;
- *)
- echo "Usage: $0 {start|stop|force-quit|restart|reload}"
- exit 1
- ;;
- esac
保存,添加x权限。
如需开机启动:chkconfig php-fpm on
更多请支持:http://www.webyang.net/Html/web/article_129.html
上一篇: 多对多的查询,三表查询,求mysql语句,该怎么处理
下一篇: PHP 连接MSSQL
推荐阅读
-
linux下编译安装MariaDB 10.4.7,解决错误:cannot access ‘/auth_pam_tool_dir’: No such file or directory
-
Linux下FastDFS图片服务器的搭建
-
FastDFS - Linux下搭建FastDFS 文件服务器与Nginx配置(部署和运维)
-
RedHat Linux9平台下搭建LAMP(Linux+Apache+Mysql+PHP)(1)_PHP教程
-
Linux下编译redis和phpredis的方法,redisphpredis_PHP教程
-
Linux环境下ElasticSearch单实例以及集群搭建
-
Linux CentOS6.0下编译安装MySQL 5.6.22
-
Linux下MySQL 5.6.24的编译安装与部署
-
Linux(CentOS)下PHP扩展PDO编译安装的方法_PHP
-
Linux下编译安装配置MariaDB数据库的方法