这篇文章主要为大家展示了“如何编译php-fpm模块与apache2.4结合”,内容简而易懂,条理清晰,希望能够帮助大家解决疑惑,下面让小编带领大家一起研究并学习一下“如何编译php-fpm模块与apache2.4结合”这篇文章吧。
准备好3台虚拟机,配置好主机名和IP地址,关闭防火墙和selinux
nfs启动顺序:先启动rpc—>在启动nfs
nfs权限参数
rw:读写
ro:只读
sync:同步模式,内存中数据时时写入磁盘
async:不同步,把内存中数据定期写入磁盘中
no_root_squash:加上这个选项后,root用户就会对共享的目录拥有至高的权限控制,就像是对本机的目录操作一样。不安全,不建议使用
root_squash:把root通过网络访问时,换成nfsnobody用户,即限制了root权限
all_squash:不管使用NFS的用户是谁,他的身份都会被限定成为nfsnobody用户身份
anonuid/anongid:要和root_squash 以及 all_squash一同使用,用于指定使用NFS的用户限定后的uid和gid,前提是服务端和客户端/etc/passwd中都存在这个uid和gid
共享文件权限为:服务权限与文件系统权限的交集
安装、配置nfs服务
[root@nfs ~]# mkdir -p /data/{mydata,www} #为web,mysql创建共享目录
[root@nfs ~]# ls /data/
mydata www
[root@nfs ~]# groupadd -g 110 apache
[root@nfs ~]# useradd -u 110 -M -s /sbin/nologin apache
[root@nfs ~]# chmod 777 /data/www/
[root@nfs ~]# groupadd -g 111 msyql
[root@nfs ~]# useradd -u 111 -M -s /sbin/nologin mysql
[root@nfs ~]# chmod 777 /data/mydata/
[root@nfs ~]# yum groupinstall -y "NFS file server"
[root@nfs ~]# vi /etc/exports
/data/www 192.168.0.11(rw,root_squash)
/data/mydata 192.168.0.20(rw,no_root_squash)
[root@nfs ~]# service rpcbind restart
Stopping rpcbind: [ OK ]
Starting rpcbind: [ OK ]
[root@nfs ~]# service nfs start
Starting NFS quotas: [ OK ]
Starting NFS mountd: [ OK ]
Starting NFS daemon: [ OK ]
Starting RPC idmapd: [ OK ]
安装、配置mysql
[root@mysql ~]# mkdir -p /data/mydata
[root@mysql ~]# showmount -e 192.168.0.30
Export list for 192.168.0.30:
/data/mydata 192.168.0.20
/data/www 192.168.0.11
[root@mysql ~]# mount -t nfs 192.168.0.30:/data/mydata /data/mydata/
[root@mysql ~]# cd /data/mydata/
[root@mysql mydata]# ll
total 0
[root@mysql mydata]# touch aa
[root@mysql mydata]# ll
total 0
-rw-r--r-- 1 root root 0 Sep 29 22:23 aa
[root@mysql mydata]# cd ~
[root@mysql ~]# groupadd -g 111 msyql
[root@mysql ~]# useradd -u 111 -M -s /sbin/nologin mysql #创建mysql账户
[root@mysql ~]# chown -R mysql:mysql /data/mydata
[root@mysql ~]# tar -xf mariadb-5.5.36-linux-x86_64.tar.gz -C /usr/local/
[root@mysql ~]# cd /usr/local
[root@mysql local]# chown -R mysql:mysql mariadb-5.5.36-linux-x86_64/
[root@mysql local]# ln -sv mariadb-5.5.36-linux-x86_64/ mysql
[root@mysql mysql]# cd mysql
[root@mysql mysql]# scripts/mysql_install_db --datadir=/data/mydata/ --user=mysql
[root@mysql mysql]# mkdir /etc/mysql
[root@mysql mysql]# cp support-files/my-large.cnf /etc/mysql/my.cnf
[root@mysql mysql]# vi /etc/mysql/my.cnf #在mysqld下面添加下面几项
[mysqld]
...
datadir = /data/mydata
innodb_file_per_table =on
skip_name_resolve = on
[root@mysql mysql]# cp support-files/mysql.server /etc/rc.d/init.d/mysqld
[root@mysql mysql]# ln -sv /usr/local/mysql/include /usr/include/mysql
[root@mysql mysql]# echo'/usr/local/mysql/lib' > /etc/ld.so.conf.d/mysql.conf
[root@mysql mysql]# ldconfig
[root@mysql mysql]# chkconfig --add mysqld
[root@mysql mysql]# service mysqld start
[root@mysql mysql]# bin/mysql_secure_installation #数据库安全初始化,设置root密码、权限和删除匿名用户
[root@mysql mysql]# /usr/local/mysql/bin/mysql -uroot -p #验证能否登录
Enter password:
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 3
Server version: 5.5.36-MariaDB-log MariaDB Server
Copyright (c) 2000, 2014, Oracle, Monty Program Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MariaDB [(none)]> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema|
| mysql |
| performance_schema|
+--------------------+
3 rows in set (0.03 sec)
MariaDB [(none)]> grant all on *.* to test@"192.168.%.%" identified by 'chinoe-147';
##在nfs服务器上可以看到mysql元数据
[root@nfs ~]# cd /data/mydata/
[root@nfs mydata]# ls
aria_log.00000001 aria_log_control ibdata1 ib_logfile0 ib_logfile1 mysql mysql-bin.000001 mysql-bin.000002 mysql-bin.000003 mysql-bin.index mysql.pid performance_schema
安装、配置apache+php-fpm
apache依赖包 apr-util-1.5.3.tar.bz2 、apr-1.5.0.tar.bz2、pcre-devel
[root@httpd ~]# groupadd -g 110 apache
[root@httpd ~]# useradd -u 110 -M -s /sbin/nologin apache
[root@httpd ~]# yum install -y pcre-devel
[root@httpd ~]# tar -xf apr-1.5.0.tar.bz2
[root@httpd ~]# cd apr-1.5.0
[root@httpd apr-1.5.0]# ./configure --prefix=/usr/local/apr
[root@httpd apr-1.5.0]# make && make install
[root@httpd apr-1.5.0]# cd ..
[root@httpd ~]# tar -xf apr-util-1.5.3.tar.bz2
[root@httpd ~]# cd apr-util-1.5.3
[root@httpd apr-util-1.5.3]#./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr
[root@httpd apr-util-1.5.3]# make && makeinstall
[root@httpd apr-util-1.5.3]# cd ..
[root@httpd ~]# tar -xvf httpd-2.4.10.tar.bz2
[root@httpd ~]# cd httpd-2.4.10
[root@httpd httpd-2.4.10]# ./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
[root@httpd httpd-2.4.10]# make && make install
###然后需要自己编写httpd服务启动脚本,我这里是直接修改rpm安装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
[root@httpd ~]# chmod +x /etc/init.d/httpd
[root@httpd ~]# chkconfig --add httpd
[root@httpd ~]# vi /etc/profile.d/httpd.sh
export PATH=/usr/local/apache/bin:$PATH
[root@httpd ~]# ./etc/profile.d/httpd.sh #重读一下配置文件
编译安装apache在服务启动之前必须指定pid文件路径
在/etc/httpd/httpd.conf的全局配置中添加pid文件
ServerRoot "/usr/local/apache"
PidFile "/var/run/httpd.pid" 必须与服务启动脚本httpd中的pidfile路径一样
[root@httpd ~]# service httpd start
[root@httpd ~]# curl -I 127.0.0.1
HTTP/1.1 200 OK
Date: Tue, 29 Sep 2015 12:57:18 GMT
Server: Apache/2.4.10 (Unix)
Last-Modified: Mon, 11 Jun 2007 18:53:14 GMT
ETag: "2d-432a5e4a73a80"
Accept-Ranges: bytes
Content-Length: 45
Content-Type: text/html
#apache已经安装完毕,测试正常
php-fpm以独立模块与apache结合
依赖包:bzip2-devel libmcrypt-devel libxml2-devel php-mysql
mysql与php不在同一台物理机时,还需要安装mysql-devel包和mysql-libs包
[root@httpd ~]# mkdir /etc/php5{,.d}
[root@httpd ~]# mkdir /usr/local/php5
[root@httpd ~]# yum -y groupinstall "Desktop Platform Development"
[root@httpd ~]# yum -y install bzip2-devel libmcrypt-devel libxml2-devel php-mysql
[root@httpd ~]# yum install -y mysql-devel mysql-libs
[root@httpd ~]# tar -xf php-5.5.29.tar.xz
[root@httpd ~]# cd php-5.5.29
[root@httpd php-5.5.29]# ./configure --prefix=/usr/local/php5/ --with-mysql --with-openssl --with-mysqli --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/php5/ --with-config-file-scan-dir=/etc/php5.d --with-bz2
[root@httpd php-5.5.29]# make -j 4 && make install
[root@httpd php-5.5.29]# cp php.ini-production /etc/php5/php.ini
[root@httpd php-5.5.29]# cp sapi/fpm/init.d.php-fpm /etc/rc.d/init.d/php-fpm
[root@httpd php-5.5.29]# chmod +x /etc/rc.d/init.d/php-fpm
[root@httpd php-5.5.29]# chkconfig --add php-fpm
[root@httpd php-5.5.29]# cp /usr/local/php5/etc/php-fpm.conf.default /usr/local/php5/etc/php-fpm.conf
###修改php-fpm参数
[root@httpd php-5.5.29]# vim /usr/local/php5/etc/php-fpm.conf
user = apache
group = apache
listen = 0.0.0.0:9000
在pm = dynamic模块下面修改参数
pm.max_children = 50
pm.start_servers = 5
pm.min_spare_servers = 2
pm.max_spare_servers = 8
pid = /usr/local/php5/var/run/php-fpm.pid
[root@httpd php-5.5.29]# service php-fpm start
[root@httpd php-5.5.29]# ss -tanlp |grep 9000
LISTEN 0 128 127.0.0.1:9000 *:* users:(("php-fpm",114598,7),("php-fpm",114599,0),("php-fpm",114600,0),("php-fpm",114601,0),("php-fpm",114602,0),("php-fpm",114603,0))
[root@httpd php-5.5.29]# vi /etc/httpd/httpd.conf
User apache #修改进程用户
Group apache
##注释掉中心主机,使用虚拟主机
#DocumentRoot "/usr/local/apache/htdocs"
#<Directory "/usr/local/apache/htdocs">
# Options Indexes FollowSymLinks
# AllowOverride None
# Require all granted
#</Directory>
在相关的LoadModule下添加
LoadModule proxy_module modules/mod_proxy.so
LoadModule proxy_fcgi_module modules/mod_proxy_fcgi.so
在AddType下添加
AddType application/x-httpd-php .php
找到DirectoryIndex index.html 修改为:
DirectoryIndex index.php index.html
#结尾加上虚拟主机
<virtualhost *:80>
servername www.test.com
documentroot /data/www
ProxyRequests Off
ProxyPassMatch ^/(.*\.php)$ fcgi://127.0.0.1:9000/data/www/$1
<directory "/data/www">
options none
allowoverride none
<requireall>
require all granted
</requireall>
</directory>
</virtualhost>
[root@httpd ~]# mkdir -p /data/www
[root@httpd ~]# mount -t nfs 192.168.0.30:/data/www /data/www/
[root@httpd ~]# vi index.php
<?php
phpinfo()
?>
[root@httpd ~]# vi index.php #测试数据库
<?php
$link = mysql_connect('192.l68.0.20','test','chinoe-147');
if ($link)
echo "Success...";
else
echo "Failure...";
mysql_close();
?>
再测试数据库是否能链接上
已经success
以上是“如何编译php-fpm模块与apache2.4结合”这篇文章的所有内容,感谢各位的阅读!相信大家都有了一定的了解,希望分享的内容对大家有所帮助,如果还想学习更多知识,欢迎关注编程网行业资讯频道!