4.Apache and PHP combined with Apache default virtual host

Source: Internet
Author: User
Tags fully qualified domain name

[TOC]

Apache and PHP combined with Apache default virtual host 11.14 ~11.5 configuration Apcahe (httpd) Support Php1.apache (httpd) Master profile:/usr/local/apache2.4/conf/ httpd.conf, edit the file
[[email protected] ~]# vim /usr/local/apache2.4/conf/httpd.conf
2. Why modify the servername before modifying the configuration file
[[email protected] ~]# /usr/local/apache2.4/bin/apachectl restartAH00558: httpd: Could not reliably determine the server‘s fully qualified domain name, using fe80::1d7a:ffe8:8235:a2a5. Set the ‘ServerName‘ directive globally to suppress this messagehttpd not running, trying to start/usr/local/apache2.4/bin/apachectl: 行 79:  2759 段错误               (吐核)$HTTPD -k $ARGV
2.1 Remove the ServerName before the www.example.com:80

FG returns to the previous command

The purpose of modifying it is to allow all requests, otherwise we will return 403 error on access.

[[email protected] ~]# fgvim /usr/local/apache2.4/conf/httpd.conf

2.2 Start/usr/local/apache2.4/bin/apachectl Restart again, the failure is because there are two
[[email protected] ~]# /usr/local/apache2.4/bin/apachectl restarthttpd not running, trying to start/usr/local/apache2.4/bin/apachectl: 行 79:  2827 段错误               (吐核)$HTTPD -k $ARGV

Back to vim/usr/local/apache2.4/conf/httpd.conf, found 79 lines, put the first sentence plus #, but still error, think of the document finally enabled two PHP, should prohibit a

2.3 First off httpd, then vim modified, then start, otherwise error: HTTPd not running, trying to start
[[email protected] ~]# /usr/local/apache2.4/bin/apachectl restarthttpd not running, trying to start
3. Start httpd to see if it started successfully: NETSTAT-LNP |grep httpd
[[email protected] ~]# /usr/local/apache2.4/bin/apachectl stop[[email protected] ~]# vim /usr/local/apache2.4/conf/httpd.conf[[email protected] ~]# /usr/local/apache2.4/bin/apachectl start

The following instructions have been started successfully

[[email protected] ~]# netstat -lnp |grep httpdtcp6       0      0 :::80                   :::*                    LISTEN      3163/httpd   
4. Modify denied4.1 Why to modify, before modifying, access the virtual machine IP

4.2 Troubleshoot whether this IP address is ping

4.3 See if port 80 is up, no telent

    • Find Telent

Pause here, not successful, may be related to the Iptables settings in the previous course.

/usr/local/apache2.4/bin/apachectl start Httpd80 is the key

. Modify denied to granted, allowing all requests to prevent access to the Times 403 error.
<Directory />    AllowOverride none    Require all denied</Directory><Directory />    AllowOverride none    Require all granted</Directory>
5. Added: AddType application/x-httpd-php php, add PHP related configuration, can parse PHP
AddType application/x-compress .ZAddType application/x-gzip .gz .tgzAddType application/x-compress .ZAddType application/x-gzip .gz .tgzAddType application/x-httpd-php .php
6. Change to DirectoryIndex index.html index.php access URL without input
<IfModule dir_module>    DirectoryIndex index.html</IfModule><IfModule dir_module>    DirectoryIndex index.html index.php</IfModule>

Test whether the lamp is successful 1. Test the HTTPTD configuration file correctly:/usr/local/apache2.4/bin/apachectl-t
[[email protected] ~]# /usr/local/apache2.4/bin/apachectl -tSyntax OK

The correct display is "Syntax OK", otherwise continue checking to modify the httpd configuration file.

1.2 If the modification is complete, reload:/usr/local/apache2.4/bin/apachectl graceful2. Test if PHP is parsed correctly

Write a test script, as follows:

[[email protected] ~]# vim /usr/local/apache2.4/htdocs/test.php //写入如下内容<?php   phpinfo(); //打印php的所有函数?>

2.1 Comment out #AddType application/x-httpd-php. php, and then check that the edit has no errors, then reload, parse failed
[[email protected] ~]# vim /usr/local/apache2.4/conf/httpd.conf[[email protected] ~]# /usr/local/apache2.4/bin/apachectl -tSyntax OK[[email protected] ~]# /usr/local/apache2.4/bin/apachectl graceful

