您好,登錄后才能下訂單哦!
這篇文章主要為大家展示了“如何編譯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結合”這篇文章的所有內容,感謝各位的閱讀!相信大家都有了一定的了解,希望分享的內容對大家有所幫助,如果還想學習更多知識,歡迎關注億速云行業資訊頻道!
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。