parsing PHP pages in httpd using PHP modules

Source: Internet
Author: User
Tags error status code

Tag: One pre lib specifies share parsing core www. Pager

Adding PHP parsing to the httpd configuration file

Modify the Apache configuration file so that Apache can parse it using PHP
httpd configuration file in/usr/local/httpd/conf/httpd.conf path
Modify the following configuration parameters in the httpd configuration file, and look for the key character configuration in the httpd.conf configuration file.

[[email protected] httpd]# vim conf/httpd.conf~ There are two PHP modules installed, you need to comment out a PHP module. Because httpd cannot load two PHP modules at the same time LoadModule php5_module modules/libphp5.so??? #LoadModule Php7_module modules/ Libphp7.so the comments of the ServerName line, which allows httpd to start and access the default page correctly # ServerName gives the name and port that the server uses to identify it Self.# This can often is determined automatically, but we recommend you specify# it explicitly to prevent problems during startup.## If Your host doesn ' t has a registered DNS name, enter its IP address here. ServerName www.example.com:80 Modify the default directory policy, denied means deny access to the Web directory, granted allow access to the Web directory, prevent open virtual host configuration will display Web page error status code 403# Deny access to The entirety of your server ' s filesystem. You must# explicitly permit access to Web content directories in other # <Directory> blocks Below.#<directory/&G  t;?  allowoverride none? Require all granted</directory> Web root configuration path and permissions configuration, Require all granted here configuration and the above directory access has an associated role, Indicates whether the Web page directory has access to the DocumentRoot "/usr/local/httpd/htdocs" <directory "/usr/local/httpd/htdocs"; ? Options Indexes followsymlinks?? # AllowOverride Controls What directives is placed in. htaccess files. ?? # It can be ' all ', ' None ', or any combination of the keywords:??  allowoverride FileInfo authconfig Limit? AllowOverride None?? # Controls who can get stuff from the this server.  ?  Require All granted</directory> Add PHP Parsing home page, add PHP Parsing home page, in order to access the PHP page correctly recognized <ifmodule dir_module>? DirectoryIndex index.html index.php</ifmodule> Add a PHP parsing configuration item, httpd must add a resolution configuration item in order for the httpd PHP parsing request to be sent to the PHP module for parsing?? # If The addencoding directives above is commented-out, then you?? # probably should define those extensions to indicate Medi  A types:?? #? AddType application/x-compress.  Z?  AddType application/x-gzip. gz. tgz? AddType application/x-httpd-php. php

Check the httpd configuration file is correct, test configuration content, here is the use of a habit, after modifying the configuration file first check for errors in the configuration file, if the configuration file is incorrectly configured and does not check the direct restart service, will cause the service startup error service start termination, Causes the service to stop providing access, which causes the service to be inaccessible for a short period of time, requires checking the configuration file and restarting the service, and using graceful to reload the service configuration

[[email protected] httpd]# /usr/local/httpd/bin/apachectl -tSyntax OK[[email protected] httpd]# /usr/local/httpd/bin/apachectl graceful[[email protected] httpd]# netstat -ntlpActive Internet connections (only servers)Proto Recv-Q Send-Q Local Address ? ? ? ? ? Foreign Address ? ? ? ? State ? ? ? PID/Program name ? ?tcp ? ? ? ?0 ? ? ?0 0.0.0.0:22 ? ? ? ? ? ? ?0.0.0.0:* ? ? ? ? ? ? ? LISTEN ? ? ?1085/sshd ? tcp ? ? ? ?0 ? ? ?0 127.0.0.1:25 ? ? ? ? ? ?0.0.0.0:* ? ? ? ? ? ? ? LISTEN ? ? ?1388/master tcp6 ? ? ? 0 ? ? ?0 :::3306 ? ? ? ? ? ? ? ? :::* ? ? ? ? ? ? ? ? ?  LISTEN ? ? ?8759/mysqld tcp6 ? ? ? 0 ? ? ?0 :::80 ? ? ? ? ? ? ? ? ? :::* ? ? ? ? ? ? ? ? ?  LISTEN ? ? ?873/httpd ? tcp6 ? ? ? 0 ? ? ?0 :::22 ? ? ? ? ? ? ? ? ? :::* ? ? ? ? ? ? ? ? ?  
httpd PHP parsing, write a PHP test file content in the HTTPD web directory

