Apache和PHP結合、Apache默認虛擬主機
Apache和PHP結合
1、先禁用之前的php7的模塊
[root@centos7 ~]# cat /usr/local/apache2.4/conf/httpd.conf| grep ‘php‘
LoadModule php5_module modules/libphp5.so
#LoadModule php7_module modules/libphp7.so
2、查看下是否禁用php7模塊
[root@centos7 ~]# /usr/local/apache2.4/bin/apachectl -M
rewrite_module (shared)
php5_module (shared) #只有一個,說明禁用了
Syntax OK
3、訪問下apache是否工作,可以看到It works!說明apache已經正常
4、添加php服務解析
[root@centos7 ~]# 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才能解析
5、/usr/local/apache2.4/bin/apachectl graceful
6、
[root@centos7 ~]# vi /usr/local/apache2.4/htdocs/1.php
<?php
phpinfo();
7、vi /usr/local/apache2.4/conf/httpd.conf
<IfModule dir_module>
DirectoryIndex index.html index.php #新增這個
</IfModule>
重載配置文件
/usr/local/apache2.4/bin/apachectl graceful
mv /usr/local/apache2.4/htdocs/1.php /usr/local/apache2.4/htdocs/index.php
8、訪問http://192.168.3.74
apache配置php7來解析
1、[root@centos7 htdocs]# vi /usr/local/apache2.4/conf/httpd.conf
#LoadModule php5_module modules/libphp5.so
LoadModule php7_module modules/libphp7.so
2、[root@centos7 htdocs]# /usr/local/apache2.4/bin/apachectl graceful
3、訪問
Apache默認虛擬主機
1、打開vhosts虛擬主機
[root@centos7 htdocs]# vi /usr/local/apache2.4/conf/httpd.conf
# Virtual hosts
Include conf/extra/httpd-vhosts.conf
2、[root@centos7 htdocs]# /usr/local/apache2.4/bin/apachectl graceful
3、定義了兩個虛擬主機
[root@centos7 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 #別名,也可以用這兩個域名訪問
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、
[root@centos7 htdocs]# mkdir /data/wwwroot/
[root@centos7 htdocs]# mkdir /data/wwwroot/abc.com
[root@centos7 htdocs]# mkdir /data/wwwroot/111.com
5、
[root@centos7 htdocs]# vi /data/wwwroot/abc.com/index.php
<h1>this is abc.com</h1>
[root@centos7 htdocs]# vi /data/wwwroot/111.com/index.php
<h1>this is 111.com</h1>
6、
[root@centos7 htdocs]# /usr/local/apache2.4/bin/apachectl graceful
7、訪問:[root@centos7 abc.com]# curl -x http://127.0.0.1:80 abc.com
錯誤:403拒絕訪問:
解決: 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、訪問
[root@centos7 abc.com]# curl -x127.0.0.1:80 www.abc.com
<h1>this is abc.com</h1>
[root@centos7 abc.com]# curl -x127.0.0.1:80 www.111.com
<h1>this is 111.com</h1>
10、abc.com為默認的頁面
11、無論訪問哪個都為調到這上
[root@centos7 abc.com]# curl -x127.0.0.1:80 123123123asdasd
<h1>this is abc.com</h1>
本文出自 “探索發現新事物” 博客,請務必保留此出處http://shenj.blog.51cto.com/5802843/1980209
Apache和PHP結合、Apache默認虛擬主機