Apache and PHP Combine
1, first disable the previous PHP7 module
[Email protected] ~]# cat/usr/local/apache2.4/conf/httpd.conf| grep ' php '
LoadModule Php5_module modules/libphp5.so
#LoadModule Php7_module modules/libphp7.so
2. Check if the PHP7 module is disabled
[Email protected] ~]#/usr/local/apache2.4/bin/apachectl-m
Rewrite_module (Shared)
Php5_module (shared) #只有一个, stating that the
Syntax OK
3, visit the next Apache whether to work, you can see it works! instructions Apache has been normal
650) this.width=650; "Src=" Https://s1.51cto.com/oss/201711/09/a2c3409799a176addea5d8aaafb37acb.png-wh_500x0-wm_3 -wmp_4-s_841585805.png "title=" 1.png "alt=" A2c3409799a176addea5d8aaafb37acb.png-wh_ "/>
4. Add PHP Service parsing
[Email protected] ~]# vi/usr/local/apache2.4/conf/httpd.conf
AddType application/x-compress. Z
AddType application/x-gzip. gz. tgz
addtype application/x-httpd-php PHP #添加下这行后, Apache can parse
5,/usr/local/apache2.4/bin/apachectl Graceful
6.
[Email protected] ~]# vi/usr/local/apache2.4/htdocs/1.php
<?php
Phpinfo ();
650) this.width=650; "Src=" Https://s4.51cto.com/oss/201711/09/0315499068a0c12b1a69327ee52ca7b5.png-wh_500x0-wm_3 -wmp_4-s_2062284237.png "title=" 2.png "alt=" 0315499068a0c12b1a69327ee52ca7b5.png-wh_ "/>
7, vi/usr/local/apache2.4/conf/httpd.conf
<ifmodule dir_module>
DirectoryIndex index.html index.php #新增这个
</IfModule>
Overloaded configuration Files
/usr/local/apache2.4/bin/apachectl Graceful
mv/usr/local/apache2.4/htdocs/1.php/usr/local/apache2.4/htdocs/index.php
8. Visit http://192.168.3.74
650) this.width=650; "Src=" Https://s5.51cto.com/oss/201711/09/a16ae17cf5ff925f1341a8cbe259816c.png-wh_500x0-wm_3 -wmp_4-s_2871950076.png "title=" 3.png "alt=" A16ae17cf5ff925f1341a8cbe259816c.png-wh_ "/>
Apache Configuration Php7 to parse
1, [[email protected] htdocs]# vi/usr/local/apache2.4/conf/httpd.conf
#LoadModule Php5_module modules/libphp5.so
LoadModule Php7_module modules/libphp7.so
2, [[email protected] htdocs]#/usr/local/apache2.4/bin/apachectl Graceful
3. Visit
650) this.width=650; "Src=" Https://s1.51cto.com/oss/201711/09/2edfb486d42636828b7a9f22b3799e5d.png-wh_500x0-wm_3 -wmp_4-s_2218255659.png "title=" 4.png "alt=" 2edfb486d42636828b7a9f22b3799e5d.png-wh_ "/>
Apache Default Virtual Host
1. Open Vhosts Virtual Host
[Email protected] htdocs]# vi/usr/local/apache2.4/conf/httpd.conf
# Virtual Hosts
Include conf/extra/httpd-vhosts.conf
2, [[email protected] htdocs]#/usr/local/apache2.4/bin/apachectl Graceful
3. Two virtual hosts defined
[Email protected] htdocs]# cat/usr/local/apache2.4/conf/extra/httpd-vhosts.conf
<virtualhost *:80>
DocumentRoot "/data/wwwroot/abc.com" #网站根目录
ServerName abc.com #域名
Serveralias www.abc.com www.123.com #别名, can also be accessed with these two domains
Errorlog "Logs/abc.com-error_log" #错误日志
Customlog "Logs/abc.com-access_log" Common #标准日志输出
</VirtualHost>
<virtualhost *:80>
DocumentRoot "/data/wwwroot/111.com"
ServerName 111.com
Serveralias www.111.com www.example.com
Errorlog "Logs/111.com-error_log"
Customlog "Logs/111.com-access_log" common
</VirtualHost>
4.
[Email protected] htdocs]# mkdir/data/wwwroot/
[Email protected] htdocs]# mkdir/data/wwwroot/abc.com
[Email protected] htdocs]# mkdir/data/wwwroot/111.com
5.
[Email protected] htdocs]# vi/data/wwwroot/abc.com/index.php
[Email protected] htdocs]# vi/data/wwwroot/111.com/index.php
6.
[Email protected] htdocs]#/usr/local/apache2.4/bin/apachectl Graceful
7, visit: [[email protected] abc.com]# curl-x http://127.0.0.1:80 abc.com
Error: 403 Access denied:
650) this.width=650; "Src=" Https://s1.51cto.com/oss/201711/09/c4b401c14f2bb629ddafdcefb1acb2df.png-wh_500x0-wm_3 -wmp_4-s_1770810071.png "title=" 5.png "alt=" C4b401c14f2bb629ddafdcefb1acb2df.png-wh_ "/>
Solution: vi/usr/local/apache2.4/conf/httpd.conf
<directory/>
Options FollowSymLinks
AllowOverride None
Order Deny,allow
# Deny from all
</Directory>
8,/usr/local/apache2.4/bin/apachectl Graceful
9. Visit
[Email protected] abc.com]# curl-x127.0.0.1:80 www.abc.com
[Email protected] abc.com]# curl-x127.0.0.1:80 www.111.com
10, ABC.com is the default page
11, regardless of access which is transferred to this
[Email protected] abc.com]# curl-x127.0.0.1:80 123123123ASDASD
This article is from the "Discover new things" blog, make sure to keep this source http://shenj.blog.51cto.com/5802843/1980209
Apache and PHP combined, Apache default virtual host