- 安装php7
下载地址:https://secure.php.net/downloads.php
这里下载的是:wget http://ar2.php.net/distributions/php-7.0.6.tar.gz
下载之后解压并进入在解压文件中
安装:./configure –enable-fpm (enable-fpm参数即可开启PHP-FPM) -> make && make install
(PHP在 5.3.3 之后已经讲php-fpm写入php源码核心了)
默认安装目录:
root@iZ25fm7iewtZ:/php-7.0.6# make install Installing shared extensions: /usr/local/lib/php/extensions/no-debug-non-zts-20151012/ Installing PHP CLI binary: /usr/local/bin/ Installing PHP CLI man page: /usr/local/php/man/man1/ Installing PHP FPM binary: /usr/local/sbin/ Installing PHP FPM config: /usr/local/etc/ Installing PHP FPM man page: /usr/local/php/man/man8/ Installing PHP FPM status page: /usr/local/php/php/fpm/ Installing phpdbg binary: /usr/local/bin/ Installing phpdbg man page: /usr/local/php/man/man1/ Installing PHP CGI binary: /usr/local/bin/ Installing PHP CGI man page: /usr/local/php/man/man1/ Installing build environment: /usr/local/lib/php/build/ Installing header files: /usr/local/include/php/ Installing helper programs: /usr/local/bin/ program: phpize program: php-config Installing man pages: /usr/local/php/man/man1/ page: phpize.1 page: php-config.1 Installing PEAR environment: /usr/local/lib/php/ [PEAR] Archive_Tar - already installed: 1.4.0 [PEAR] Console_Getopt - already installed: 1.4.1 [PEAR] Structures_Graph- already installed: 1.1.1 [PEAR] XML_Util - already installed: 1.3.0 [PEAR] PEAR - already installed: 1.10.1 Wrote PEAR system config file at: /usr/local/etc/pear.conf You may want to add: /usr/local/lib/php to your php.ini include_path /php-7.0.6/build/shtool install -c ext/phar/phar.phar /usr/local/bin ln -s -f phar.phar /usr/local/bin/phar Installing PDO headers: /usr/local/include/php/ext/pdo/
- 安装Nginx,见http://www.cnblogs.com/jecyhw/p/5505474.html
- nginx整合php-fpm
1. 启动php-fpm: /usr/local/sbin/php-fpm
报错 [18-May-2016 18:07:58] ERROR: failed to open configuration file '/usr/local/etc/php-fpm.conf': No such file or directory (2) [18-May-2016 18:07:58] ERROR: failed to load configuration file '/usr/local/etc/php-fpm.conf' [18-May-2016 18:07:58] ERROR: FPM initialization failed
到/usr/local/etc/目录下,将php-fpm.conf.default拷贝一份成php-fpm.conf
root@iZ25fm7iewtZ:/# cd /usr/local/php/etc/ root@iZ25fm7iewtZ:/usr/local/etc# cp php-fpm.conf.default php-fpm.conf
然后在编辑php-fpm.conf配置文件
;最后一行改成如下
include=/usr/local/etc/php-fpm.d/*.conf进入到/usr/local/etc/php-fpm.d/目录下,将www.conf.default拷贝一份成www.conf
root@iZ25fm7iewtZ:/usr/local/etc# cd php-fpm.d/ root@iZ25fm7iewtZ:/usr/local/etc/php-fpm.d# cp www.conf.default www.conf
编辑www.conf文件,将user和group改成和nginx.conf中的user和group一致
user = www group = www
再次启动
/usr/local/sbin/php-fpm
root@iZ25fm7iewtZ:/usr/local/etc# ps -ef | grep php-fpm root 3691 1 0 18:49 ? 00:00:00 php-fpm: master process (/usr/local/etc/php-fpm.conf) www-data 3692 3691 0 18:49 ? 00:00:00 php-fpm: pool www www-data 3693 3691 0 18:49 ? 00:00:00 php-fpm: pool www root 4982 29553 0 18:59 pts/1 00:00:00 grep --color=auto php-fpm root@iZ25fm7iewtZ:/usr/local/etc# netstat -tnl | grep 9000 tcp 0 0 127.0.0.1:9000 0.0.0.0:* LISTEN
开机启动php-fpm,开机启动的配置文件是:
/etc/rc.local
,加入/usr/local/sbin/php-fpm
即可vi /etc/rc.local
添加 /usr/local/sbin/php-fpm
修改nginx的配置文件,支持php文件的解析,找到location的添加位置,在后面添加下面这个locationlocation ~ .php$ { root /var/www; #指定php的根目录 fastcgi_pass 127.0.0.1:9000;#php-fpm的默认端口是9000 fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; }
测试nginx.conf是否修改成功
/usr/sbin/nginx -t
重起nginx
/usr/sbin/nginx -s reload
进入到/var/www目录(如果该目录不存在的话,就使用mkdir命令创建)
vi index.php 添加 <?php phpinfo(); ?>
最后在浏览器中输入:localhost/index.php即可