首先要下载到apache的源码包,这里我选择下载的是httpd-2.4.25.tar.gz:
wget http://apache.fayea.com/httpd/httpd-2.4.25.tar.gz
下载apr:
wget http://mirrors.cnnic.cn/apache//apr/apr-1.5.2.tar.gz
下载apr-utile:
wget http://mirrors.cnnic.cn/apache//apr/apr-util-1.5.4.tar.gz
下载pcre:
wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.40.tar.gz
安装编译环境:
yum install -y gcc make gcc-c++
1、安装apr
tar zxf apr-1.5.2.tar.gz
cd apr-1.5.2
./configure --prefix=/data/server/apr
make
make install
2、安装apr-utile
tar zxf apr-util-1.5.4.tar.gz
cd apr-util-1.5.4
./configure --prefix=/data/server/apr-util --with-apr=/data/server/apr
make
make install
tar zxf pcre-8.40.tar.gz
cd pcre-8.40
3、安装pcre:
./configure
make
make install
4、安装httpd
tar zxf httpd-2.4.25.tar.gz
cd httpd-2.4.25
./configure --prefix=/data/server/apache --with-apr=/data/server/apr --with-apr-util=/data/server/apr-util --with-pcre=/data/server/pcre
make
make install
接下来可以编译安装php了:
1、安装依赖:php编译时要安装超级多的依赖包,因为php要调用很多库。
yum -y install libxml2-devel libcurl libcurl-devel libmcrypt libmcrypt-devel libpng libpng-devel libjpeg libjpeg-devel gcc gcc-c++ freetype-devel glib2-devel cairo-devel openssl openssl-devel openldap openldap-devel
再加一个网上找到的:
yum install -y gcc gcc-c++ make zlib zlib-devel pcre pcre-devel libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel glibc glibc-devel glib2 glib2-devel bzip2 bzip2-devel ncurses ncurses-devel curl curl-devel e2fsprogs e2fsprogs-devel krb5 krb5-devel openssl openssl-devel openldap openldap-devel nss_ldap openldap-clients openldap-servers
2、下载php源码包:http://php.net/get/php-5.6.30.tar.gz/from/a/mirror,可以选择一个下载,我选择的:
wget http://am1.php.net/get/php-5.6.30.tar.gz/from/this/mirror
因为网址跟了参数,所以修改一下文件名吧:mv mirror.2 php-5.6.30.tar.gz
编译安装php是一个最漫长的过程,也最容易缺少依赖包:
tar zxf php-5.6.30.tar.gz
cd php-5.6.30
./configure --prefix=/data/server/php \
--enable-pdo --with-pdo-mysql --enable-mysqlnd \
--with-mysql=/data/server/mysql --with-mysqli=/data/server/mysql/bin/mysql_config \
--with-freetype-dir --with-jpeg-dir --with-png-dir --with-gd --enable-gd-native-ttf \
--with-config-file-path=/data/server/php/etc \
--with-openssl --with-mhash \
--enable-fpm --enable-sysvsem --enable-sockets --enable-pcntl --enable-mbstring \
--enable-opcache --enable-shmop --enable-zip --with-mcrypt \
--with-zlib --enable-zip --with-curl \
--with-pcre-dir=/data/server/pcre \
--with-fpm-user=www --with-fpm-group=www
make
make install
准备配置文件:
cp /data/server/php/etc/php-fpm.conf.default /data/server/php/etc/php-fpm.conf
修改apache配置文件,设置php-fpm为php代理:
vim /data/server/apache/conf/httpd.conf
LoadModule proxy_module modules/mod_proxy.so
LoadModule proxy_fcgi_module modules/mod_proxy_fcgi.so
把这两行前面的#号去掉,然后最下面增加如下配置:
ServerName 127.0.0.1
SetHandler "proxy:fcgi://127.0.0.1:9000"
修改apache默认运行用户为www
User www
Group www
准备默认网站路径:
mkdir -p /data/web/www/localhost
启动apache:
/data/server/apache/bin/apachectl start
启动php-fpm:
/data/server/php/sbin/php-fpm
一切OK:
vim /data/server/apache/htdocs/index.php
phpinfo();
保存退出看效果吧。
配置apache,允许.htaccess文件:
去掉如下一行的注释:
LoadModule rewrite_module modules/mod_rewrite.so
另外:
AllowOverride All
Require all denied
安装php-memcache扩展:
http://pecl.php.net/package/memcache 下载扩展:
wget http://pecl.php.net/get/memcache-3.0.8.tgz
tar zxf memcache-3.0.8.tgz
cd memcache-3.0.8
/data/server/php/bin/phpize
./configure --enable-memcache --with-php-config=/data/server/php/bin/php-config --with-zlib-dir
make
make install
这时候看到:
Installing shared extensions: /data/server/php/lib/php/extensions/no-debug-non-zts-20131226/
这个目录就是php扩展的目录。当然从phpinfo中也能看到:
附注apache和php-fpm重启脚本:
/data/server/apache/bin/apachectl -k restart
ps aux | grep php-fpm | grep master | awk '{print $2}' | xargs kill -SIGUSR2
万一编译php的时候忘记了gd库,找到自己安装的php版本的php源码,进入ext目录,比如我这次这个:
cd php-5.6.30/ext/gd
./configure --with-php-config=/data/server/php/bin/php-config --with-jpeg-dir --with-freetype-dir
make
make install
然后在php.ini中增加一行:
extension=gd.so
另外,拷贝php到别的主机,也要把依赖的一些库安装好,就是上面的yum安装的。