Linux安装配置PHP+Nginx的方法:首先安装好php;然后安装好Nginx;接着Nginx与PHP通过本机的9000端口完成数据请求;最后完成测试即可。
[root@ser3 Desktop]# rpm -qa libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 curl-devel libxslt-devel openssl-devel
[root@ser3 Desktop]# yum -y install libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxslt-devel openssl-devel
[root@ser3 Desktop]# tar xf php-7.0.4.tar.gz
[root@ser3 Desktop]# cd php-7.0.4
[root@ser3 php-7.0.4]# ./configure --prefix=/usr/local/php7 --exec-prefix=/usr/local/php7 --with-config-file-path=/usr/local/php7/etc --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 --with-zlib-dir --with-mhash --with-mcrypt --with-openssl-dir --with-jpeg-dir --enable-gd-jis-conv --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
[root@ser3 php-7.0.4]# make
[root@ser3 php-7.0.4]# make test
[root@ser3 php-7.0.4]# make install 2.设置配置文件 [root@ser3 php-7.0.4]# cp php.ini-production /usr/local/php7/etc/php.ini php.ini-development 适合开发测试,如本地测试环境,php.ini-production拥有较高的安全性设定,适合服务器上线运营当产品。一般修改php.ini-production为php.ini,安全性更高,确保测试环境(本地)与正式环境(线上)一致 [root@ser3 php-7.0.4]# cp /usr/local/php7/etc/php-fpm.conf.default /usr/local/php7/etc/php-fpm.conf
[root@ser3 php-7.0.4]# cp /usr/local/php7/etc/php-fpm.d/www.conf.default /usr/local/php7/etc/php-fpm.d/www.conf
[root@ser3 php-7.0.4]# cp ./sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm 3.加入启动服务 [root@ser3 php-7.0.4]# chmod +x /etc/init.d/php-fpm
[root@ser3 php-7.0.4]# chkconfig --add php-fpm 注意的是php7中www.conf这个配置文件配置phpfpm的端口号等信息,如果你修改默认的9000端口号需在这里改,再改nginx的配置 4.启动php服务 [root@ser3 php-7.0.4]# /etc/init.d/php-fpm start
[root@ser3 php-7.0.4]# ps -ef | grep php-fpm 二、Nginx的安装 1.软件下载: wget http://nginx.org/download/nginx-1.6.2.tar.gz直接在Linux上用命令下载 2.安装依赖包pcre和依赖的软件 安装nginx之前,确保已安装了# rpm -qa gcc openssl-devel pcre zlib-devel 软件库 安装pcre库是为了使Nginx支持HTTP Rewriter模块。若pcre默认没有这个安装包,安装则需要下载手动安装。
3. 安装前进行安装包优化 (编译安装过程优化)减小nginx编译后的文件的大小在编译nginx时,默认以debug模式下会插入很多跟踪和ASSERT之类的信息,编译完成后, [root@svr1 nginx-1.6.2]# vim auto/cc/gcc
# debug
CFLAGS="$CFLAGS -g"
注释或删除这两行,即可取消debug模式.
[root@svr1 nginx-1.6.2]# ./configure --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_gzip_static_module --with-openssl=/usr/local/openssl
[root@svr1 nginx-1.6.2]# make && make install
[root@svr1 nginx-1.6.2]# ps -ef | grep nginx
[root@svr1 nginx-1.6.2]# /usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
[root@svr1 nginx-1.6.2]# curl -i 127.0.0.1
......
Welcome to nginx!
If you see this page, the nginx web server is successfully installed and
...... 测试i页显示说明nginx安装没有问题 三、整合Nginx与PHP Nginx自己并不处理动态网页的请求,而且Nginx将得到的动态请求转交给PHP,Nginx的配置文件 # vim /usr/local/nginx/conf/nginx.conf //标的部分是我们后面要修改的 如上图所示,我们在前面已经看到过Nginx是通过本机的9000端口将PHP请求转发给PHP的,而上图我们可以看到PHP自己是从本机的9000端口侦听数据 ,Nginx与PHP通过本机的9000端口完成了数据请求。 四、测试 我们在nginx的配置文件里面已经定义了PHP网站的存放路径,路径是/usr/local/nginx/html 下面我们在这个目录下新建一个PHP页面测试网页,文件名为test.php,内容如下
关闭php
killall php-fpm
php重启
/usr/local/php7/sbin/php-fpm &
关闭nginx
/usr/local/nginx/sbin/nginx -s stop //关闭服务器
重启nginx
/usr/local/nginx/sbin/nginx 开启服务器 重启PHP与nginx后 我们在浏览器中输入http://localhost/test.php ,出现如下界面算成功 相关学习推荐:PHP编程从入门到精通
以上就是Linux如何安装配置PHP+Nginx的详细内容,更多请关注 模板之家(www.mb5.com.cn) 其它相关文章! |