Apache和PHP结合
1、先禁用之前的php7的模块
[[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、查看下是否禁用php7模块
[[email protected] ~]# /usr/local/apache2.4/bin/apachectl -M
rewrite_module (shared)
php5_module (shared) #只有一个,说明禁用了
Syntax OK
3、访问下apache是否工作,可以看到It works!说明apache已经正常
4、添加php服务解析
[[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才能解析
5、/usr/local/apache2.4/bin/apachectl graceful
6、
[[email protected] ~]# 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、[[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、访问
Apache默认虚拟主机
1、打开vhosts虚拟主机
[[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、定义了两个虚拟主机
[[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 #别名,也可以用这两个域名访问
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
<h1>this is abc.com</h1>
[[email protected] htdocs]# vi /data/wwwroot/111.com/index.php
<h1>this is 111.com</h1>
6、
[[email protected] htdocs]# /usr/local/apache2.4/bin/apachectl graceful
7、访问:[[email protected] 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、访问
[[email protected] abc.com]# curl -x127.0.0.1:80 www.abc.com
<h1>this is abc.com</h1>
[[email protected] abc.com]# curl -x127.0.0.1:80 www.111.com
<h1>this is 111.com</h1>
10、abc.com为默认的页面
11、无论访问哪个都为调到这上
[[email protected] abc.com]# curl -x127.0.0.1:80 123123123asdasd
<h1>this is abc.com</h1>