1.5 CentOS7 配置AMP环境之Apache

安装apache

1. 直接用本地的yum安装

yum install httpd httpd-devel
systemctl start httpd.service
systemctl status httpd.service

2. 用安装包安装

2.1 首先安装gcc等开发环境

yum -y installgcc
yum -y installgcc-c++
yum installmake

-- 或者
yum groupinstall "Development Tools"

-- 或者
yum installgccgcc-c++ kernel-devel

2.2 安装libxml2和libxml2-devel

yum install libxml2 libxml2-devel 

2.3 安装相关程序包
相应的程序包可以在网上搜到,先放到/home下

1.tar zxvf httpd-2.2.11.tar.gz
2.cd httpd-2.2.11
./configure --prefix=/usr/local/apache--enable-module=so
make
make install

设置apache开机启动

systemctl enable httpd.service

配置apache

根据需求可选

vi /etc/httpd/conf/httpd.conf
去除 Indexes
修改:
AllowOverride All
DirectoryIndex index.php index.html
#禁止显示版本,修改或添加:
ServerTokens Prod

禁止IP直接访问,防止恶意解析:

vi /etc/httpd/conf.d/default.conf        
Order Allow,Deny        
Deny from all 

设置gzip压缩传输和客户端缓存时间:

vi /etc/httpd/conf.d/xxx.conf
添加:
<VirtualHost *:80>
...
    <IfModule mod_deflate.c>
        AddOutputFilterByType DEFLATE text/plain text/css application/xml application/rss+xml application/atom_xml application/javascript application/x-javascript text/x-component application/x-httpd-php text/html
        AddOutputFilter DEFLATE js css
    </IfModule>
    <IfModule mod_expires.c>
        <FilesMatch "\.(jpg|jpeg|png|gif|js|css)$">
            ExpiresActive On
            ExpiresDefault "accesss plus 60 seconds"
            FileETag None
            Header unset ETag
        </FilesMatch>
    </IfModule>
</VirtualHost>

设置VirtualHost:

vi /etc/httpd/conf.d/xxx.conf
<VirtualHost *:80>
    ServerName xxx.com
    DocumentRoot /var/www/html/xxx.com
    ErrorLog /var/log/xxx.com-error_log
    CustomLog /var/log/xxx.com-access_log common
</VirtualHost>

测试

在浏览器中输入127.0.0.1:10080注意这个端口是博文1.1《VM中CentOS7通过NAT方式设置静态IP》中提到的自己配置的端口
1.5 CentOS7 配置AMP环境之Apache_第1张图片

上述内容则说明配置正确

apache配置的具体信息请看我的另一篇博文:《Linux(CentOS)下的apache服务器配置与管理》

你可能感兴趣的:(apache,yum,amp)