nginx与PHP配置
Posted 鱼丸粗面没鱼丸
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了nginx与PHP配置相关的知识,希望对你有一定的参考价值。
一、安装依赖包
yum -y install libxml2 libxml2-devel openssl openssl-devel curl curl-devel libjpeg libjpeg-devel libpng libpng-devel freetype pcre pcre-devel libxslt libxslt-devel bzip2 bzip2-devel
二、安装php
1.下载php7.0
wget http://php.net/get/php-7.0.2.tar.gz/from/a/mirror
2.解压安装
# tar zxvf php-7.0.2.tar.gz
# cd php-7.0.2
首先查看安装帮助
# ./configure --help
# ./configure --prefix=/usr/local/php \\
--with-curl \\
--with-freetype-dir \\
--with-gd \\
--with-gettext \\
--with-iconv-dir \\
--with-kerberos \\
--with-libdir=lib64 \\
--with-libxml-dir \\
--with-mysqli \\
--with-openssl \\
--with-pcre-regex \\
--with-pdo-mysql \\
--with-pdo-sqlite \\
--with-pear \\
--with-png-dir \\
--with-xmlrpc \\
--with-xsl \\
--with-zlib \\
--enable-fpm \\
--enable-bcmath \\
--enable-libxml \\
--enable-inline-optimization \\
--enable-gd-native-ttf \\
--enable-mbregex \\
--enable-mbstring \\
--enable-opcache \\
--enable-pcntl \\
--enable-shmop \\
--enable-soap \\
--enable-sockets \\
--enable-sysvsem \\
--enable-xml \\
--enable-zip
--with-curl \\
--with-freetype-dir \\
--with-gd \\
--with-gettext \\
--with-iconv-dir \\
--with-kerberos \\
--with-libdir=lib64 \\
--with-libxml-dir \\
--with-mysqli \\
--with-openssl \\
--with-pcre-regex \\
--with-pdo-mysql \\
--with-pdo-sqlite \\
--with-pear \\
--with-png-dir \\
--with-xmlrpc \\
--with-xsl \\
--with-zlib \\
--enable-fpm \\
--enable-bcmath \\
--enable-libxml \\
--enable-inline-optimization \\
--enable-gd-native-ttf \\
--enable-mbregex \\
--enable-mbstring \\
--enable-opcache \\
--enable-pcntl \\
--enable-shmop \\
--enable-soap \\
--enable-sockets \\
--enable-sysvsem \\
--enable-xml \\
--enable-zip
3.编译安装
# make && make install
4配置文件
# cp php.ini-development /usr/local/php/lib/php.ini
# cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf
# cp /usr/local/php/etc/php-fpm.d/www.conf.default /usr/local/php/etc/php-fpm.d/www.conf
# cp /usr/local/php/etc/php-fpm.d/www.conf.default /usr/local/php/etc/php-fpm.d/www.conf
# cp -R ./sapi/fpm/php-fpm /etc/init.d/php-fpm
5修改php-fpm配置文件
php-fpm配置文件位置:(/etc/php-fpm.d/www.conf)
修改
user =www-data
group=www-data
php-fpm配置文件位置:(/etc/php-fpm.d/www.conf)
修改
user =www-data
group=www-data
三、配置nginx解析php
location ~ \\.php$ {
root html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
#fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
root html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
#fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
在/usr/loca/nginx/html/test.php
<?php
phpinfo();
?>
phpinfo();
?>
重启nginx /use/local/sbin/ -s reload
启动php /usr/local/php/bin/php-fpm
四 、访问http://192.168.3.81/test.php
以上是关于nginx与PHP配置的主要内容,如果未能解决你的问题,请参考以下文章