First, the configuration httpd support PHP
1?HTTPD's master configuration file:/usr/local/apache/conf/httd.conf
1. After we have installed the httpd, there will be a prompt set ServerName, we enter the above configuration file, the # number in front of the ServerName removed, and then commented out a PHP, so that the error is not prompted.
2. Add a line: Require all granted if this line is not added, the access is 403
We need to ping the 80 ports first.
Temporarily allow the Linux firewall to open port 80: iptables-i input-p TCP--dport 80-j ACCEPT, you can access it.
Check that the compounding syntax is right:/usr/local/apache/bin/apachectl-t
Reload the configuration file without restarting the service:/usr/local/apache/bin/apachectl Graceful
3?增加一行跟php相关的配制,AddType application/x-httpd-php .php,加在AddType类似行 4?增加一个索引页: DirectoryIndex index.php 直接在index.html后面空格一行加上index.php就好了 5?写一个测试的脚本:vim /usr/local/apache2.4/htodcs/1.php 增加内类
<?php
Echo 123;
?>
(Add a file without restarting, if PHP can not parse the original code is displayed, then we will have to think of no Apache file: Php5_module There is no this module, there is no/usr/local/apche/modules/libphp5.so this file , but also to check that the system files are not Loadmoudel and there is no AddType application/x-httpd-php. php)
Shortcut key: Quick Find History Command ctrl+r re-enter command
6. Restart httpd:/usr/local/apache/bin/apachectl restart
Second, the HTTPD default virtual host
A server can access multiple sites, the first Web site is a virtual host, why we access to index.html 1.php is because DocumentRoot "Usr/local/apache/htdocs This parameter defines the directory where this site.
How to write hosts:/windosw/system32/drivers/etc/hosts in windows open in WordPad. Add a line inside, 192.168.1.23 www.abc.com we open in the browser directly www.abc.com it directly to the 192.168.1.23 in the case of the DNS is not effective.
2?apache's default virtual host, any domain name, as long as the point to this IP, we can access to this site.
3. On a server, I can run multiple domain names, do not want all domains to point to the same IP, so we need to open a virtual host configuration file for it, search in/usr/local/apache/conf/httdp.conf: Extra Find/virtual Hosts this row, the line to remove the #, open this, htdocs inside the document will not be used, the previous servername we will not use.
Open level Two virtual configuration file:/usr/local/apache/conf/extra/httpd-vhosts.conf can define multiple servername, inside the first pair of virtualhost on the table a host
DocumentRoot: Where is the root directory of the Web site such as:/data/wwwroot/abc.com
ServerName: If can be defined as abc.com can only write a
Serveralias: Define aliases: such as: www.abc.com can write multiple
Errorlog: Error log path such as: Logs/abc.com-error_log
Customlog: Access log path such as: "Logs/abc.com-access_log" common
Once the virtual host has been put into effect, the previous definition of servername is invalidated.
5, create the corresponding directory:
Mkdir/data/wwwroot
Mkdir/data/wwwroot/abc.com
6. Create PHP in the corresponding site directory
vim/data/wwwroot/abc.com/index.php
7, check there is no mistake:/usr/local/apache/bin/apachectl-t
8. Reload:/usr/local/apache/bin/apchectl Graceful
9. Test the Virtual Host:
The Curl command is used interchangeably with the browser:
-X For example, if we are going to visit www.abc.com, if we do not bind the hosts, then Ping will ping to the outside web. You can edit/etc/hosts or direct access with curl+x:
Curl-x192.168.1.23:80 www.abc.com
So we can access the virtual mainframe.
If the virtual host is in effect, the master configuration file is invalidated.
The default virtual host is: Regardless of any domain name, as long as the resolution to this IP, will access the default virtual host.
Configuring httpd with PHP and default virtual host