Linux安装配置PHP+Nginx的方法:首先安装好php;然后安装好Nginx;接着Nginx与PHP通过本机的9000端口完成数据请求;最后完成测试即可。
Linux安装配置PHP+Nginx的方法:
一、PHP的安装
1.安装php7.0
软件下载 # wget http://cn2.php测试数据/distributions/php-7.0.4.tar.gz
检查并安装依赖包
[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 install2.设置配置文件
[root@ser3 php-7.0.4]# cp php.ini-production /usr/local/php7/etc/php.iniphp.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/HdhCmsTestconf.default /usr/local/php7/etc/php-fpm.d/HdhCmsTestconf [root@ser3 php-7.0.4]# cp ./sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm3.加入启动服务
[root@ser3 php-7.0.4]# chmod +x /etc/init.d/php-fpm [root@ser3 php-7.0.4]# chkconfig --add php-fpm4.启动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 ......四、测试
我们在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的详细内容!
查看更多关于Linux如何安装配置PHP+Nginx的详细内容...
声明:本文来自网络,不代表【好得很程序员自学网】立场,转载请注明出处:http://www.haodehen.cn/did54991
Linux如何安装配置PHP+Nginx
阅读:46次