编译安装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编译安装之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-server
2.安装编译需要的环境
~]# yum groupinstall -y "Development Tools"
~]# yum groupinstall -y "Server Platform Development"
~]# yum install -y pcre-devel
~]# yum install -y libevent-devel
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 install
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 install
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 -v
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.创建用于启动服务和管理数据的用户和组:
groupadd -r -g 306 mysql
# 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 --add mysqld
# 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进程状态:
service php-fpm status
# 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行
DirectoryIndex index.html index.php
2.编辑虚拟主机配置文件:
php-5.6.31]# vim /etc/httpd-2.4.27/extra/httpd-vhosts.conf
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
Options None
AllowOverride None
Require all granted
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也不难,只能过程比较繁琐,难度不大;