您好,登錄后才能下訂單哦!
一、編譯安裝httpd(httpd 2.4.4,相關軟件包可到apache官網上下載)
# hwclock -s 將軟件時間同步為硬件時間,防止安裝軟件時出錯
1、解決依賴關系
httpd-2.4.4需要較新版本的apr和apr-util,因此需要事先對其進行升級。這里使用源碼包進行升級(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時會報錯: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,但實際不編譯任何動態模塊;--enable-ssl 支持ssl模塊;--enable-cgi支持cgi模塊;--enable-rewrite 支持url重寫;--with-zlib支持zlib庫文件;--with-pcre 包含pcre函數;--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的主配置文件,設置其Pid文件的路徑
#vim /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/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
5.提供執行相關命令所需的環境變量
#vim /etc/profile.d/httpd.sh,添加以下內容:
export PATH=$PATH:/usr/local/apache/bin
6.至此,http服務配置結束,可以啟動測試了
#service httpd restart
二、安裝MySQL(我這里通過編譯安裝MySQL-5.6.33(通用二進制格式))
1.將下載好的壓縮包解壓至/usr/local,并進入此目錄
# tar xf mysql-5.6.33-linux-glibc2.5-x86_64.tar.gz -C /usr/local
# cd /usr/local/
2.為解壓后的目錄創建一個鏈接,并進入此目錄
# ln -sv mysql-5.6.33-linux-glibc2.5-x86_64 mysql
# cd mysql
3.創建MySQL用戶(使其成為系統用戶)和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.提前準備一個分區用來創建邏輯卷(我這里用/dev/sda5),在此分區上創建邏輯卷并使其可以開機自動掛載使用。
# pvcreate /dev/sda5
# vgcreate myvg /dev/sda5
# lvcreate -n mydata -L 512M myvg
# mkfs.ext4 /dev/myvg/mydata
#vim /etc/fstab,添加以下內容:
/dev/myvg/mydata /mydata ext4 defaults 0 0
# mkdir /mydata
# mount -a
6.創建數據目錄,并使其屬于mysql用戶和mysql組,其他人無權限
# mkdir /mydata/data
# chown -R mysql:mysql /mydata/data/
# chmod o-rw /mydata/data/
7.準備安裝所需的開發環境
# yum -y install perl-Data-Dumper.x86_64
8.準備就緒,開始安裝
# scripts/mysql_install_db --user=mysql --datadir=/mydata/data
9.安裝完成后為了安全,更改/usr/local/mysql下所有文件的權限
#chown -R root .
10.準備啟動腳本,并使其開機自動啟動
# cp support-files/mysql.server /etc/init.d/mysqld
# chkconfig --add mysqld
# chkconfig --list mysqld
11.編輯數據庫配置文件
# cp support-files/my-default.cnf /etc/my.cnf
#vim /etc/my.cnf,修改和添加以下內容:
datadir = /mydata/data
12.提供執行相關命令所需的環境變量
# vim /etc/profile.d/mysql.sh
添加以下內容:
export PATH=$PATH:/usr/local/mysql/bin
13.至此,MySQL服務配置完成,可以啟動測試
# systemctl start mysqld
三、編譯安裝php-5.5.38:(相關包可以到http://www.php.net/ 下載)
1.安裝前準備:
1)想讓編譯的php支持mcrypt擴展,需要裝兩個包(這兩個包需要額外下載):
# rpm -ivh libmcrypt-2.5.8-13.el7.x86_64.rpm
# rpm -ivh libmcrypt-devel-2.5.8-13.el7.x86_64.rpm
2)如果出現出現configure:error:xml2-config not found錯誤:
# 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安裝目錄,對mysql的支持;--with-openssl增加openssl的支持;--with-mysqli=/usr/local/mysql/bin/mysql_configmysqlin擴展技術,不僅可以調用MySQL的存儲過程,處理MySQL事物,而且可以使訪問數據庫工作變得穩定;
--enable-mbstring多字節字符串的支持;
--with-freetype-dir打開對freetype字體庫的支持;
--with-jpeg-dir對jpeg格式圖片的支持;
--with-png-dir打開對png圖片的支持;
--with-zlib打開對zlib庫的支持;
--with-libxml-dir=/usr打開libxml2庫的支持;
--enable-xml打開對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打開對bz2文件的支持;
)
#make
#make install
3.為php提供配置文件
# cp php.ini-production /etc/php.ini
4.配置php-fpm
為php-fpm提供Sysv init腳本,并將其添加至服務列表:
# 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的相關選項為你所需要的值
pm.max_children = 50
pm.start_servers = 5
pm.min_spare_servers = 2
pm.max_spare_servers = 8
7.接下來就可以啟動php-fpm了:
# service php-fpm start
四、配置虛擬主機支持使用fcgi
1、注釋中心主機,啟用虛擬主機,并啟用mod_proxy_fcgi.so和mod_proxy.so模塊
(在Apache httpd 2.4以后已經專門有一個模塊針對FastCGI的實現,此模塊為mod_proxy_fcgi.so,它其實是作為mod_proxy.so模塊的擴充,因此,這兩個模塊都要加載)
# 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、需要先創建目錄:/www/a.org/,并在其中提供測試頁面
# mkdir -p /www/a.org
# vim index.php
<h2>my first </h2>
<?php
phpinfo();
?>
3、編輯虛擬主機配置文件,并檢查有無語法錯誤
# vim /etc/httpd/extra/httpd-vhosts.conf
改為如下內容
<VirtualHost *:80>
DocumentRoot "/www/a.org"
ServerName www.a.org
ProxyRequests Off(關閉正向代理功能)
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、現在即可重啟httpd,進行測試了!
# 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擴展
# /usr/local/php/bin/phpize
在此處可能遇到報錯:Cannot find autoconf. Please check your autoconf installation and the $PHP_AUTOCONF environment variable.Then,return this script
原因:Autoconf是一個用于生成可以自動地配置軟件源代碼包以適應多種Unix類系統的 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
結束后會生成: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服務
# service php-fpm restart
此時訪問到的頁面會有xcache的擴展!
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。