2018-3-1 10 weeks 2 lessons Apache and PHP combined, Apache default virtual host

Source: Internet
Author: User
Tags fully qualified domain name

11.14/11.15 Apache and PHP combined



1, modify servername

There are similar error prompts when you start Apache

[[email protected] ~]#/usr/local/apache2.4/bin/apachectl restartAH00558:httpd:Could not reliably determine the server ' s fully qualified domain name, using Localhost.localdomain. Set the ' ServerName ' directive globally to suppress this message

If you do not want to see this error, then go to/usr/local/apache2.4/conf/httpd.conf to find servername, and remove the # comment and save the exit.

Restart Apache, error occurred

Go into the/usr/local/apache2.4/conf/httpd.conf and comment out the PHP7, just let Apache load only php5

Save after exiting, restart Apache, everything is OK

[[email protected] ~]# /usr/local/apache2.4/bin/apachectl restarthttpd not  Running, trying to start[[email protected] ~]# ps aux | grep  httpdroot      45504  0.2  0.8 253576   8892 ?        ss   21:48   0:00  /usr/local/apache2.4/bin/httpd -k restartdaemon    45505  0.0   0.6 540404  6936 ?        Sl    21:48   0:00 /usr/local/apache2.4/bin/httpd -k restartdaemon     45506  0.0  0.8 540404  8972 ?         sl   21:48   0:00 /usr/local/apache2.4/bin/ httpd -k restartdaemon    45507  0.0  0.8 540404  8976 ?         sl   21:48   0:00 /usr/local/apache2.4/bin/ httpd -k restartroot      45590  0.0  0.0  112676   984 pts/2    s+   21:49   0:00  grep --color=auto httpd


2, modify require all denied

[[email protected] ~]# iptables-i input-p TCP--dport 80-j ACCEPT

Access 192.168.65.128 from inaccessible to It works!

In Windows, turn on Telnet and use Telnet 192.168.65.128 80 to view the unicom situation

Unicom will jump to the sub-interface after

If it does not, the connection is displayed

Cannot access 192.168.65.128 after the change is completed

Therefore, you need to change the configuration file Require all denied to Require all granted


• Check the configuration file syntax:

[[email protected] ~]#/usr/local/apache2.4/bin/apachectl-tsyntax OK


• Reload the configuration:

[Email protected] ~]#/usr/local/apache2.4/bin/apachectl Graceful

(The advantage is not to restart the server, the maximum load is not successful, will not be killed in town)


3, add a row AddType application/x-httpd-php php , otherwise PHP cannot parse

4, put DirectoryIndex index.html Change to DirectoryIndex index.html index.php

Verify that Apache support does not support PHP parsing

Test the PHP script:

vim/usr/local/apache2.4/htodcs/1.php

[Email protected] ~]#/usr/local/apache2.4/bin/apachectl-t

Syntax OK

[Email protected] ~]#/usr/local/apache2.4/bin/apachectl Graceful

Visit http://192.168.65.128/1.php,


If you access 192.168.65.128/1.php, you see

You need to check the Apache configuration file

First, check to see if the PHP5 module is loaded

[Email protected] ~]#/usr/local/apache2.4/bin/apachectl-m

See if there's/usr/local/apache2.4/modules/libphp5.so file.

If you have a libphp5.so file, check to see if the Apache configuration file is loaded libphp5.so

Then, check that the configuration file has no AddType application/x-httpd-php. PHP lines


Check DirectoryIndex index.html index.php this line again, but this line does not affect

index.php, you can jump to index.php under the default.


shortcut keys:CTRL + R input keywords, you can search the command history of the command about the keyword


Ban php5, use only PHP7

Libphp5.so commented out in the configuration file, with libphp7.so

[Email protected] ~]#/usr/local/apache2.4/bin/apachectl-t

Syntax OK

[Email protected] ~]#/usr/local/apache2.4/bin/apachectl Graceful

version changed when accessing http://192.168.65.128/1.php

/usr/local/php7/bin/php-i | Less results when the text form is displayed.



11.16/11.17 Apache Default Virtual Host


httpd multiple websites running under one service, multiple domain names

When DNS is not in effect, you can define the hosts file in Windows

The format is: IP domain name ...


/usr/local/apache2.4/conf/httpd.conf can only define one servername

[Email protected] ~]# vim/usr/local/apache2.4/conf/httpd.conf

Search Httpd-vhost, get rid of #

Edit the Virtual host profile (multiple servername can be defined):

[Email protected] ~]# vim/usr/local/apache2/conf/extra/httpd-vhosts.conf


ServerAdmin Admin mailbox, can be deleted

DocumentRoot Web site root directory

ServerName Domain name

Serveralias aliases (more than one is preferable)

Errorlog error Log

Customlog Access Log


Create a Directory

[[email protected] ~]# mkdir/data/wwwroot/[[email protected] ~]# mkdir/data/wwwroot/abc.com[[email protected] ~]# mkdir /data/wwwroot/111.com[[email protected] ~]# vim/data/wwwroot/abc.com/index.php

Define a index.php

With no end.

A PHP is also defined in 111.com

[Email protected] ~]# vim/data/wwwroot/111.com/index.php

[Email protected] ~]#/usr/local/apache2.4/bin/apachectl-tsyntax ok[[email protected] ~]#/usr/local/apache2.4/bin/ Apachectl Graceful

if the domain name configuration is not found, the default virtual host configuration file is found, for example www.111.com in the configuration file does not have this domain name or alias, so directly find the default configuration, that is, the first paragraph, so it is abc.com


If there are errors, please correct them and learn from each other.


2018-3-1 10 weeks 2 lessons Apache and PHP combined, Apache 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.