Apache 2.4 整合 PHP 5.4

配置apache支持php

# vim /usr/local/apache/conf/httpd.conf

在LoadModule php5_module modules/libphp5.so这一行下面添加

AddType application/x-httpd-php .php

添加默认索引

# vim /usr/local/apache/conf/httpd.conf

找到DirectoryIndex,在index.html后面添加index.php

修改主机名

# vim /usr/local/apache/conf/httpd.conf

找到#ServerName www.example.com:80,将这一行前面的注释去掉,改为如下

ServerName 127.0.0.1:80或者ServerName localhost:80

更改apache运行的用户和组

# vim /usr/local/apache/conf/httpd.conf

找到

User daemon
Group daemon

将其改为

User apache
Group apache

如果你用的是www用户和组,则修改为www

开启重写

# vim /usr/local/apache/conf/httpd.conf

找到#LoadModule rewrite_module modules/mod_rewrite.so将其前面的注释#去掉

开启gzip压缩

# vim /usr/local/apache/conf/httpd.conf

找到LoadModule deflate_module modules/mod_deflate.so,将其前面的注释#去掉,并在httpd.conf末尾添加如下

DeflateCompressionLevel 6
AddOutputFilterByType DEFLATE text/html text/plain text/xml application/x-httpd-php
AddOutputFilter DEFLATE js css

隐藏apache版本号

# vim /usr/local/apache/conf/httpd.conf

找到#Include conf/extra/httpd-default.conf将其前面的注释#去掉,并编辑httpd-default.conf

# vim /usr/local/apache/conf/extra/httpd-default.conf

找到ServerTokens Full将其改为ServerTokens Prod

优化mpm参数

# vim /usr/local/apache/conf/httpd.conf

找到#Include conf/extra/httpd-mpm.conf,将其前面的注释#去掉,并编辑httpd-mpm.conf

# vim /usr/local/apache/conf/extra/httpd-mpm.conf

将prefork参数改为如下

    StartServers             5
    MinSpareServers          5
    MaxSpareServers         10
    ServerLimit           2000
    MaxRequestWorkers     1024
    MaxConnectionsPerChild   10000

具体情况请根据自己实际情况修改