1. 安装php
- 安装依赖库及软件
yum install zlib-devel libxml2-devel libjpeg-devel libjpeg-turbo-devel openssl-devel -y
yum install freetype-devel libpng-devel gd-devel libcurl-devel libxslt-devel -y
2. 安装libiconv-devel
wget https://www.linux.ac.cn/scripts/libiconv-1.14.tar.gz
tar xf libiconv-1.14.tar.gz
cd libiconv-1.14
./configure —prefix=/usr/local/libiconv
make && make install
cd ../
3. 安装libmcrypt、mcrypt、mhash、openssl等库
wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-6.repo
yum install libmcrypt-devel mcrypt mhash openssl-devel -y
4. 下载并编译php
wget http://mirrors.sohu.com/php/php-5.3.27.tar.xz
tar xf php-5.3.27.tar.xz
cd php-5.3.27
./configure —prefix=/app/php5.3.27 —with-apxs2=/app/apache/bin/apxs \
—with-mysql=mysqlnd —with-pdo-mysql=mysqlnd —with-iconv-dir=/usr/local/libiconv \
—with-freetype-dir —with-jpeg-dir —with-png-dir —with-zlib —with-libxml-dir \
—enable-xml —disable-rpath —enable-bcmath —enable-shmop —enable-sysvsem \
—enable-inline-optimization —with-curl —enable-mbregex —enable-mbstring \
—with-mcrypt —with-gd —enable-gd-native-ttf —with-openssl —with-mhash \
—enable-pcntl —enable-sockets —with-xmlrpc —enable-soap —enable-short-tags \
—enable-static —with-xsl —enable-ftp
make
make install
cd ../
ln -s /app/php5.3.27/ /app/php
#提示:—with-mysql=mysqlnd 是用此参数可以允许本地没有mysql数据库
5. 拷贝php.ini配置文件到对应的目录下
cp php.ini-production /app/php/lib/php/php.ini
6. apache跟php结合
编辑httpd.conf文件,在311行下添加如下代码,并保存
AddType application/x-httpd-php .php .phtml
AddType application/x-gzip .gz .tgz
如下图:
7. 设置php首页文件
编辑httpd.conf文件,大约在168行的DirectoryIndex 后面添加 index.php,如下图所示
8. 添加用户,并修改httpd.conf文件里的用户和组
要求跟上面Nginx用户信息一致(uid和gid)
useradd -u 893 -s /sbin/nologin -M www
cd /app/apache/conf/
sed -i -e ‘s@User daemon@User www@g’ -e ‘s@Group daemon@Group www@g’ httpd.conf
9. 重启apache
/app/apache/bin/apachectl graceful
到此Apache跟php结合就安装完成了。