nginx连接php测试

1 nginx连接php

[root@web01 /application/nginx/conf/conf.d]# cat docs.conf
server {
        server_name docs.oldboy.com;
        listen 80;
        root /code;
        index index.php index.html;
        
        location / {

        }

        location ~ \.php$ {
            root /code;
            fastcgi_pass   127.0.0.1:9000;                                      # 请求被location匹配到 ,通过fastcgi_pass(php服务端)交给本地9000端口
            fastcgi_index  index.php;                                           # 默认的php文件
            fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
            include        fastcgi_params;
        }
}

2 测试php与mysql的连接(使用浏览器测试是否连接成功)

php5.6版本测试命令是mysql_connect

$conn = mysql_connect($servername, $username, $password)

php7版本测试命令是mysqli_conncet

$conn = mysqli_connect($servername, $username, $password)

测试时候选则对应的命令否则报错

[root@web01 /application/nginx/conf/conf.d]# tail -f ../../logs/error.log 
2018/12/23 22:55:05 [error] 7040#0: *13 FastCGI sent in stderr: "PHP message: PHP Fatal error:  Call to undefined function mysqli_connect() in /code/mysql.php on line 7" wh
ile reading response header from upstream, client: 10.0.0.1, server: docs.oldboy.com, request: "GET /mysql.php HTTP/1.1", upstream: "fastcgi://127.0.0.1:9000", host: "docs.oldboy.com"
[root@web02 ~]# cat /code/wordpress/mysql.php
         <?php
        $servername = "localhost";
        $username = "root";
        $password = "Bgx123.com";

        // 创建连接
        $conn = mysqli_connect($servername, $username, $password);

        // 检测连接
        if (!$conn) {
            die("Connection failed: " . mysqli_connect_error());
        }
        echo "连接成功";
        ?>