系統: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