学习linux第四十二天

配置httpd支持php

[root@hanlinxy etc]# /usr/local/apache2/bin/httpd -M (查看apache下的模块)
httpd: Could not reliably determine the server's fully qualified domain name, using fe80::2e6b:5bf4:b8b1:e506 for ServerName
Loaded Modules:
core_module (static)
authn_file_module (static)
authn_default_module (static)
authz_host_module (static)
authz_groupfile_module (static)
authz_user_module (static)
authz_default_module (static)
auth_basic_module (static)
include_module (static)
filter_module (static)
log_config_module (static)
env_module (static)
setenvif_module (static)
mpm_prefork_module (static)
http_module (static)
mime_module (static)
status_module (static)
autoindex_module (static)
asis_module (static)
cgi_module (static)
negotiation_module (static)
dir_module (static)
actions_module (static)
userdir_module (static)
alias_module (static)
so_module (static)
php5_module (shared) (说明php是作为httpd的一个扩展模块存在的)

 

 

[root@hanlinxy etc]# /usr/local/php/bin/php -m (查看php下面的模块)
[PHP Modules] (都是静态地所以没标注)
bz2
Core
ctype
date
dom
ereg
exif
fileinfo
filter
gd
hash
iconv
json
libxml
mbstring
mcrypt
mysql
mysqli
openssl
pcre
PDO
pdo_mysql
pdo_sqlite
Phar
posix
Reflection
session
SimpleXML
soap
sockets
SPL
sqlite3
standard
tokenizer
xml
xmlreader
xmlwriter
zlib

[Zend Modules]

 

[root@hanlinxy etc]# ls /usr/local/apache2/conf/httpd.conf
/usr/local/apache2/conf/httpd.conf
[root@hanlinxy etc]# vim !$

ServerName取消注释

可以直接浏览器测试ip输入192.168.3.136如果显示it works说明80端口运行正常

如果报错,进行检查

1.ping 192.168.3.136

2.Telnet 192.168.3.136 80

3.ps aux |grep httpd

4.netstat -lntp |grep httpd

5.systemctl stop iptables

6.systemctl stop firewalld.service

或者加入防火墙规则 iptables -I INPUT -p tcp --dport 80 -j ACCEPT

 

修改第一项

#
<Directory />
AllowOverride None
Require all granted


 

修改第二项 (增加跟php相关的配配置)

#
AddType application/x-compress .Z
AddType application/x-gzip .gz .tgz
AddType application/x-httpd-php .php

#
修改第三项 (增加一个索引页)

<IfModule dir_module>
DirectoryIndex index.html index,php
</IfModule>

 

 

 

测试lamp是否成功

 

测试httpd

[root@hanlinxy conf]# /usr/local/apache2/bin/apachectl -t (检测httpd配置文件的语法是否正确)
Syntax OK

[root@hanlinxy php-7.1.6]# /usr/local/apache2/bin/apachectl graceful (重新加载配置文件)
 

[root@hanlinxy conf]# netstat -lntp |grep httpd (说明httpd启动成功)
tcp6 0 0 :::80 :::* LISTEN 61125/httpd

[root@hanlinxy conf]# curl localhost

<html><body><h1>It works!</h1></body></html>[root@hanlinxy conf]# (这个也是检测httpd是否成功启动的标志)
 

测试php

[root@hanlinxy conf]# vim /usr/local/apache2/htdocs/1.php (访问httpd的时候是访问的这个目录下的文件)
<?php
echo "php解析正常";
?>
[root@hanlinxy conf]# curl localhost/1.php
<?php
echo "php解析正常";
?>

 

碰到apache不能正常解析php的时候的检查项目:

1.[root@hanlinxy modules]# /usr/local/apache2/bin/apachectl -M (看看Apache模块里面有没有php)

 php5_module (shared) 

 

如果没有这个模块,看有没有模块这个文件

[root@hanlinxy modules]# ls /usr/local/apache2/modules/libphp5.so 
/usr/local/apache2/modules/libphp5.so


如果有文件,就检查配置文件有没有libphp5的配置

[root@hanlinxy modules]# vim /usr/local/apache2/conf/httpd.conf

 

LoadModule php5_module modules/libphp5.so
AddType application/x-httpd-php .php
DirectoryIndex index.html index.php
 

默认虚拟主机

vim /usr/local/apache2.4/conf/http.conf

#Virtual hosts
Include conf/extra/httpd-vhosts.conf
vim /usr/local/apache2.4/conf/extra/httpd-vhosts.conf
<VirtualHost *:80>
DocumentRoot "/data/wwwroot/abc.com"
ServceName 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"
ServceName 111.com
ServerAlias www.example.com
Errorlog "logs/111.com-error_log"
CustomLog "logs/111.com-access_log" common
</VirtualHost>
mkdir /data/wwwroot/
mkdir /data/wwwroot/111.com
mkdir /data/wwwroot/abc.com

vim /data/wwwroot/abc.com/index.php
<?php
echo "abc.com";


/usr/local/apache2.4/bin/apachectl -t
/usr/local/apache2.4/bin/apachectl graceful

 

 

 

转载于:https://my.oschina.net/u/3867255/blog/1921177

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值