CentOS6.6下源码安装apache2.4.20+PHP5.6.20

来源:互联网 发布:电脑音乐录音软件 编辑:程序博客网 时间:2024/05/19 04:27
准备
CentOS6.6 Linux机器一台 root权限或者sudo


Apache官网下载:http://httpd.apache.org/download.cgi
由于Apache依赖于APR、APR-Util和PCRE,所以需要下载:

APR + APR-Util:http://apr.apache.org/download.cgi

获取httpd-2.4.20.tar.gz apr-1.5.2.tar.gz apr-util-1.5.4.tar.gz

编译安装apache
# yum install gcc
# yum install pcre-devel


# tar -zxvf apr-1.5.2.tar.gz
# cd apr-1.5.2
# ./configure --prefix=/usr/local/apr   (--prefix指定apr安装的目录)
# make
# make  install


# tar -zxvf apr-util-1.5.4.tar.gz
# cd apr-util-1.5.4
# ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr
# make
# make install


# tar -zxvf httpd-2.4.20.tar.gz
# cd httpd-2.4.20
# ./configure                           \
        --with-apr=/usr/local/apr           \
        --with-apr-util=/usr/local/apr-util \
        --prefix=/usr/local/apache \
        --enable-so                \
        --enable-ssl               \
        --enable-cgi               \
        --enable-rewrite           \
        --with-zlib                \
        --with-pcre                \
        --with-mpm=prefork         \
        --enable-modules=most      \
        --enable-mpms-shared=all
# make
# make install

configure解释
--enable-so  启动模块动态装卸载
--enable-ssl 编译ssl模块
--enable-cgi 支持cgi机制(能够让静态web服务器能够解析动态请求的一个协议)
--enable-rewrite  支持url重写
--with-zlib  支持数据包压缩
--with-pcre  支持正则表达式
--with-apr=/usr/local/apr  指明依赖的apr所在目录
    --with-apr-util=/usr/local/apr-util/  指明依赖的apr-util所在的目录
--enable-modules=most      启用的模块
    --enable-mpms-shared=all   以共享方式编译的模块
    --with-mpm=prefork         指明httpd的工作方式为prefork


编译安装php
安装依赖




yum install gcc bison bison-devel zlib-devel libmcrypt-devel mcrypt mhash-devel openssl-devel libxml2-devel libcurl-devel bzip2-devel readline-devel libedit-devel sqlite-devel
tar -zxvf php-5.6.20.tar.gzcd php-5.6.20./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/ --enable-soap --with-openssl --with-mcrypt --with-zlib --with-curl --with-gd --enable-mbstring --enable-pdo --with-pdo-mysql --enable-sockets --enable-zip --with-mysql --with-apxs2=/usr/local/apache/bin/apxsmake make install




可能出现的问题
1、configure: error: mcrypt.h not found. Please reinstall libmcrypt
解决方案
# yum install -y libmcrypt-devel 
因为centos6.x 默认的yum源没有libmcrypt-devel这个包,可能需要借助第三方yum源
rpm -ivh "http://www.lishiming.net/data/attachment/forum/month_1211/epel-release-6-7.noarch.rpm"
或者自己手动下载编译安装包


2、Sorry, I cannot run apxs. Possible reasons follow:
1. Perl is not installed
2. apxs was not found. Try to pass the path using --with-apxs2=/path/to/apxs
3. Apache was not built using --enable-so (the apxs usage page is displayed)
 
configure: error: Sorry, I cannot run apxs. Either you need to install Perl or you need to pass the absolute path of apxs by using --with-apxs=/absolute/path/to/apxs


解决方案
# head -1 /usr/local/apache/bin/apxs得倒如下内容
#!/replace/with/path/to/perl/interpreter -w
说明没有指明正确的perl执行程序的位置
编辑/usr/local/apache/bin/apxs把这一行更改为"#!/usr/bin/perl -w"
再运行php的configure


3、找不到php.ini
解决方案
进入解压的源码包,将php.ini-production复制到/usr/local/php/并重命名为php.ini




注:缺少依赖,安装依赖。


配置apache conf文件
1、找到AddType,并在其下方新增一行
AddType application/x-httpd-php .php
2、找到DirectoryIndex index.html,并在其结尾处新增index.php
    DirectoryIndex index.html index.php
3、ServerName定义
ServerName 127.0.0.1
4、nginx转发apache日志无法记录真实IP解决方案
在httpd.conf LoadModule php5_module modules/libphp5.so下方添加如下代码:
########## mod_remoteip begin ###########
RemoteIPHeader X-Forwarded-For
RemoteIPInternalProxy aaa.bbb.ccc.ddd 
########## mod_remoteip end ############

#aaa.bbb.ccc.ddd即nginx服务器内部IP
并修改一下两行
LogFormat "%h %a %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined
LogFormat "%h %a %l %u %t \"%r\" %>s %b" common
5、日志按天切割
CustomLog "|/usr/local/apache/bin/rotatelogs /var/apachelog/access_%Y%m%d.log 86400 480" common
注意生成日志的路径,尽量放在空间较大的盘
6、开启静态文件缓存,需确认开启mod_expires.so和mod_headers.so
<IfModule mod_expires.c>
ExpiresActive On 
ExpiresByType text/css A31536000
ExpiresByType application/x-javascript A31536000
ExpiresByType application/javascript A31536000
ExpiresByType application/x-shockwave-flash A31536000
ExpiresByType image/png A31536000
ExpiresByType image/jpeg A31536000
ExpiresByType image/gif A31536000
</IfModule>


<ifmodule mod_headers.c>   
# css, js, swf类的文件缓存一个星期  
<filesmatch “.(css|js|swf)$”> 
header set cache-control “max-age=31536000″ 
</filesmatch> 
 
# jpg,gif,jpeg,png,ico,flv,pdf等文件缓存一年 
<filesmatch “.(ico|gif|jpg|jpeg|png|flv|pdf)$”> 
header set cache-control “max-age=31536000″ 
</filesmatch> 
</ifmodule>
7、禁止显示Apache目录列表
找到Options Indexes FollowSymLinks
改为Options  FollowSymLinks


0 0
原创粉丝点击