[email protected] httpd]# cat htdocs/index.php

<?phpphpinfo();?>
PHP page parse the access results correctly example: httpd loaded PHP module, and return the page header information, the response of the service-side resolver is php/5.6.37
[[email protected] httpd]# curl -I 192.168.1.233/index.phpHTTP/1.1 200 OKDate: Sun, 29 Jul 2018 09:22:59 GMTServer: Apache/2.4.33 (Unix) PHP/5.6.37X-Powered-By: PHP/5.6.37Content-Type: text/html; charset=UTF-8

If you write a PHP test page but cannot display the PHP test page, you need to check it out in the following ways:
PHP can not parse, first check whether there is a PHP module, whether in the httpd configuration file has php load configuration parameters, whether to write to parse the PHP configuration parameters, test whether to specify the index page of the homepage

 [[email protected] httpd]# /usr/local/httpd/bin/apachectl -MLoaded Modules: core_module (static) so_module (static)-----------------------------------略------------------------- alias_module (shared) php5_module (shared)[[email protected] httpd]# cat conf/httpd.conf |grep php.*soLoadModule php5_module modules/libphp5.so[[email protected] httpd]# cat conf/httpd.conf |grep AddType ? ?# AddType allows you to add to or override the MIME configuration ? ?#AddType application/x-gzip .tgz ?  AddType application/x-compress .Z ?  AddType application/x-gzip .gz .tgz ?  AddType application/x-httpd-php .php ? ?[[email protected] httpd]# cat conf/httpd.conf |grep index.php ?  DirectoryIndex index.html index.php

HTTPD Virtual Host Configuration
About Virtual hosts:
A server can run multiple Web sites, one host multiple domain names specify different sites, each site is a virtual host

Modify the resolution file of Windows, this is used only as a test, modified file path in C:\Windows\System32\drivers\etc\?, open the Hosts file with a notebook, the format of the IP? Domain name, you can specify that an IP has multiple domain names
When the client accesses the httpd of the default virtual host that is not configured, resolves any IP addresses of the domain name if the IP address pointing to the server is directly accessible to the HTTPD's default host

Configure the HTTPD virtual host, open the virtual host profile, modify the conf/httpd.conf configuration file, remove comments or add:

# Virtual hostsInclude conf/extra/httpd-vhosts.conf

When the virtual host configuration is turned on, the site configuration defined in the original master profile fails to stop access, and the settings in the virtual host configuration file are in effect. The following are examples of virtual host configuration items:

[[email protected] httpd]# cat conf/extra/httpd-vhosts.conf # Virtual Hosts## Required modules: mod_log_config-------------------------------省略---------------------------------------<VirtualHost *:80> ?  DocumentRoot "/usr/local/httpd/docs/abcd.com" ? ? <---网站网页加载路径 ?  ServerName abcd.com ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? <---解析的虚拟主机名 ?  ServerAlias www.abcd.com ? ? ? ? ? ? ? ? ? ? ? ?  <---虚拟主机域名 ?  ErrorLog "logs/abcd.com-error_log" ? ? ? ? ? ? ?  <---虚拟主机错误日志 ?  CustomLog "logs/abcd.com-access_log" common ? ? ? <---虚拟主机访问日志</VirtualHost><VirtualHost *:80> ?  DocumentRoot "/usr/local/httpd/docs/123.com" ?  ServerName 123.com ?  ServerAlias www.123.com ?  ErrorLog "logs/123.com-error_log" ?  CustomLog "logs/123.com-access_log" common</VirtualHost>

Create a Web page store directory for the virtual host and use Apachectl to check the configuration file and reload the httpd configuration

[[email protected] httpd]# mkdir -p /usr/local/httpd/docs/abcd.com[[email protected] httpd]# mkdir -p /usr/local/httpd/docs/123.com[[email protected] httpd]# /usr/local/httpd/bin/apachectl -tSyntax OK[[email protected] httpd]# /usr/local/httpd/bin/apachectl graceful

On the Windows side and Linux side briefly authenticate the virtual host access results:

Using the Curl command to access the contents of a Web page under Linux, the results are as follows:

[[email protected] abcd.com]# curl -x192.168.1.233:80 abcd.comabcd.com[[email protected] abcd.com]# curl -x192.168.1.233:80 123.com123.com

parsing PHP pages in httpd using PHP modules

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.