一、安装PHP
1.安装依赖
yum install libmcrypt-devel mhash-devel libxslt-devel libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel zlib zlib-devel glibc glibc-devel glib2 glib2-devel bzip2 bzip2-devel ncurses ncurses-devel curl curl-devel e2fsprogs e2fsprogs-devel krb5 krb5-devel libidn libidn-devel openssl openssl-devel
源码编译安装,去http://www.sourceforge.net下载Libmcrypt,mhash,mcrypt安装包
libmcrypt(libmcrypt-2.5.8.tar.gz ):
mcrypt(mcrypt-2.6.8.tar.gz ):
mhash(mhash-0.9.9.9.tar.gz ):
2 .安装Libmcrypt
tar -zxvf libmcrypt-2.5.8.tar.gz cd libmcrypt-2.5.8 ./configure make make install
说明:libmcript默认安装在/usr/local
3.安装mhash
tar -zxvf mhash-0.9.9.9.tar.gz cd mhash-0.9.9.9 ./configure make make install
4.安装mcrypt
tar -zxvf mcrypt-2.6.8.tar.gz cd mcrypt-2.6.8 ./configure make
make install
5.下载、安装PHP
wget http://cn2.php.net/distributions/php-5.4.7.tar.gz tar zvxf php-5.4.7.tar.gz cd php-5.4.7 ./configure --prefix=/usr/local/php --enable-fpm --with-mcrypt --enable-mbstring --disable-pdo --with-curl --disable-debug --disable-rpath --enable-inline-optimization --with-bz2 --with-zlib --enable-sockets --enable-sysvsem --enable-sysvshm --enable-pcntl --enable-mbregex --with-mhash --enable-zip --with-pcre-regex --with-mysql --with-mysqli --with-gd --with-jpeg-dir --enable-opcache=no make all install
以上就完成了php-fpm的安装。
下面是对php-fpm运行用户进行设置
cd /usr/local/php cp etc/php-fpm.conf.default etc/php-fpm.conf vi etc/php-fpm.conf
修改
user = www-data
group = www-data
如果www-data用户不存在,那么先添加www-data用户
groupadd www-data
useradd -g www-data www-data
二、编译安装nginx
然后按照http://www.nginx.cn/install 安装nginx
三、修改nginx配置文件以支持php-fpm
nginx安装完成后,修改nginx配置文件为,nginx.conf
其中server段增加如下配置,注意 fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;内容配置,否则会出现No input file specified.错误
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
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;
}
四、创建测试php文件
创建php文件
在/usr/local/nginx/html下创建index.php文件,输入如下内容
<?php
echo phpinfo();
?>
五、启动服务
启动php-fpm和nginx
/usr/local/nginx/sbin/nginx
/usr/local/php/sbin/php-fpm
关闭防火墙
service iptables stop //临时关闭
php-fpm关闭重启见文章结尾
六、浏览器访问
访问http://你的服务器ip/index.php 就可以见到php信息了。
本机浏览器访问不到Linux虚拟机中的nginx开启页面
1、使用该执行打开端口文件
vi /etc/sysconfig/iptables
2、将你要打开的端口设置上就行了,这里是打开80端口
-A INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT
3、输入:wq保存退出
4、service iptables restart,使设置生效
php-fpm 关闭:
kill -INT cat /usr/local/php/var/run/php-fpm.pid
php-fpm 重启:
kill -USR2 cat /usr/local/php/var/run/php-fpm.pid
查看php-fpm进程数:
ps aux | grep -c php-fpm
8.命令行下执行php,提示找不到命令
-bash: /usr/bin/php: No such file or directory
vi /etc/profile
在文件底部增加一行配置
export PATH=/usr/local/php/bin:$PATH
保存退出
source /etc/profile
一些报错
configure: error: off_t undefined; check your library configuration
我也遇到这个问题了,报的前一个错是
configure: error: Don’t know how to define struct flock on this system, set –enable-opcache=no
我把–enable-opcache=no加上,结果报了这个错;
最后,
[root@localhost php-7.1.7]#vim /etc/ld.so.conf.d/local.conf
# 添加一行
/usr/local/lib
[root@localhost php-7.1.7]# ldconfig -v
而且把–enable-opcache=no去掉也不报错了。
ERROR: No pool defined. at least one pool section must be specified in config file
root@ubuntu:/opt/php7# /opt/php7/sbin/php-fpm
[22-Sep-2015 14:29:00] WARNING: Nothing matches the include pattern '/opt/php7/etc/php-fpm.d/*.conf' from /opt/php7/etc/php-fpm.conf at line 125.
[22-Sep-2015 14:29:00] ERROR: No pool defined. at least one pool section must be specified in config file
[22-Sep-2015 14:29:00] ERROR: failed to post process the configuration
[22-Sep-2015 14:29:00] ERROR: FPM initialization failed
大概意思就是说找不到 opt/php7/etc/php-fpm.d/目录下的配置文件。 进入里面的目录,会有一个www.conf.default文件。执行下面命名复制一份
root@ubuntu:/opt/php7/etc/php-fpm.d/# cp www.conf
复制好之后,编辑该文件
root@ubuntu:/opt/php7/etc/php-fpm.d/# nano www.conf
定位到里面文件的 user = nobody 和 group = nobody ,调整为 www-data。这一步和5版编译安装一样。最后启动PHP-FPM
root@ubuntu:~# /opt/php7/sbin/php-fpm
root@ubuntu:~#