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 "连接成功";
        ?>

转载于:https://www.cnblogs.com/john5yang/p/10164343.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值