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