php關聯Apache和nginx

來源:互聯網
上載者:User

標籤:資訊   連結   ati   工作   apach   request   格式   127.0.0.1   ...   

編輯apache設定檔httpd.conf,以apache支援php

 vim /etc/httpd/httpd.conf
添加如下二行
AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps

定位至DirectoryIndex index.html 

修改為:
DirectoryIndex index.php index.html

而後重新啟動httpd,或讓其重新載入設定檔即可測試php是否已經可以正常使用。

 

編輯nginx設定檔nginx.conf,以nginx支援php

編輯/etc/nginx/nginx.conf,啟用如下選項:
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;
}

編輯/etc/nginx/fastcgi_params,將其內容更改為如下內容:
fastcgi_param GATEWAY_INTERFACE CGI/1.1;
fastcgi_param SERVER_SOFTWARE nginx;
fastcgi_param QUERY_STRING $query_string;
fastcgi_param REQUEST_METHOD $request_method;
fastcgi_param CONTENT_TYPE $content_type;
fastcgi_param CONTENT_LENGTH $content_length;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param SCRIPT_NAME $fastcgi_script_name;
fastcgi_param REQUEST_URI $request_uri;
fastcgi_param DOCUMENT_URI $document_uri;
fastcgi_param DOCUMENT_ROOT $document_root;
fastcgi_param SERVER_PROTOCOL $server_protocol;
fastcgi_param REMOTE_ADDR $remote_addr;
fastcgi_param REMOTE_PORT $remote_port;
fastcgi_param SERVER_ADDR $server_addr;
fastcgi_param SERVER_PORT $server_port;
fastcgi_param SERVER_NAME $server_name;

並在所支援的首頁面格式中添加php格式的首頁,類似如下:
location / {
root html;
index index.php index.html index.htm;
}

而後重新載入nginx的設定檔:
# service nginx restart

 

在網頁根目錄下建立index.php的測試頁面,測試php是否能正常工作:
# cat > /usr/html/index.php << EOF
<?php
phpinfo();
?>

這個可以查看PHP的資訊;

測試頁面index.php樣本如下:
<?php
$link = mysql_connect(‘127.0.0.1‘,‘root‘,‘123.abc‘);
if ($link)
echo "Success...";
else
echo "Failure...";

mysql_close();
?>

這個可以查看PHP和資料庫是否連結成功

php關聯Apache和nginx

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.