您的位置:首页 > 运维架构 > Apache

Apache2.4 + PHP 5.5 源码编译安装

2017-02-28 17:33 423 查看
系统:centos6.4

MySQL5.5.53已经编译安装完成

请见(http://blog.csdn.net/odongyuan1/article/details/58602551

旧版本卸载

rpm -qa|grep httpd
yum remove httpd


编译环境安装

yum install  gcc  gcc-c++


依赖包

这两项必须编译安装:
apr
#wget http://mirrors.cnnic.cn/apache//apr/apr-1.5.2.tar.gz # mkdir /usr/local/apr
# tar xvf apr-1.5.2.tar.gz
#cd apr-1.5.2
#./configure --prefix=/usr/local/apr
#make && make install

apr-util
#wget http://mirrors.cnnic.cn/apache//apr/apr-util-1.5.4.tar.gz # mkdir /usr/local/apr-util
# tar xvf 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


yum install pcre.x86_64 pcre-devel.x86_64 openssl.x86_64 openssl-devel.x86_64


apache编译安装

#mkdir /usr/local/apache
#wget http://mirrors.cnnic.cn/apache/httpd/httpd-2.4.25.tar.gz #tar zxvf httpd-2.4.20.tar.gz
#cd httpd-2.4.20

#./configure \
--prefix=/usr/local/apache \
--sysconfdir=/etc/httpd \
--enable-so \
--enable-ssl \
--enable-cgi \
--enable-rewrite \
--with-zlib \
--with-apr=/usr/local/apr \
--with-apr-util=/usr/local/apr-util \
--enable-mods-shared=most \
--enable-mpms-shared=all \
--with-mpm=prefork


以下为成功显示



make && make install


以下为成功显示



配置Apache的环境变量

#vim /etc/profile.d/apache.sh
export PATH=$PATH:/usr/local/apache/bin

#source /etc/profile.d/apache.sh 立即生效

启动服务
apachectl start


编写服务脚本/etc/init.d/httpd,让其可以使用service起停,并可以加到服务列表中

vim /etc/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/httpd/conf/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/init.d/httpd
chkconfig httpd on
service httpd start


编译安装PHP5.5

下载 PHP 源码包

# wget http://cn2.php.net/distributions/php-5.5.15.tar.bz2 # tar xf php-5.5.15.tar.bz2 -C /usr/local/src/


安装依赖包

首先配置yum源,一定要配置EPEL源,否则mcrypt,mhash相关的软件包安装不了,详细配置请见

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


创建www用户

# groupadd www
# useradd -g www -s /sbin/nologin -M www


编译安装

# cd /usr/local/src/php-5.5.15/

./configure \
--prefix=/usr/local/php \
--with-config-file-path=/etc \
--with-apxs2=/usr/local/apache/bin/apxs \
--enable-inline-optimization \
--disable-debug \
--disable-rpath \
--enable-shared \
--enable-opcache \
--enable-fpm \
--with-fpm-user=www \
--with-fpm-group=www \
--with-mysql=mysqlnd \
--with-mysqli=mysqlnd \
--with-pdo-mysql=mysqlnd \
--with-gettext \
--enable-mbstring \
--with-iconv \
--with-mhash \
--with-mcrypt \
--with-openssl \
--enable-bcmath \
--enable-soap \
--with-libxml-dir \
--enable-pcntl \
--enable-shmop \
--enable-sysvmsg \
--enable-sysvsem \
--enable-sysvshm \
--enable-sockets \
--with-curl \
--with-zlib \
--enable-zip \
--with-bz2 \
--with-readline \
--without-sqlite3 \
--without-pdo-sqlite \
--with-pear


以下为成功显示



make && make install


以下为成功显示



配置PHP

# cp php.ini-development /etc/php.ini


添加PHP命令到环境变量

# vim /etc/profile.d/php.sh
PATH=$PATH:$HOME/bin:/usr/local/php/bin

source /etc/profile.d/php.sh 立即生效


Apache关联PHP

vim /etc/httpd/httpd.conf
添加以下内容
LoadModule php5_module modules/libphp5.so  #这行可能在编译安装 php 的过程中已经自动添加了
<FilesMatch \.php$>
SetHandler application/x-httpd-php
</FilesMatch>

添加index.php
<IfModule dir_module>
DirectoryIndex index.php index.html
</IfModule>


测试Apache是否与PHP关联成功

新建测试页
vi /usr/local/apache/htdocs/index.php 添加一下内容
<?php
phpinfo();
?>




测试PHP与MySQL是否关联成功

新建测试页
vi /usr/local/apache/htdocs/test.php
<?php     $conn=mysql_connect('127.0.0.1','root','ctyun@123');
if ($conn)
echo "Success...";
else
echo "Failure...";
?>




这里遇到点问题:当主机为’localhost’时,连接失败,改为’127.0.0.1’,则连接成功 (参考:http://www.jb51.net/article/54025.htm

参考:http://blog.csdn.net/dwzjs/article/details/38448593

使用php-fpm运行php

说明:PHP最常用的方式是以模块的方式(mod_php)运行在Apache中,也是Apache运行PHP的默认方式。但是在Nginx中,Nginx又使用的是PHP-FPM,从 PHP 5.3.3 开始就成为了 PHP 的内置管理器。Apache 从httpd 2.4.x 也可以使用 mod_proxy_fcgi 和 PHP-FPM 来运行 php

前面编译安装php时,已经支持mod_php和php-fpm,所以apache可以任选一个方式来运行php,且可以再安装一个nginx,用php-fpm方式运行,与Apache共存。

php-fpm服务

拷贝配置文件,在安装目录里
#cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf

拷贝服务脚本,在源码包里
# cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
# chmod +x /etc/init.d/php-fpm


启动php-fpm

# service php-fpm start
Starting php-fpm  done 显示这个则表明启动成功
启动之后默认监听9000端口


php-fpm 可用参数 start|stop|force-quit|restart|reload|status

安装phpMyAdmin

wget http://sw.bos.baidu.com/sw-search-sp/software/0128854f8d323/phpMyAdmin_4.7.0_beta1_all_languages.zip 放到apache的htdocs目录下
unzip phpMyAdmin_4.7.0_beta1_all_languages.zip
cd phpMyAdmin_4.7.0_beta1_all_languages
修改配置文件
vim libraries/config.default.php
将localhost改为127.0.0.1,也可以改为自己的域名
$cfg['Servers'][$i]['host'] = '127.0.0.1';
添加MySQL root密码:
$cfg['Servers'][$i]['password'] = '123456';


登录phpMyAdmin



经测试:只有php5.5和php5.6才能正常打开,php5.2打不开,可能是phpmyadmin版本太高的原因

如果是用apache启用php5.2,可以用nginx启用php5.5来运行php MyAdmin
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: