您好,登錄后才能下訂單哦!
一、編譯安裝httpd(httpd 2.4.4,相關(guān)軟件包可到apache官網(wǎng)上下載)
# hwclock -s 將軟件時(shí)間同步為硬件時(shí)間,防止安裝軟件時(shí)出錯(cuò)
1、解決依賴關(guān)系
httpd-2.4.4需要較新版本的apr和apr-util,因此需要事先對(duì)其進(jìn)行升級(jí)。這里使用源碼包進(jìn)行升級(jí)(apr-1.5.2,apr-util-1.5.4 )
(1) 編譯安裝apr
# tar xf apr-1.5.2.tar.bz2
# cd apr-1.5.2
# ./configure --prefix=/usr/local/apr
# make && make install
(2) 編譯安裝apr-util
# tar xf apr-util-1.5.4.tar.bz2
# cd apr-util-1.5.4
# ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr
# make && make install
(3) httpd-2.4.4編譯過程也要依賴于pcre-devel軟件包,需要事先安裝。
#yum -y install pcre-devel
(4) 可在編譯安裝httpd時(shí)會(huì)報(bào)錯(cuò):checking for OpenSSL version >=0.9.7 ... FAILED
#yum -y install openssl-devel
#yum update openssl
2、編譯安裝httpd-2.4.4
# tar xf httpd-2.4.4.tar.bz2
# cd httpd-2.4.4
# ./configure --prefix=/usr/local/apache --sysconfdir=/etc/httpd --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
(含義:--perfix=/usr/local/apache 指定安裝路徑;--sysconfdir=/etc/httpd 指定配置文件路徑;--enable-so apache核心裝載DSO,但實(shí)際不編譯任何動(dòng)態(tài)模塊;--enable-ssl 支持ssl模塊;--enable-cgi支持cgi模塊;--enable-rewrite 支持url重寫;--with-zlib支持zlib庫文件;--with-pcre 包含pcre函數(shù);--with-apr=/usr/local/apr 指定apr的路徑;--with-apr-util=/usr/local/apr-util 指明apr-util路徑;--enable-modules=most 支持模塊;支持共享模塊;--with-mpm=event加載模塊event)
# make && make install
3、修改httpd的主配置文件,設(shè)置其Pid文件的路徑
#vim /etc/httpd/httpd.conf,添加如下行即可:
PidFile "/var/run/httpd.pid"
4、提供SysV服務(wù)腳本/etc/rc.d/init.d/httpd,內(nèi)容如下:
#!/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
而后為此腳本賦予執(zhí)行權(quán)限并加入服務(wù)列表:
# chmod +x /etc/rc.d/init.d/httpd
# chkconfig --add httpd
5.提供執(zhí)行相關(guān)命令所需的環(huán)境變量
#vim /etc/profile.d/httpd.sh,添加以下內(nèi)容:
export PATH=$PATH:/usr/local/apache/bin
6.至此,http服務(wù)配置結(jié)束,可以啟動(dòng)測(cè)試了
#service httpd restart
二、安裝MySQL(我這里通過編譯安裝MySQL-5.6.33(通用二進(jìn)制格式))
1.將下載好的壓縮包解壓至/usr/local,并進(jìn)入此目錄
# tar xf mysql-5.6.33-linux-glibc2.5-x86_64.tar.gz -C /usr/local
# cd /usr/local/
2.為解壓后的目錄創(chuàng)建一個(gè)鏈接,并進(jìn)入此目錄
# ln -sv mysql-5.6.33-linux-glibc2.5-x86_64 mysql
# cd mysql
3.創(chuàng)建MySQL用戶(使其成為系統(tǒng)用戶)和MySQL組
# groupadd -r -g 306 mysql
# useradd -g 306 -r -u 306 mysql
4.使mysql下的所有文件都屬于mysql用戶和mysql組
# chown -R mysql.mysql /usr/local/mysql/*
5.提前準(zhǔn)備一個(gè)分區(qū)用來創(chuàng)建邏輯卷(我這里用/dev/sda5),在此分區(qū)上創(chuàng)建邏輯卷并使其可以開機(jī)自動(dòng)掛載使用。
# pvcreate /dev/sda5
# vgcreate myvg /dev/sda5
# lvcreate -n mydata -L 512M myvg
# mkfs.ext4 /dev/myvg/mydata
#vim /etc/fstab,添加以下內(nèi)容:
/dev/myvg/mydata /mydata ext4 defaults 0 0
# mkdir /mydata
# mount -a
6.創(chuàng)建數(shù)據(jù)目錄,并使其屬于mysql用戶和mysql組,其他人無權(quán)限
# mkdir /mydata/data
# chown -R mysql:mysql /mydata/data/
# chmod o-rw /mydata/data/
7.準(zhǔn)備安裝所需的開發(fā)環(huán)境
# yum -y install perl-Data-Dumper.x86_64
8.準(zhǔn)備就緒,開始安裝
# scripts/mysql_install_db --user=mysql --datadir=/mydata/data
9.安裝完成后為了安全,更改/usr/local/mysql下所有文件的權(quán)限
#chown -R root .
10.準(zhǔn)備啟動(dòng)腳本,并使其開機(jī)自動(dòng)啟動(dòng)
# cp support-files/mysql.server /etc/init.d/mysqld
# chkconfig --add mysqld
# chkconfig --list mysqld
11.編輯數(shù)據(jù)庫配置文件
# cp support-files/my-default.cnf /etc/my.cnf
#vim /etc/my.cnf,修改和添加以下內(nèi)容:
datadir = /mydata/data
12.提供執(zhí)行相關(guān)命令所需的環(huán)境變量
# vim /etc/profile.d/mysql.sh
添加以下內(nèi)容:
export PATH=$PATH:/usr/local/mysql/bin
13.至此,MySQL服務(wù)配置完成,可以啟動(dòng)測(cè)試
# systemctl start mysqld
三、編譯安裝php-5.5.38:(相關(guān)包可以到http://www.php.net/ 下載)
1.安裝前準(zhǔn)備:
1)想讓編譯的php支持mcrypt擴(kuò)展,需要裝兩個(gè)包(這兩個(gè)包需要額外下載):
# rpm -ivh libmcrypt-2.5.8-13.el7.x86_64.rpm
# rpm -ivh libmcrypt-devel-2.5.8-13.el7.x86_64.rpm
2)如果出現(xiàn)出現(xiàn)configure:error:xml2-config not found錯(cuò)誤:
# yum -y install libxml2
#yum -y install libxml2-devel
2.將源碼包下載至本地,開始安裝
# tar xf php-5.5.38.tar.bz2
#cd php-5.5.38
#./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 --enable-fpm --with-mcrypt --with-config-file-path=/etc --with-config-file-scan-dir=/etc/php.d --with-bz2
(釋義:
--prefix=/usr/local/php指定php安裝目錄;--with-mysql=/usr/local/mysqlmysql安裝目錄,對(duì)mysql的支持;--with-openssl增加openssl的支持;--with-mysqli=/usr/local/mysql/bin/mysql_configmysqlin擴(kuò)展技術(shù),不僅可以調(diào)用MySQL的存儲(chǔ)過程,處理MySQL事物,而且可以使訪問數(shù)據(jù)庫工作變得穩(wěn)定;
--enable-mbstring多字節(jié)字符串的支持;
--with-freetype-dir打開對(duì)freetype字體庫的支持;
--with-jpeg-dir對(duì)jpeg格式圖片的支持;
--with-png-dir打開對(duì)png圖片的支持;
--with-zlib打開對(duì)zlib庫的支持;
--with-libxml-dir=/usr打開libxml2庫的支持;
--enable-xml打開對(duì)xml的支持;
--enable-sockets打開socket支;--with-apxs2=/usr/local/apache/bin/apxs;整合apache,apxs功能是使用mod_so中的LoadModule指令,加載指定模塊到apache,要求apache 要打開SO模塊;
--with-mcrypt算法;
--with-config-file-path=/etc指定php.ini(配置文件)位置;--with-config-file-scan-dir=/etc/php.d是搜索下面的ini文件php.ini一起使用;
--with-bz2打開對(duì)bz2文件的支持;
)
#make
#make install
3.為php提供配置文件
# cp php.ini-production /etc/php.ini
4.配置php-fpm
為php-fpm提供Sysv init腳本,并將其添加至服務(wù)列表:
# cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
# chmod +x /etc/rc.d/init.d/php-fpm
# chkconfig --add php-fpm
5.為php-fpm提供配置文件:
# cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf
6.編輯php-fpm的配置文件:
# vim /usr/local/php/etc/php-fpm.conf
配置fpm的相關(guān)選項(xiàng)為你所需要的值
pm.max_children = 50
pm.start_servers = 5
pm.min_spare_servers = 2
pm.max_spare_servers = 8
7.接下來就可以啟動(dòng)php-fpm了:
# service php-fpm start
四、配置虛擬主機(jī)支持使用fcgi
1、注釋中心主機(jī),啟用虛擬主機(jī),并啟用mod_proxy_fcgi.so和mod_proxy.so模塊
(在Apache httpd 2.4以后已經(jīng)專門有一個(gè)模塊針對(duì)FastCGI的實(shí)現(xiàn),此模塊為mod_proxy_fcgi.so,它其實(shí)是作為mod_proxy.so模塊的擴(kuò)充,因此,這兩個(gè)模塊都要加載)
# vim /etc/httpd/httpd.conf
注釋:DocumentRoot "/usr/local/apache/htdocs"
啟用:Include /etc/httpd/extra/httpd-vhosts.conf
LoadModule proxy_module modules/mod_proxy.so
LoadModule proxy_fcgi_module modules/mod_proxy_fcgi.so
添加:AddType application/x-httpd-php .php
AddType application/x-httpd-php.source .phps
修改:DirectoryIndex index.html index.php
2、需要先創(chuàng)建目錄:/www/a.org/,并在其中提供測(cè)試頁面
# mkdir -p /www/a.org
# vim index.php
<h2>my first </h2>
<?php
phpinfo();
?>
3、編輯虛擬主機(jī)配置文件,并檢查有無語法錯(cuò)誤
# vim /etc/httpd/extra/httpd-vhosts.conf
改為如下內(nèi)容
<VirtualHost *:80>
DocumentRoot "/www/a.org"
ServerName www.a.org
ProxyRequests Off(關(guān)閉正向代理功能)
ProxyPassMatch ^/(.*\.php)$ fcgi://127.0.0.1:9000/www/a.org/$1
<Directory "/www/a.org">
Options none
AllowOverride none
Require all granted
</Directory>
ErrorLog "logs/dummy-host.example.com-error_log"
CustomLog "logs/dummy-host.example.com-access_log" common
</VirtualHost>
# httpd -t
4、現(xiàn)在即可重啟httpd,進(jìn)行測(cè)試了!
# systemctl restart httpd
五、安裝xcache,為php加速(我這里用xcache-3.1.2)
1.下載源碼,解壓
# tar xf xcache-3.1.2.tar.bz2
# cd xcache-3.1.2
2.使php加載xcache擴(kuò)展
# /usr/local/php/bin/phpize
在此處可能遇到報(bào)錯(cuò):Cannot find autoconf. Please check your autoconf installation and the $PHP_AUTOCONF environment variable.Then,return this script
原因:Autoconf是一個(gè)用于生成可以自動(dòng)地配置軟件源代碼包以適應(yīng)多種Unix類系統(tǒng)的 shell腳本的工具,需要安裝。
解決辦法:
# cd /usr/src/
#wget http://ftp.gnu.org/gnu/m4/m4-1.4.9.tar.gz
# tar -zvxf m4-1.4.9.tar.gz
# cd m4-1.4.9/
# ./configure && make && make install
# cd ../
# wget http://ftp.gnu.org/gnu/autoconf/autoconf-2.62.tar.gz
# tar -zvxf autoconf-2.62.tar.gz
# cd autoconf-2.62/
# ./configure && make && make install
3.編譯安裝
#./configure --enable-xcache -with-php-config=/usr/local/php/bin/
php-config
#make
#make install
結(jié)束后會(huì)生成:Installing shared extensions: /usr/local/php/lib/php/extensions/no-debug-zts-20121212/
4.編輯配置文件
# mkdir /etc/php.d
# cp xcache.ini /etc/php.d/
5.重啟php-fpm服務(wù)
# service php-fpm restart
此時(shí)訪問到的頁面會(huì)有xcache的擴(kuò)展!
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。