安裝環境
redhat5.8(2.6.18-194.el5.i386,_)
Apache-httpd 2.2.29
MysQl mysql-5.5.44二進制通用包
PHP php-5.4.43
pcre依賴包
xcache 2.0.1
安裝順序
apr-->apr-util-->httpd-->MySQl-->php-->xcache
1,編譯安裝httpd
安裝httpd依賴環境:apr和par-util,首選需要安裝
1.1安裝apr
解壓apr源碼包,編譯安裝並指定安裝路徑
./configure --prefix=/usr/local/apr
make &&make install
1.2安裝apr-util,安裝時需指定apr安裝路徑
./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr
make && make install
1.3安裝httpd服務(首先需要解決pcre依賴)
1.3.1安裝httpd,需指定apr和par-util安裝路徑
安裝選項說明:
--enable-ssl 啓用https支持
--enable-so 啓用動態共享庫支持
--enable-deflate 壓縮傳輸支持
--enable-proxy-scgi fastcgi支持
--with-mpm=MPM 默認MPM類型
--enable-mpms-shared=all 編譯mpm模塊(all表示編譯所有)
--sysconfdir=/etc/httpd 配置文件路徑
...(詳見,.configure --help)
./configure --prefix=/usr/local/apache --sysconfdir=/etc/httpd --enable-so --enable-rewirte --enable-ssl --enable-cgi --enable-cgid --enable-modules=most --enable-mods-shared=most --enable-mpms-shared=all --with-mpm=event --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util
make &&make install
1.3.2 添加httpd可執行文件到環境變量,及其他相關
修改pid文件路徑,編譯安裝後默認在編譯目錄./logs下
vi /etc/httpd/httpd.conf
在任意位置添加PidFile "/var/run/httpd.pid"
提供SysV服務腳本
vi /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/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/rc.d/init.d/httpd
加入服務列表:
chkconfig --add httpd
修改環境變量
vi /etc/profile.d/httpd.sh
添加如下內容,不需要給予該文件其他權限
export PATH=$PATH:/usr/local/apache/bin
測試httpd服務(需關閉iptables和SELinux)
啓動httpd服務
service httpd start
1.4 安裝mysqld服務,mysql的服務使用通用二進制格式安裝,需要解壓到/usr/local目錄下
創建mysql用戶和組,使用-r選項不允許登錄,且系統服務使用500以下UID和GID
groupadd -g 306 -r myql
useradd -g 306 -r -u 306 mysql
添加目錄軟連接
ln -s mysql-5.5.44-linux2.6-i686 mysql
修改mysql解壓目錄權限
chown-R mysql:mysql mysql/*
創建數據目錄並修改相應權限
chmod 750 /data/
初始化mysql
scripts/mysql_install_db --user=mysql --datadir=/data
複製配置文件到/etc目錄
cp support-files/my-large.cnf /etc/my.cnf
在配置文件尾部添加數據目錄路徑
datadir = /data
拷貝SysV服務腳本,並修改
cp support-files/mysql.server /etc/init.d/mysqld
編輯
basedir=/usr/local/mysql
datadir=/data
chkconfig --add mysqld
爲mysqld添加環境變量
vi /etc/profile.d/mysql.sh
export PATH=$PATH:/usr/local/mysql/bin
添加man環境變量
vi /etc/man.config
MANPATH /usr/local/mysql/man
共享庫文件
vi /etc/ld.so.conf.d/mysql.conf
/usr/local/mysql/lib
使用ldconfig -v 使共享立即生效,-v顯示過程
啓動mysql 並修改root密碼
service mysqld start
mysqladmin -uroot password 'password'
1.4 編譯安裝php模塊
此處將php編譯爲httpd的一個模塊
編譯選項說明
php53-mbstring 多語言支持
--with-openssl openssl支持
--with-freetype-dir 字體庫支持,實現引用特定字體
--with-zlib 壓縮庫支持
--with-apxs2=/usr/local/apache/bin/apxs讓php編譯成apache的模塊
--with-mcrypt 支持額外的加密庫
--enable-maintainer-zts 使用prefork模型使用該設置.使用線程模塊時需要
安裝 mcrypt.h支持,需要的安裝包如下:
mhash-0.9.2-6.el5.i386.rpm
mhash-devel-0.9.2-6.el5.i386.rpm
libmcrypt-2.5.7-5.el5.i386.rpm
libmcrypt-devel-2.5.7-5.el5.i386.rpm
./configure --prefix=/usr/local/php --with-mysql=/usr/local/mysql --with-openssl --with-mysqli=/usr/local/mysql/bin/mysql_config --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
make &&make install
檢查httpd.conf配置文件如下行是否存在,若不存在,則加入
LoadModule php5_module modules/libphp5.so
提供配置文件,在編譯目錄下複製下列文件中的一個到/etc/php.ini
php.ini-development 開發環境
php.ini-production 生產環境
結合php和apache
測試LAMP環境
1.測試httpt和php的結合
編譯安裝的httpd默認文檔位置爲/usr/local/apache/htdocs
編輯如下文件
vi index.php
<html><body><h1>It works!</h1></body></html>
<?php
phpinfo();
?>
vi index.php
<html><body><h1>It works!</h1></body></html>
<?php
$conn=mysql_connect('localhost','root','passwd');
if (!$conn)
echo "Could not connet...";
else
echo "connectting,,,";
?>
<?php
phpinfo();
?>
<?php
phpinfo();
?>
爲php增加xcache拓展
運行/usrlocalphp/bin/phpize
編譯
./configure --enable-xcache --with-php-config=/usr/local/php/bin/php-config
make &&make install
安裝完成後複製Installing shared extensions: 此行後面的路徑/usr/local/php/lib/php/extensions/no-debug-zts-20100525/,後面需要
複製配置文件(沒有php.d目錄可手動創建)
cp xcache.ini /etc/php.d/
vi /etc/php.d/xcache.ini把上面安裝xcache完成後的那個路徑添加到該位置
zend_extension = /usr/local/php/lib/php/extensions/no-debug-zts-20100525/xcache.so
重啓httpd服務