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


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM