PHP associated Apache and Nginx

Source: Internet
Author: User

Edit Apache config file httpd.conf to Apache support PHP

Vim/etc/httpd/httpd.conf
Add the following two lines
AddType application/x-httpd-php. php
AddType Application/x-httpd-php-source. Phps

Position to DirectoryIndex index.html

Modified to:
DirectoryIndex index.php index.html

Then restart httpd, or let it reload the configuration file to test if PHP is already working.

Edit Nginx Config file nginx.conf to support PHP with Nginx

To edit/etc/nginx/nginx.conf, enable the following options:
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;
}

Edit/etc/nginx/fastcgi_params to change its contents to the following:
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;

and add a PHP-formatted home page in the supported master page format, similar to the following:
Location/{
root HTML;
Index index.php index.html index.htm;
}

Then reload the Nginx configuration file:
# Service Nginx Restart

Create a new index.php test page at the root of the Web page to test if PHP works correctly:
# cat >/usr/html/index.php << EOF
<?php
Phpinfo ();
?>

This can view the PHP information;

The test page index.php example is as follows:
<?php
$link = mysql_connect (' 127.0.0.1 ', ' root ', ' 123.abc ');
if ($link)
echo "Success ...";
Else
echo "Failure ...";

Mysql_close ();
?>

This can see if PHP and database are linked successfully

PHP associated Apache and Nginx

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.