Apache and PHP combined, Apache's default virtual host

Source: Internet
Author: User
Tags fully qualified domain name

One: Apache and PHP Combine

Modifying the Apache configuration file
#vi/usr/local/apache2/conf/httpd.conf
Found it:
<directory/>
Options FollowSymLinks
AllowOverride None
Order Deny,allow
Deny from all
</Directory>
Switch
<directory/>
Options FollowSymLinks
AllowOverride None
Order Deny,allow
Allow from all
</Directory>
Description: If you do not modify this place, we visit the site will be forbidden to access, display 403.
Then find:
AddType application/x-gzip. gz. tgz
Under this line, add the following:
AddType application/x-httpd-php. php
Note that to support PHP script parsing, you must add the corresponding type.
Find again:
<ifmodule dir_module>
DirectoryIndex index.html
</IfModule>
Change the line to read:
<ifmodule dir_module>
DirectoryIndex index.html index.htm index.php
</IfModule>
Description: Increase the index for PHP, if a site default page is index.php, then you have to add this
Index.php's support.
Find again:
#ServerName www.example.com:80
Modified to:
ServerName localhost:80
If you do not remove #, when you start Apache, there will be a warning message "httpd:could not reliably determine the
Server ' s fully qualified domain name, using Localhost.localdomain for ServerName ", looks like a
Error, actually has no effect.
See if there is a problem with the configuration file:
/usr/local/apache2/bin/apachectl-t
If the Syntax OK is displayed, the configuration is no problem. Then start the service:
/usr/local/apache2/bin/apachectl start
The command to check if Apache starts properly is:
PS aux |grep httpd
See if there is a list of processes.

vi/usr/local/apache2/htdocs/1.php
Write:
<?php
echo "PHP works.";
?>
After saving, continue testing:
Curl localhost/1.php
PHP works. Only if this information is displayed is normal parsing. Otherwise, there is no successful resolution. Of course, you can also
To use the browser on the real machine through IP access, such as your virtual machine IP is 192.168.1.101, then in the browser input
http://192.168.1.101/1.php See if only one line of PHP works is displayed. If your visit is not very smooth, please check
Iptables rules.
Iptables-nvl
If there are some rules, please do
Iptables-f
Service Iptables Save

II: Apache Default Virtual Host

Vim/usr/local/apache2/conf/extra/httpd-vhosts.conf
Put the following configuration:
<virtualhost:80>
ServerAdmin [email protected]
DocumentRoot "/usr/local/apache2/docs/dummy-host.example.com"
ServerName dummy-host.example.com
Serveralias www.dummy-host.example.com
Errorlog "Logs/dummy-host.example.com-error_log"
Customlog "Logs/dummy-host.example.com-access_log" common
</VirtualHost>
Modified to:
<virtualhost
:80>
DocumentRoot "/tmp/tmp"
ServerName tmp.com
<Directory/tmp/tmp/>
Order Allow,deny
Deny from all
</Directory>
Create the directories mentioned in the configuration
#mkdir/tmp/tmp
chmod 600/tmp/tmp
/usr/local/apache2/bin/apachectl Graceful #重新加载
In fact, this default virtual host is the first virtual host in a configuration file. About the default virtual host has a special
Point, any resolution to the domain name of this machine, no matter what domain name, as long as in the configuration file is not configured, then will
Access to this host. For example, we directly use IP access, will be access to this site. In order to avoid others
Random parsing, so should be the default is the first virtual host to be banned. Here we use the Allow,deny statement,
has been banned, as for its meaning, will be introduced later. At this time, we use IP to access, found already prompt:
Forbidden
You don't have permission to access/on the this server.

Apache and PHP combined, Apache's default virtual host

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.