设为首页 加入收藏

TOP

Linux下PHP+Nginx环境搭建(五)
2019-09-15 00:33:49 】 浏览:260
Tags:Linux PHP Nginx 环境 搭建
og logs/access.log main; sendfile on; #tcp_nopush on; #keepalive_timeout 0; keepalive_timeout 65; #gzip on; server { listen 80; server_name localhost; #charset koi8-r; #access_log logs/host.access.log main; location / { root html; index index.html index.htm; } #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 html; } # 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 html; # fastcgi_pass 127.0.0.1:9000; # fastcgi_index index.php; # fastcgi_param SCRIPT_FILENAME /scripts$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 html; # 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; # } #} }

修改server配置块中的location和php后端请求配置块

  server {
        listen       80;
        server_name  localhost;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        location / {
            root   html;
            index  index.html index.htm index.php
        }

        #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   html;
        }

        # 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           html;
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.php;
            fastcgi_param  SCRIPT_FILENAME  /scripts$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;
        #}
    }

在location配置块中添加index.php首页

php请求和后端php-fpm模块进行通信,需要配置location ~ .php$配置块

? root:配置php程序文件的根目录

*** 修改配置文件的第一行:”user“属性为我们之前配置的用户**,表示nginx的权限

至此!我们的Nginx和php的环境完成简单的配置!

大功告成

启动步骤:

  • 启动Nginx服务

    # /usr/local/nginx/sbin/nginx
  • 启动php-fpm服务

    # /usr/local/php/sbin/php-fpm
  • 启动mysql服务

    # systemctl start mysqld

phpinfo():

在Nginx的目录html中添加一个php文件:”index.php“

<?php
    phpinfo();
?>

测试数据库连接:

编写一个连接数据库行为的php文件:”mysql.php“

php和mysql之间的连接操作依靠的是”mysqli“

<?php
    $conn = mysqli_connect("127.0.0.1","root","926498");
    if(! $conn ) {
        echo "连接失败".mysqli_connect_error();
    } else {
        echo "连接成功";
    }
?>

至此!PHP+Nginx+MySQL环境完成了基本的搭建!

首页 上一页 2 3 4 5 下一页 尾页 5/5/5
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇PHP 利用PHPExcel到处数据到Excel.. 下一篇PHP最新面试题2019

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目