本次实验目的:实现httpd与php通过fpm结合。 服务器相关信息: 1
2
3
4
5
| IP:172.16.113.16
2.6.32-504.el6.x86_64
[iyunv@web~]# cat redhat-re
[iyunv@web~]# cat /etc/redhat-release
CentOSrelease 6.6 (Final)
|
编译安装httpd2.2 需要的源码包: httpd-2.4.16.tar.bz2 apr-1.5.0.tar.bz2 apr-util-1.5.3.tar.bz2
准备开发环境:
解决依赖关系:安装pcre-devel包
展开并安装apr [iyunv@web~]# tar xf apr-1.5.0.tar.bz2 [iyunv@web~]# cd apr-1.5.0
展开并安装apr-util [iyunv@web~]# tar xf apr-util-1.5.3.tar.bz2 [iyunv@web~]# cd apr-util-1.5.3
展开并安装httpd [iyunv@web~]# tar xf httpd-2.4.16.tar.bz2 [ root@webhttpd-2.4.16]# ./configure --prefix=/usr/local/apache --sysconfdir=/etc/httpd24--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 #--prefix=/usr/local/apache //指明安装目录 #--sysconfdir=/etc/httpd24 //指定配置文件的安装路径,此处为了避免与rpm包所装的httpd冲突,将路径名取名为httpd24 #--enable-so //支持httpd的模块化机制 #--enable-ssl //启用支持ssl功能,实现https #--enable-cgi //支持cgi协议 #--enable-rewrite //支持url重写 #--with-zlib //支持传输压缩 #--with-pcre //支持perl语言的正则表达式 #--with-apr=/usr/local/apr //指明编译升级的apr的路径 #--with-apr-util=/usr/local/apr-util//指明编译升级的apr-util路径 #--enable-modules=most //指明启动大多数的模块 #--enable-mpms-shared=all //将所有mpm模块都编译进httpd(httpd2.4版本的新特性) #--with-mpm=event //默认使用event的MPM工作模型 PidFile"/var/run/httpd24/httpd.pid" //添加运行时pid文件的位置
为httpd24提供服务管理脚本:放置于/etc/rc.d/init.d/httpd24,并赋予可执行权限
#!/bin/bash #chkconfig: - 85 15 #description: The Apache HTTP Server Management script. ./etc/rc.d/init.d/functions
apachectl=/usr/local/apache/bin/apachectl httpd=/usr/local/apache/bin/httpd prog=httpd pidfile=/var/run/httpd24/httpd.pid lockfile=/var/lock/subsys/httpd24 RETVAL=0 STOP_TIMEOUT=${STOP_TIMEOUT-10}
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 ${STOP_TIMEOUT} $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=6 echo $"not reloading due to configuration syntaxerror" failure $"not reloading $httpd due to configurationsyntax error" else # Force LSB behaviour from killproc LSB=1 killproc -p ${pidfile} $httpd -HUP RETVAL=$? if [ $RETVAL -eq 7 ]; then failure $"httpd shutdown" fi fi echo } case"$1" in start) start ;; stop) stop ;; status) status -p ${pidfile} $httpd RETVAL=$? ;; restart) stop start ;; condrestart|try-restart) if status -p ${pidfile} $httpd >&/dev/null; then stop start fi ;; force-reload|reload) reload ;; graceful|help|configtest|fullstatus) $apachectl $@ RETVAL=$? ;; *) echo $"Usage: $prog{start|stop|restart|condrestart|try-restart|force-reload|reload|status|fullstatus|graceful|help|configtest}" RETVAL=2 esac
exit$RETVAL exportPATH=/usr/local/apache/bin:$PATH
编译安装mariadb 需要的源码包: mariadb-5.5.43-linux-x86_64.tar.gz (二进制包)
安装mariadb,可通过展开包中的“INSTALL-BINARY”查看安装步骤: [iyunv@web~]# tar -xf mariadb-5.5.43-linux-x86_64.tar.gz [iyunv@web~]# mv mariadb-5.5.43-linux-x86_64 /usr/local/mysql //将展开目录移动至/usr/local下,并重命名为"mysql" [iyunv@web~]# cd /usr/local/mysql [iyunv@webmysql]# groupadd -r -g 306 mysql //创建系统用户组:mysql [iyunv@webmysql]# useradd -r -g 306 -u 306 mysql //创建系统用户:mysql [iyunv@webmysql]# chown -R mysql.mysql . //将mariadb的展开目录改为属主属组都是mysql [iyunv@webmysql]# mkdir -pv /mydata/data //创建数据库存放目录,此目录最好为xfs文件系统 mkdir:created directory `/mydata' mkdir:created directory `/mydata/data' [iyunv@webmysql]# scripts/mysql_install_db --user=mysql--datadir=/mydata/data //运行程序自带脚本安装mariadb [iyunv@webmysql]# chown -R root . //将mariadb的展开目录及其子目录属主改为root
将mariadb自带的配置文件模板拷贝至/etc下命名为my.cnf作为mariadb的配置文件 [iyunv@webmysql]# scp support-files/my-large.cnf /etc/my.cnf [iyunv@webmysql]# vim /etc/my.cnf //配置下面几项参数,入没有需手动添加 thread_concurrency= 8 //此处改为服务器cpu核心数的2倍 //在[mysqld]配置池中添加下面三项参数: datadir =/mydata/data innodb_file_per_table= yes skip_name_resolve= yes
为mariadb提供服务管理脚本,mariadb自带有服务管理脚本,拷贝至/etc/rc.d/init.d/下即可 [iyunv@webmysql]# cp support-files/mysql.server /etc/rc.d/init.d/mysqld
启动mariadb,并运行mariadb的安全初始化脚本,完成初始化配置,为root添加密码等操作: [iyunv@webmysql]# service mysqld start [iyunv@webmysql]# bin/mysql_secure_installation
将mariadb添加至开机自动启动 [iyunv@webmysql]# chkconfig --add mysqld [iyunv@webmysql]# chkconfig mysqld on
将mariadb目录添加至环境变量 [iyunv@webmysql]# vim /etc/profile.d/mariadb.sh exportPATH=/usr/local/mysql/bin:$PATH
编译安装php
需要的源码包:php-5.6.13.tar.bz2 1、解决依赖关系:(事先配置好yum源)
2、安装php [iyunv@web~]# tar xf php-5.6.13.tar.bz2 [iyunv@php_mariadb ~]# cd php-5.6.13 [ root@webphp-5.6.13]# ./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
// --enable-fpm 此项参数最为关键。是表明让php运行为单独的服务
3、提供php的配置文件:php源码包中自带配置文件模板,由于刚才编译安装时指定了php启动扫描配置文件的路径为/etc/php.d 因此:
4、位php提供服务管理脚本:php源码包中自带
5、为fpm提供配置文件 [ root@webphp-5.6.13]# cp /usr/local/php/etc/php-fpm.conf.default/usr/local/php/etc/php-fpm.conf pid =run/php-fpm.pid pm.max_children= 50 //服务启动的最大进程数 pm.start_servers= 10 //开启服务是启动的进程数 pm.min_spare_servers= 5 //最小空闲进程数 pm.max_spare_servers= 10 //最大空闲进程数
6、修改httpd配置文件 启用如下两个模块: LoadModuleproxy_module modules/mod_proxy.so LoadModuleproxy_fcgi_module modules/mod_proxy_fcgi.so //在Apache httpd 2.4以后已经专门有一个模块针对FastCGI的实现,此模块为mod_proxy_fcgi.so,它其实是作为mod_proxy.so模块的扩充,因此,这两个模块都要加载 添加如下两项参数,在Directory中添加;若想使此项对虚拟主机生效,需添加至虚拟主机内部 ProxyRequestsOff ProxyPassMatch^/(.*\.php)$ fcgi://127.0.0.1:9000/PATH/TO/DOCUMENT_ROOT/$1 修改 DirectoryIndex index.php index.html 添加: AddType application/x-httpd-php .php AddType application/x-httpd-php-source .phps
7、重启httpd24,编辑php测试
<?php $conn=mysql_connect('127.0.0.1','root','root'); if ($conn) echo "OK"; else "Failure"; phpinfo(); ?>
8、在浏览器输入url进行测试: 至此,php的fpm工作机制已搭建完成
|