1.安装环境,此处使用rhel7.2,安装httpd2.4.18,php5.6.26,mariadb使用的是之前已经编译安装好的mariadb。
A.编译安装httpd
1.解决依赖关系。httpd-2.4.18需要较新版本的apr和apr-util,因此需要事先对其进行升级。升级方式有两种,一种是通过源代码编译安装,一种是直接升级rpm包。这里选择使用编译源代码的方式进行
(1) 编译安装apr
# tar xf apr-1.5.0.tar.bz2
# cd apr-1.5.0
# ./configure --prefix=/usr/local/apr
# make && make install
(2) 编译安装apr-util
# tar xf apr-util-1.5.3.tar.bz2
# cd apr-util-1.5.3
# ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr
# make && make install
(3) httpd-2.4.18编译过程也要依赖于pcre-devel软件包,需要事先安装。此软件包系统光盘自带,因此,使用本地yum源安装即可。
(4)还需要安装openssl-devel模块,此处使用本地yum源安装。
2.编译安装httpd-2.4.18
# tar xf httpd-2.4.18.tar.bz2
# cd httpd-2.4.18
# ./configure --prefix=/usr/local/apache --sysconfdir=/etc/httpd24 --enable-so --enable-ssl --enable-cgi --enable-rewrite --with-zlib --with-pcre --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util --enable-modules=most --enable-mpms-shared=all --with-mpm=event
# make && make install
3.修改httpd的主配置文件,设置其Pid文件的路径
编辑/etc/httpd/httpd.conf,添加如下行即可:
PidFile "/var/run/httpd.pid"
4.提供SysV服务脚本/etc/rc.d/init.d/httpd,内容如下:
#!/bin/bash
#
# httpd Startup script for the Apache HTTP Server
#
# chkconfig: - 85 15
# description: Apache is a World Wide Web server. It is used to serve \
# HTML files and CGI.
# processname: httpd
# config: /etc/httpd24/httpd.conf
# config: /etc/sysconfig/httpd
# pidfile: /var/run/httpd.pid
# Source function library.
. /etc/rc.d/init.d/functions
if [ -f /etc/sysconfig/httpd ]; then
. /etc/sysconfig/httpd
fi
# Start httpd in the C locale by default.
HTTPD_LANG=${HTTPD_LANG-"C"}
# This will prevent initlog from swallowing up a pass-phrase prompt if
# mod_ssl needs a pass-phrase from the user.
INITLOG_ARGS=""
# Set HTTPD=/usr/sbin/httpd.worker in /etc/sysconfig/httpd to use a server
# with the thread-based "worker" MPM; BE WARNED that some modules may not
# work correctly with a thread-based MPM; notably PHP will refuse to start.
# Path to the apachectl script, server binary, and short-form for messages.
apachectl=/usr/local/apache/bin/apachectl
httpd=${HTTPD-/usr/local/apache/bin/httpd}
prog=httpd
pidfile=${PIDFILE-/var/run/httpd.pid}
lockfile=${LOCKFILE-/var/lock/subsys/httpd}
RETVAL=0
start() {
echo -n $"Starting $prog: "
LANG=$HTTPD_LANG daemon --pidfile=${pidfile} $httpd $OPTIONS
RETVAL=$?
echo
[ $RETVAL = 0 ] && touch ${lockfile}
return $RETVAL
}
stop() {
echo -n $"Stopping $prog: "
killproc -p ${pidfile} -d 10 $httpd
RETVAL=$?
echo
[ $RETVAL = 0 ] && rm -f ${lockfile} ${pidfile}
}
reload() {
echo -n $"Reloading $prog: "
if ! LANG=$HTTPD_LANG $httpd $OPTIONS -t >&/dev/null; then
RETVAL=$?
echo $"not reloading due to configuration syntax error"
failure $"not reloading $httpd due to configuration syntax error"
else
killproc -p ${pidfile} $httpd -HUP
RETVAL=$?
fi
echo
}
# See how we were called.
case "$1" in
start)
start
;;
stop)
stop
;;
status)
status -p ${pidfile} $httpd
RETVAL=$?
;;
restart)
stop
start
;;
condrestart)
if [ -f ${pidfile} ] ; then
stop
start
fi
;;
reload)
reload
;;
graceful|help|configtest|fullstatus)
$apachectl $@
RETVAL=$?
;;
*)
echo $"Usage: $prog {start|stop|restart|condrestart|reload|status|fullstatus|graceful|help|configtest}"
exit 1
esac
exit $RETVAL
而后为此脚本赋予执行权限:
# chmod +x /etc/rc.d/init.d/httpd
加入服务列表:
# chkconfig --add httpd
配置httpd环境变量,让系统可以调用httpd命令
echo 'export PATH=/usr/local/apache/bin:$PATH' > /etc/profile.d/httpd.sh
输出httpd的头文件至系统头文件路径
ln -sv /usr/local/apache/include /usr/include/apache
输出httpd的库文件给系统库查找路径
echo '/usr/local/apache/lib/' > /etc/ld.so.conf.d/apache.conf
重载系统库
ldconfig
输出httpd的man手册到man命令的查找路径
vim /etc/man_db.conf
添加如下字段:
MANDATORY_MANPATH /usr/local/apache/man
以上httpd安装完成了。
B.编译安装php5.6.26
先安装开发包组
#yum -y groupinstall "Desktop Platform Development"
#yum -y groupinstall "Development tools"
php依赖libmcrypt 需先安装libmcrypt-devel 在编译安装时启用xml模块需要安装libxml2-devel
本地系统光盘有的版本不带此rpm包,可以到aliyun镜像上下载安装。
解压安装包
#tar -xf php-5.6.26.tar.gz
#cd php-5.6.26
#./configure --prefix=/usr/local/php --with-mysql=mysqlnd --with-pdo-mysql=mysqlnd --with-openssl --with-mysqli=mysqlnd --enable-mbstring --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir=/usr --enable-xml --enable-sockets --with-apxs2=/usr/local/apache/bin/apxs --with-mcrypt --with-config-file-path=/etc --with-config-file-scan-dir=/etc/php.d --with-bz2 --enable-maintainer-zts
说明:
1、这里为了支持apache的worker或event这两个MPM,编译时使用了--enable-maintainer-zts选项。
2、如果使用PHP5.3以上版本,为了链接MySQL数据库,可以指定mysqlnd,这样在本机就不需要先安装MySQL或MySQL开发包了。mysqlnd从php 5.3开始可用,可以编译时绑定到它(而不用和具体的MySQL客户端库绑定形成依赖),但从PHP 5.4开始它就是默认设置了。
# ./configure --with-mysql=mysqlnd --with-pdo-mysql=mysqlnd --with-mysqli=mysqlnd
# make -j 8 // 用make -j带一个参数,可以把项目在进行并行编译,比如在一台双核的机器上,完全可以用make -j4,让make最多允许4个编译命令同时执行,这样可以更有效的利用CPU资源。
# make -j 8 test
# make -j 8 install
安装完成,为php提供配置文件。
#cp php.ini-production /etc/php.ini
编辑apache配置文件httpd.conf,以apache支持php
# vim /etc/httpd/httpd.conf
1、添加如下二行
AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps
2、定位至DirectoryIndex index.html
修改为:
DirectoryIndex index.php index.html
而后重新启动httpd,或让其重新载入配置文件即可测试php是否已经可以正常使用。
测试页面index.php示例如下:
$link = mysql_connect('10.33.133.160','sqladmin','123456');
if ($link)
echo "Success...";
else
echo "Failure...";
mysql_close();
phpinfo();
?>
以上配置就算完成。
安装phpmyadmin方便远程管理数据库。
下载phpmyadmin ,此处下载的是phpMyAdmin-4.4.15.8-all-languages.tar.bz2版本。
将此文件解压到httpd的文件目录
# tar -xf phpMyAdmin-4.4.15.8-all-languages.tar.bz2 -C /usr/local/apache/htdocs/phpmyadmin
打开phpmyadmin目录,在此目录下是否有config.sample.inc.php文件,如果存在,那么将其改名为config.inc.php。(根据版本不同,有可能直接就有config.inc.php文件,那就无需改名,也有可能根本就没有config.sample.inc.php或者config.inc.php,那我们就到phpmyadmin\libraries目录下将config.default.php复制到phpmyadmin目录下并改名为config.inc.php)。
#cp config.sample.inc.php config.inc.php
修改config.inc.php配置文件如下:
$cfg['Servers'][$i]['auth_type'] = 'cookie';
/* Server parameters */
$cfg['Servers'][$i]['host'] = '10.33.133.160';
$cfg['Servers'][$i]['connect_type'] = 'tcp';
$cfg['Servers'][$i]['compress'] = false;
$cfg['Servers'][$i]['AllowNoPassword'] = false;
$cfg['PmaAbsoluteUri'] = 'http://sqladmin1.xiewl.com/phpmyadmin/';
$cfg['Servers'][$i]['user'] = '';
$cfg['Servers'][$i]['password'] = '';