Centos6.10整合Nginx与php7
1、删除旧版本php
yum remove php*
rpm -qa|grep php
rpm -e 名称
2、安装php7 相对应的源
rpm -Uvh https://mirror.webtatic.com/yum/el6/latest.rpm
3、yum 安装php7
yum install php70w php70w-opcache
4、安装其他插件
php70w
php70w-bcmath
php70w-cli
php70w-common
php70w-dba
php70w-devel
php70w-embedded
php70w-enchant
php70w-fpm
php70w-gd
php70w-imap
php70w-interbase
php70w-intl
php70w-ldap
php70w-mbstring
php70w-mcrypt
php70w-mysql
php70w-mysqlnd
php70w-odbc
php70w-opcache
php70w-pdo
php70w-pdo_dblib
php70w-pear
php70w-pecl-apcu
php70w-pecl-imagick
php70w-pecl-xdebug
php70w-pgsql
php70w-phpdbg
php70w-process
php70w-pspell
php70w-recode
php70w-snmp
php70w-soap
php70w-tidy
php70w-xml
php70w-xmlrpc
5、需要安装的插件php-mysqlnd与php-fpm
6、配置php处理器
vim /etc/php.ini
查找cgi.fix_pathinfo
将 ;cgi.fix_pathinfo=1改为cgi.fix_pathinfo=0
7、配置www.conf
vim /etc/php-fpm.d/www.conf
将
user = apache
group = apache
改为
user = nginx
group = nginx
前提是已经创建了nginx用户和nginx组。
如果没有创建,请参考:
添加nginx用户和用户组
groupadd -r nginx
useradd -r -g nginx nginx
8、启动php-fpm
/etc/init.d/php-fpm start
9、配置nginx
vim /etc/nginx/conf.d/default.conf
server {
listen 80;
server_name 127.0.0.1;
# note that these lines are originally from the "location /" block
root /usr/share/nginx/html;
index index.php index.html index.htm;
location / {
try_files $uri $uri/ =404;
}
error_page 404 /404.html;
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
location ~ .php$ {
try_files $uri =404;
root /usr/share/nginx/html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi.conf;
}
}
10、重启nginx
/etc/init.d/nginx restart
11、测试php
vim /usr/share/nginx/html/index.php
输入以下代码
<?php phpinfo(); ?>
然后服务器访问http://127.0.0.1/index.php
出现此界面即为正常。
还没有评论,来说两句吧...