设为首页 收藏本站
开启辅助访问 快捷导航
菜单
猿人部落 主页 资讯 查看内容

nginx 配置php环境

2019-7-23 03:39 发布者: qiyu001 评论 0 查看 996
[root@redhat7 ~]# wget http://am1.php.net/get/php-7.1.2.tar.gz/from/this/mirror[root@redhat7 ~]# tar xzvf php-7.1.2.tar.gz[root@redhat7 ~]# cd php-7.1.2/[root@redhat7 ~]# ./configure--prefix=/usr/loca

[root@redhat7 ~]# wget http://am1.php.net/get/php-7.1.2.tar.gz/from/this/mirror

[root@redhat7 ~]# tar xzvf php-7.1.2.tar.gz

[root@redhat7 ~]# cd php-7.1.2/

[root@redhat7 ~]# ./configure--prefix=/usr/local/php --enable-fpm

[root@redhat7 php-7.1.2]# make&&make install

检察能否 乐成编译装置 PHP

[root@redhat7 php-7.1.2]# php -v

PHP 7.1.2 (fpm-fcgi) (built: Apr 14 2017 20:21:53)

Copyright (c) 1997-2017 The PHP Group


编译装置 实现 后PHP不 具有 设置文件php.ini,此时只需 复制php.ini-production到 /usr/local/lib/php.ini便可 ,php.ini文件一样平常在 /usr/local/lib/和 /etc目次下


[root@localhost php-7.1.2]# cp php.ini-production /usr/local/lib/php.ini

[root@redhat7 php]# /usr/local/php/sbin/php-fpm

[14-Apr-2017 20:59:49] ERROR: failed to open configuration file '/usr/local/php/etc/php-fpm.conf': No such file or directory (2)

[14-Apr-2017 20:59:49] ERROR: failed to load configuration file '/usr/local/php/etc/php-fpm.conf'

[14-Apr-2017 20:59:49] ERROR: FPM initialization failed

启动php-fpm发明 不足 设置文件/usr/local/php/etc/php-fpm.conf

此时只需 复制php-fpm的设置文件在 装置 php时供应 的设置文件的模版/usr/local/php/etc/php-fpm.conf.default到相应/usr/local/php/etc/php-fpm.conf便可

[root@redhat7 etc]# /usr/local/php/sbin/php-fpm

[14-Apr-2017 21:14:32] WARNING: Nothing matches the include pattern '/usr/local/php/etc/php-fpm.d/*.conf' from /usr/local/php/etc/php-fpm.conf at line 125.

[14-Apr-2017 21:14:32] ERROR: No pool defined. at least one pool section must be specified in config file

[14-Apr-2017 21:14:32] ERROR: failed to post process the configuration

[14-Apr-2017 21:14:32] ERROR: FPM initialization failed

[root@redhat7 etc]# cp php-fpm.conf.default /usr/local/php/etc/php-fpm.conf

[root@redhat7 etc]# cp /usr/local/php/etc/php-fpm.d/www.conf.default /usr/local/php/etc/php-fpm.d/www.conf

[root@redhat7 etc]# /etc/init.d/php-fpm

[14-Apr-2017 21:23:02] ERROR: unable to bind listening socket for address '127.0.0.1:9000': Address already in use (98)

[14-Apr-2017 21:23:02] ERROR: FPM initialization failed

[root@redhat7 etc]# netstat -nldp|grep 9000

tcp        0      0 127.0.0.1:9000          0.0.0.0:*              LISTEN      3721/php-fpm: maste

[root@redhat7 php-7.1.2]# cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm

[root@redhat7 php-7.1.2]# chmod a+x /etc/init.d/php-fpm

[root@redhat7 php-7.1.2]# ll /etc/init.d/php-fpm

-rwxr-xr-x 1 root root 2401 4月  14 21:26 /etc/init.d/php-fpm

[root@redhat7 php-7.1.2]# /etc/init.d/php-fpm start

Starting php-fpm [14-Apr-2017 21:28:09] ERROR: unable to bind listening socket for address '127.0.0.1:9000': Address already in use (98)

[14-Apr-2017 21:28:09] ERROR: FPM initialization failed

failed

[root@redhat7 php-7.1.2]# netstat -nldp |grep 9000

