編譯安裝AMP:
A(Apache):
1.http://httpd.apache.org
2.http://archive.apache.org/dist/
M(Mysql/MariaDB):
http://www.mysql.com/download
https://mariadb.org/download/
P(PHP):
https://www.php.net/releases/php
組合:
httpd-2.4.27(apr-1.5.2 + apr-util-1.5.4) + MariaDB-5.5.57 + php-5.6.31html
編譯安裝的前提條件——完整的編譯環境:
1."Development Tools"和"Server Platform Development"兩個程序包組;
2.pcre-devel
3.libevent-develmysql
編譯環境的安裝方式: # yum -y groupinstall "Development Tools" "Server Platform Development" # yum -y install pcre-devel # yum -y install libevent-devel
注意:在編譯AMP程序以前,須要確保沒有使用rpm程序包安裝過AMP中的任何組件,包括:httpd,httpd-tools,mysql-server/mariadb-server,php,php-fpm,...linux
AMP編譯安裝之A(Apache):
1.卸載原有的AMP
~]# rpm -q mysql-server httpd php
~]# rpm -ql httpd-tools
~]# yum erase -y httpd-tools
~]# yum erase -y php httpd mysql-serversql
2.安裝編譯須要的環境
~]# yum groupinstall -y "Development Tools"
~]# yum groupinstall -y "Server Platform Development"
~]# yum install -y pcre-devel
~]# yum install -y libevent-develshell
3.編譯安裝apr
~]# tar xf apr-1.5.2.tar.bz2
~]# cd apr-1.5.2
apr-1.5.2]# ./configure --prefix=/usr/local/apr-1.5.2
apr-1.5.2]# cat /proc/cpuinfo
//查看虛擬機核心數#,"process"從0開始計
apr-1.5.2]# make -j 4
apr-1.5.2]# make install數據庫
4.編譯安裝apr-util
apr-1.5.2]# cd
~]# tar xf apr-util-1.5.4.tar.bz2
~]# cd apr-util-1.5.4
apr-util-1.5.4]# ./configure --prefix=/usr/local/apr-util-1.5.4 --with-apr=/usr/local/apr-1.5.2
apr-util-1.5.4]# ./configure --prefix=/usr/local/apr-util-1.5.4 --with-apr=/usr/local/apr-1.5.2
apr-util-1.5.4]# make -j 4
apr-util-1.5.4]# make installapache
5.編譯安裝httpd
apr-util-1.5.4]# cd
~]# tar xf httpd-2.4.27.tar.bz2
~]# cd httpd-2.4.27
httpd-2.4.27]# ./configure --prefix=/usr/local/apache-2.4.27 --sysconfdir=/etc/httpd-2.4.27 --enable-so --enable-ssl --enable-cgi --enable-rewrite --enable-modules=most --enable-mpms-shared=all --with-apr=/usr/local/apr-1.5.2 --with-apr-util=/usr/local/apr-util-1.5.4 --with-zlib --with-pcre --with-mpm=prefork
httpd-2.4.27]# make -j 4
httpd-2.4.27]# make installvim
6.編譯完成後的收尾工做
1) 導出二進制文件:
httpd-2.4.27]# vim /etc/profile.d/httpd-2.4.27.sh
export PATH=/usr/local/apache-2.4.27/bin:$PATH
httpd-2.4.27]# source /etc/profile.d/httpd-2.4.27.sh
//使用source命令(.)來使其內容生效;
2) 導出幫助文檔:
httpd-2.4.27]# vim /etc/man.config
找到"MANPATH"這個配置段,添加:
MANPATH /usr/local/apache-2.4.27/man
3) 導出頭文件
httpd-2.4.27]# ln -sv /usr/local/apache-2.4.27/include/ /usr/include/httpd
4) 導出庫文件
檢測是否有httpd目錄下的lib64目錄,沒有則建立:
httpd-2.4.27]# mkdir -pv /usr/local/apache-2.4.27/lib64
建立一個文件:
httpd-2.4.27]# vim /etc/ld.so.conf.d/httpd.conf
添加:/usr/local/apache-2.4.27/lib64
完成則可進行導出:
httpd-2.4.27]# ldconfig -vapi
7.配置工做
由於編譯安裝的httpd.conf文件沒有"PidFile"配置、"Include"配置也沒有生效,因此要在httpd.conf主配置文件中編輯:
httpd-2.4.27]# vim /etc/httpd-2.4.27/httpd.conf
爲了規範和好看,在"ServerRoot"配置下添加:
PidFile /var/run/httpd-2.4.27.pid
在"Include"配置段添加:
Include /etc/httpd-2.4.27/extra/*.conf
8.提供sysv風格的服務管理腳本:/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-2.4.27/httpd.conf # config: /etc/sysconfig/httpd-2.4.27 # pidfile: /var/run/httpd-2.4.27.pid # Source function library. . /etc/rc.d/init.d/functions if [ -f /etc/sysconfig/httpd-2.4.27 ]; then . /etc/sysconfig/httpd-2.4.27 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-2.4.27/bin/apachectl httpd=${HTTPD-/usr/local/apache-2.4.27/bin/httpd} prog=httpd pidfile=${PIDFILE-/var/run/httpd-2.4.27.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 上述腳本建立以後,須要完成下列操做: httpd-2.4.27]# chmod +x /etc/init.d/httpd 若想設置開機自啓動httpd服務: # chkconfig --add httpd # chkconfig httpd on
9.測試httpd服務
1.關閉防火牆:
httpd-2.4.27]# iptables -F
2.禁用SELinux:
httpd-2.4.27]# setenforce 0
3.瀏覽器訪問服務器地址:
172.16.69.1
顯示:
It works!
編譯安裝AMP:
A(Apache):
1.http://httpd.apache.org
2.http://archive.apache.org/dist/
M(Mysql/MariaDB):
http://www.mysql.com/download
https://mariadb.org/download/
P(PHP):
https://www.php.net/releases/
組合:
httpd-2.4.27(apr-1.5.2 + apr-util-1.5.4) + MariaDB-5.5.57 + php-5.6.31
編譯安裝的前提條件——完整的編譯環境:
1."Development Tools"和"Server Platform Development"兩個程序包組;
2.pcre-devel
3.libevent-devel
編譯環境的安裝方式: # yum -y groupinstall "Development Tools" "Server Platform Development" # yum -y install pcre-devel # yum -y install libevent-devel
注意:在編譯AMP程序以前,須要確保沒有使用rpm程序包安裝過AMP中的任何組件,包括:httpd,httpd-tools,mysql-server/mariadb-server,php,php-fpm,...
AMP編譯安裝之M(Mysql/MariaDB)
1.解壓縮二進制程序包到指定目錄(/usr/local)
~]# tar xf mariadb-5.5.57-linux-x86_64.tar.gz -C /usr/local
~]# cd /usr/local
2.建立用於啓動服務和管理數據的用戶和組:
# useradd -r -u 306 -g mysql mysql //若是此前組裝過mysql,則不須要建立了;在/etc/passwd下可查
3.建立數據目錄並修改相應文件的權限:
local]# ln -sv /usr/local/mariadb-5.5.57-linux-x86_64/ mysql
local]# cd mysql
mysql]# mkdir -pv /var/lib/mysql
mysql]# chown mysql. /var/lib/mysql
4.導出二進制文件
mysql]# vim /etc/profile.d/mariadb-5.5.57.sh
export PATH=/usr/local/mysql/bin:$PATH
mysql]# . /etc/profile.d/mariadb-5.5.57.sh
//使用source命令(.)來使其內容生效;
5.導出幫助文檔
mysql]# vim /etc/man.config
找到"MANPATH"這個配置段,添加:
MANPATH /usr/local/mysql/man
6.導出庫文件
mysql]# vim /etc/ld.so.conf.d/mariadb-5.5.57.conf
添加:
/usr/local/mysql/lib
7.導出頭文件
mysql]# ln -sv /usr/local/mysql/include/ /usr/include/mysql
8.導出配置文件
mysql]# ls /usr/local/mysql/support-files/
//查看此目錄下全部以".cnf"結尾的文件;根據服務器的內存導出"my.cnf"配置文件到指定目錄;
mysql]# cp support-files/my-large.cnf /etc/my.cnf
9.配置/etc/my.cnf
mysql]# vim /etc/my.cnf
在[mysqld]配置段添加:
datadir = /var/lib/mysql
innodb_file_per-table = ON
skip_name_resolve = ON
10.配置服務啓動的腳本
mysql]# cp -a support-files/mysql.server /etc/init.d/mysqld
//確保文件已經被賦予執行的權限
若想設置開機自啓動mysql服務:
# chkconfig mysqld on
11.啓動服務測試
mysql]# service mysqld start
Starting MySQL.181224 16:37:52 mysqld_safe Logging to '/var/lib/mysql/localhost.localdomain.err'.
181224 16:37:52 mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql
... ERROR!
//發生錯誤,提示數據目錄方面錯誤
mysql]# scripts/mysql_install_db --user=mysql --datadir=/var/lib/mysql
//初始化數據庫配置
mysql]# service mysqld start
Starting MySQL.181224 16:43:26 mysqld_safe Logging to '/var/lib/mysql/localhost.localdomain.err'.
181224 16:43:26 mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql
. SUCCESS!
//成功啓動
mysql]# ss -tnl
mysql]# mysql
//若啓動成功進入交互式命令界面則成功編譯安裝
編譯安裝AMP:
A(Apache):
1.http://httpd.apache.org
2.http://archive.apache.org/dist/
M(Mysql/MariaDB):
http://www.mysql.com/download
https://mariadb.org/download/
P(PHP):
https://www.php.net/releases/
組合:
httpd-2.4.27(apr-1.5.2 + apr-util-1.5.4) + MariaDB-5.5.57 + php-5.6.31
編譯安裝的前提條件——完整的編譯環境:
1."Development Tools"和"Server Platform Development"兩個程序包組;
2.pcre-devel
3.libevent-devel
編譯環境的安裝方式: # yum -y groupinstall "Development Tools" "Server Platform Development" # yum -y install pcre-devel # yum -y install libevent-devel
注意:在編譯AMP程序以前,須要確保沒有使用rpm程序包安裝過AMP中的任何組件,包括:httpd,httpd-tools,mysql-server/mariadb-server,php,php-fpm,...
AMP編譯安裝之P(PHP):
1.想要正確的編譯php-5.6.31,可能須要解決下列依賴關係:
若使用本地光盤的yum倉庫:
libxml2-devel
gd-devel
freetype-devel
libmcrypt-devel
注意:gd-devel-2.0.35-11.el6.x86_64.rpm在DVD2光盤鏡像中,能夠拷貝出來,再掛載DVD1光盤鏡像,完成安裝; 也能夠配置其餘的yum倉庫,直接就能安裝上 ~]# yum install -y libxml2-devel freetype-devel libmcrypt-devel ~]# yum install gd-devel -y
2.解壓縮二進制程序包到指定目錄
~]# tar xf php-5.6.31.tar.bz2
~]# cd php-5.6.31
3.編譯安裝PHP
php-5.6.31]# ./configure --prefix=/usr/local/php-5.6.31 --enable-fpm --with-mysql=/usr/local/mysql --with-mysqli=/usr/local/mysql/bin/mysql_config --with-openssl --enable-mbstring --enable-xml --enable-sockets --with-freetype-dir --with-libxml-dir=/usr --with-zlib --with-apxs2=/usr/local/apache-2.4.27/bin/apxs --with-config-file-path=/etc/php-5.6.31.ini --with-config-file-scan-dir=/etc/php-5.6.31.d --with-gd --with-jpeg-dir --with-png-dir --with-mcrypt
php-5.6.31]# make -j 4 && make install
4.建立必編譯安裝缺乏且必須的配置文件
php-5.6.31]# cp php.ini-production /etc/php-5.6.31.ini
php-5.6.31]# mkdir -pv /etc/php-5.6.31.d
php-5.6.31]# cp sapi/fpm/php-fpm.conf /etc/php-5.6.31.d/
5.編輯配置文件
php-5.6.31]# vim /etc/php56.d/php-fpm.conf
;;;;;;;;;;;;;;;;;;;;
; Pool Definitions ;
;;;;;;;;;;;;;;;;;;;;
[global] ;pid = /usr/loca/php-5.6.31/var/run/php-fpm.pid [www] user = nobody group = nobody listen = 127.0.0.1:9000 ;listen.backlog = 65535 ;listen.allowed_clients = 127.0.0.1 pm = dynamic pm.max_children = 5 pm.start_servers = 2 pm.min_spare_servers = 1 pm.max_spare_servers = 3 ;pm.max_requests = 500 ;pm.status_path = /fpm-status 尋找適當的位置添加; php_value[session.save_handler] = files php_value[session.save_path] = /var/lib/php-5.6.31/session 添加完成後完善目錄文件並受權根據[www]: php-5.6.31]# mkdir -pv /var/lib/php-5.6.31/session php-5.6.31]# chown nobody. /var/lib/php-5.6.31/session
6.爲php-fpm服務程序提供一個sysv風格的腳本
php-5.6.31]# cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
php-5.6.31]# chmod +x /etc/init.d/php-fpm
若想設置開機自動: # chkconfig --add php-fpm # chkconfig php-fpm on
7.導出二進制文件:
php-5.6.31]# vim /etc/profile.d/php-5.6.31.sh
export PATH=/usr/local/php-5.6.31/bin:$PATH
php-5.6.31]# . /etc/profile.d/php-5.6.31.sh
//使用source命令(.)來使其內容生效;
8.修改服務啓動腳本中的內容
php-5.6.31]# vim /etc/init.d/php-fpm
1) 添加一個變量:
scan_confi_dir=/etc/php56.d
2) 修改一個變量定義:
php_fpm_CONF=${prefix}/etc/php-fpm.conf
改成:
php_fpm_CONF=${scan_conf_dir}/php-fpm.conf
修改的結果: scan_conf_dir=/etc/php-5.6.31.d/ php_fpm_BIN=${exec_prefix}/sbin/php-fpm php_fpm_CONF=${scan_conf_dir}/php-fpm.conf php_fpm_PID=${prefix}/var/run/php-fpm.pid
9.檢查php-fpm進程狀態:
# ss -tnl # netstat -tnl AMP編輯完成的構建: 1.編輯httpd的主配置文件: php-5.6.31]# vim /etc/httpd-2.4.27/httpd.conf 1) 取消註釋,啓動容許httpd的虛擬主機配置:大約在485行 # Virtual hosts Include /etc/httpd-2.4.27/extra/httpd-vhosts.conf 2) 容許默認的主頁格式:大約在260行 <IfModule dir_module> DirectoryIndex index.html index.php </IfModule> 2.編輯虛擬主機配置文件: php-5.6.31]# vim /etc/httpd-2.4.27/extra/httpd-vhosts.conf <VirtualHost 172.16.69.1:80> DocumentRoot "/myvhost/vhost1" ServerName www.vayne36.com ErrorLog "logs/error_log" Customlog "logs/access_log" common DIrectoryIndex index.php ProxyRequests Off ProxyPassMatch ^/(.*\.php)$ fcgi://127.0.0.1:9000/myvhost/vhost1/$1 <Directory "/myvhost/vhost1"> Options None AllowOverride None Require all granted </Directory> </VirtualHost> 3.檢查語法排查錯誤 php-5.6.31]# httpd -t AH00526: Syntax error on line 46 of /etc/httpd-2.4.27/extra/httpd-vhosts.conf: Invalid command 'ProxyRequests', perhaps misspelled or defined by a module not included in the server configuration //缺乏某個模塊,關於vhost的模塊沒有被加載 4.編譯httpd的主配置文件,取消註釋,加載模塊: php-5.6.31]# vim /etc/httpd-2.4.27/httpd.conf 大約在120行,取消註釋,把: #LoadModule proxy_module modules/mod_proxy.so #LoadModule proxy_fcgi_module modules/mod_proxy_fcgi.so 改成: LoadModule proxy_module modules/mod_proxy.so LoadModule proxy_fcgi_module modules/mod_proxy_fcgi.so 5.檢查語法 php-5.6.31]# httpd -t AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using localhost.localdomain. Set the 'ServerName' directive globally to suppress this message Syntax OK 6.添加PHP應用:phpMyAdmin vhost1]# tar xf phpMyAdmin-3.5.4-all-languages.tar.gz vhost1]# service httpd reload 7.關閉防火牆,禁用SELinux vhost1]# iptables -F vhost1]# setenforce 0 8.重啓服務,測試 vhost1]# service httpd reload 瀏覽器訪問: http://www.vayne36.com/phpMyAdmin-3.5.4-all-languages/ 9.修改服務器的/etc/hosts文件: 添加: 172.16.69.1 www.vayne36.com 10.測試請求/響應的數量: vhost1]# ab -c 10 -n 100 http://www.vayne36.com/phpMyAdmin-3.5.4-all-languages/index.php 輸出結果顯示: Requests per second: 112.57 [#/sec] (mean)
編譯安裝xcache以加速php訪問:
1.下載xcache的源代碼:
http://xcache.lighttpd.net/
2.利用Xshell的新建文件傳輸把Xcache源代碼包傳進來並解壓縮 ~]# tar xf xcache-3.2.0.tar.gz ~]# cd xcache-3.2.0 3.xcache是被編譯成php的一種組件,但在"xcache-3.2.0"目錄下沒有"configure"文件,利用php的編譯工具命令建立出來: xcache-3.2.0]# phpize //生成"configure"文件 4.編譯安裝xcache xcache-3.2.0]# ./configure --enable-xcache --with-php-config=/usr/local/php-5.6.31/bin/php-config xcache-3.2.0]# make -j 4 && make install 輸出結果的最後一行: Installing shared extensions: /usr/local/php-5.6.31/lib/php/extensions/no-debug-non-zts-20131226/ /usr/local/php-5.6.31/lib/php/extensions/no-debug-non-zts-20131226/就是存放xcache模塊的目錄 5.爲xcache提供配置文件 xcache-3.2.0]# cp xcache.ini /etc/php-5.6.31.d/ 6.編譯xcache的配置文件 在前幾行能夠找到,把xcache模塊的路徑補全: extension = /usr/local/php-5.6.31/lib/php/extensions/no-debug-non-zts-20131226/xcache.so 7.重啓php-fpm服務,檢驗加速效果 php-5.6.31.d]# service php-fpm restart php-5.6.31.d]# curl http://www.vayne36.com/yAdmin-3.5.4-all-languages/index.php //先令其有個緩存 php-5.6.31.d]# ab -c 10 -n 100 http://www.vayne36.com/phpMyAdmin-3.5.4-all-languages/index.php 輸出結果顯示: Requests per second: 552.84 [#/sec] (mean)
總結:
相比較有和沒有xcache這個組件,明顯的能夠看出"Requests per second"的值明顯的提升了;也就是加速的php的訪問
通常來講,對於LAMP架構,自行編譯安裝AMP會比直接利用yum倉庫安裝AMP來得更好,特別是在利用Xcache完成php加速方面;由於自行編譯安裝可以自行選擇須要的功能、模塊、組件等;雖然沒有沒有利用yum倉庫來得簡單容易,但自行編譯安裝AMP也不難,只能過程比較繁瑣,難度不大;