Only source code can be displayed, unable to parse

2.4 The source code is, to start with the Apache configuration file check the first:/usr/local/apache2.4/bin/apachectl-m, see there is no php5_module (shared) This module, the second item: [[Email Protected] ~]# ls/usr/local/apache2.4/modules/libphp5.so

/usr/local/apache2.4/modules/libphp5.so

Third, the file exists but not loadmoudle in the httpd configuration.

Fourth item: AddType application/x-httpd-php. php

3. index.php

Many PHP architecture sites have index.php URLs for their URL suffixes.

The origin of it works before 3.1: parsing the index.html
[[email protected] ~]# ls /usr/local/apache2.4/htdocs/index.html  
Test with PHP7.1. Modify the httpd configuration file vim/usr/local/apache2.4/conf/httpd.conf

2. Check for syntax errors, reload the configuration
[[email protected] ~]# /usr/local/apache2.4/bin/apachectl -tSyntax OK[[email protected] ~]# /usr/local/apache2.4/bin/apachectl graceful

11.6 Set httpd default virtual Host 1. The hosts role under Windows

The Hosts file is a system file with no extension, its main function is to speed up the domain name resolution, but also to block the site and so on.
The hosts for Windows

1.1 Windows XP/2003/VISTA/2008/7/8 User Hosts file is in the "c:\windows\system32\drivers\etc,

Note that this file must be on the system disk, and if your system is on the D disk, modify the previous drive letter yourself. As shown

Add code to the hosts

1.2 Under Windows cmd, ping just entered the IP and URL, you can ping through

Just edit the IP and the website are annotated with the # number, ping the URL when the IP address of the public network, and not just the virtual test machine IP

1.3 Save the edits before the hosts (IP and URLs), open the browser, enter the URL, show Itworks

The important note here is to open the HTTPD service:

[[email protected] ~]# /usr/local/apache2.4/bin/apachectl start

You can also access test.php

2. Edit the httpd configuration file
[[email protected] ~]# vim /usr/local/apache2.4/conf/httpd.conf
2.1 Search for/extra in the file contents, locate the virtual host configuration file, and then remove the comment

3. Edit the virtual host configuration file/usr/local/apache2.4/conf/extra/httpd-vhosts.conf
[[email protected] ~]# vim /usr/local/apache2.4/conf/extra/httpd-vhosts.conf

Edit its contents as:

<VirtualHost *:80>                                     //每个VirtualHost代表一个主机,一个主机代表一个网站        #ServerAdmin [email protected]     //定义管理员的邮箱,作用不大可以删除    DocumentRoot "/data/wwwroot/abc.com"                  //指定网站的根目录在哪    ServerName abcd.com                                                   //定义网站名称,只能写一个    ServerAlias www.abcd.com www.123.com                                             //设置网站别名,支持多个网站    ErrorLog "logs/abcd.com-error_log"       //错误日志,保存和虚拟主机网站一样的名字方便读取    CustomLog "logs/abcd.com-error_log" common</VirtualHost>
3.1 The default host (www.example.com 192.168.) in the original Apache configuration file becomes invalid after the virtual host is in effect.
<VirtualHost *:80>    #ServerAdmin [email protected]    DocumentRoot "/data/wwwroot/xavi.com"    ServerName xavi.com     ServerAlias www.example.com    ErrorLog "logs/xavi.com-error_log"    CustomLog "logs/xavi.com-access_log" </VirtualHost>
3.2 Create a site root that corresponds to a virtual host
[[email protected] ~]# mkdir /data/wwwroot/[[email protected] ~]# mkdir /data/wwwroot/abcd.com[[email protected] ~]# mkdir /data/wwwroot/xavi.com

Create a Index.php,vim in the corresponding site root directory
[[email protected] ~]# vim /data/wwwroot/abcd.com/index.php<?phpecho "abc.com";php?>

You can also simply edit the PHP code without ending

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

Error, no reason found

[Email protected] ~]#/usr/local/apache2.4/bin/apachectl-t
Ah00526:syntax error on line of/usr/local/apache2.4/conf/extra/httpd-manual.conf:
Invalid command ' languagepriority ', perhaps misspelled or defined by a module no included in the server configuration

4.Apache and PHP combined with 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.