tcp        0      0 127.0.0.1:9000          0.0.0.0:*              LISTEN      3721/php-fpm: maste

[root@redhat7 php-7.1.2]# kill 3721

[root@redhat7 php-7.1.2]# netstat -nldp |grep 9000

[root@redhat7 php-7.1.2]# /etc/init.d/php-fpm start

Starting php-fpm  done

[root@redhat7 php-7.1.2]# service php-fpm status

php-fpm (pid 3927) is running...

[root@redhat7 php-7.1.2]# chkconfig --add php-fpm

[root@redhat7 php-7.1.2]# chkconfig php-fpm --level 345 on


设置nginx撑持 PHP

useradd nginx -g nginx

[root@redhat7 php-7.1.2]# vim /usr/local/nginx/conf/nginx.conf

user  nginx nginx;

worker_processes auto;

error_log  logs/error.log;

#error_log  logs/error.log  notice;

#error_log  logs/error.log  info;

pid        logs/nginx.pid;

events {

    worker_connections  1024;

}

http {

    include      mime.types;

    default_type  application/octet-stream;

    #log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '

    #                  '$status $body_bytes_sent "$http_referer" '

    #                  '"$http_user_agent" "$http_x_forwarded_for"';

    #access_log  logs/access.log  main;

server_tokens off;

    sendfile        on;

    tcp_nopush    on;

tcp_nodelay on;

    #keepalive_timeout  0;

    keepalive_timeout  30;

send_timeout 30;

    gzip  on;

    server {

        listen      80;

        server_name  localhost;

        charset UTF-8;

        #access_log  logs/host.access.log  main;

        location / {

            root  /data/webroot;

            index index.php index.html;

        }

        error_page  404              /404.html;

        # redirect server error pages to the static page /50x.html

        #

        error_page  500 502 503 504  /50x.html;

        location = 50x.html {

            root  /data/webroot;

        }

        # proxy the PHP scripts to Apache listening on 127.0.0.1:80

        #

        #location ~ \.php$ {

        #    proxy_pass  http://127.0.0.1;

        #}

        # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000

        #

        location ~ \.php$ {

            root          /data/webroot;

            fastcgi_pass  127.0.0.1:9000;

            fastcgi_index  index.php;

            fastcgi_param  SCRIPT_FILENAME  /data/webroot/$fastcgi_script_name;

            include        fastcgi_params;

        }

        # deny access to .htaccess files, if Apache's document root

        # concurs with nginx's one

        #

        #location ~ /\.ht {

        #    deny  all;

        #}

    }

    # another virtual host using mix of IP-, name-, and port-based configuration

    #

    #server {

    #    listen      8000;

    #    listen      somename:8080;

    #    server_name  somename  alias  another.alias;

    #    location / {

    #        root  /data/webroot;

    #        index  index.html index.htm;

    #    }

    #}

    # HTTPS server

    #

    #server {

    #    listen      443 ssl;

    #    server_name  localhost;

    #    ssl_certificate      cert.pem;

    #    ssl_certificate_key  cert.key;

    #    ssl_session_cache    shared:SSL:1m;

    #    ssl_session_timeout  5m;

    #    ssl_ciphers  HIGH:!aNULL:!MD5;

    #    ssl_prefer_server_ciphers  on;

    #    location / {

    #        root  html;

    #        index  index.html index.htm;

    #    }

    #}

}


创立 test.php测试nginx能否 撑持 PHP

上面 我们 在 /data/webroot这个目次下新建一个PHP页面测试网页,文件名为test.php


而后 重启php和 nginx

[root@redhat7 php-7.1.2]# service php-fpm restart

Gracefully shutting down php-fpm . done

Starting php-fpm  done

[root@redhat7 php-7.1.2]# service nginx restart

Restarting nginx (via systemctl):                          [  判断   ]

重启PHP与nginx后  我们 在 赞赏 器中输入 http://192.168.42.131/test.php


转载: https://www.cnblogs.com/hsia2017/p/6711171.html


来源:https://www.jianshu.com/p/303fe915ba03
免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!

路过

雷人

握手

鲜花

鸡蛋
收藏 邀请
上一篇:PHP学习路线图:PHP从入门到精通教程下一篇:PHP 实例

相关阅读

一周热门

头条攻略!

日排行榜

相关分类