您好,登錄后才能下訂單哦!
實驗拓撲圖:
考慮到復雜的應用環境,我們將apache/php/mysql三種服務獨立配置不同主機
我們知道apache與php有三種工作模式:
1、CGI
2、Modules
3、FastCGI
第一種現在用得很少了,性能差;對于動態頁面全部由apache進程啟用php解釋器,然后再釋放
第二種需要到本地磁盤加載Modules模塊,性能比第一種好,但還是會有很多消耗資源
第三種php是一個獨立應用,通過網絡套接字接口,接收apache進程傳過來的請求,所有php進程都由php自身管理
在php5.4以前,如果php需要連接mysql需要mysql頭文件等,但在php5.4以后就不需要了,直接使用"--with-mysql=mysqlnd --with-pdo-mysql=mysqlnd --with-mysqli=mysqlnd"
由于apache并不處理動態頁面,所以前端用戶請求的php頁面需要轉發到php服務器上,這里就需要對apache做反向代理設置
當然了,我們在這里最好啟用虛擬主機功能,這樣方便管理。
編譯安裝Apache2.4.4
準備軟件包:
apr-1.4.6.tar.gz
apr-util-1.4.1.tar.gz
httpd-2.4.4.tar.bz2
pcre-8.32.tar.gz
[root@station01 ~]# tar xf apr-1.4.6.tar.gz
[root@station01 ~]# cd apr-1.4.6
[root@station01 apr-1.4.6]# ./configure --prefix=/usr/local/apr
[root@station01 apr-1.4.6]# make &&make install
[root@station01 apr-1.4.6]# cd ..
[root@station01 ~]# tar xf apr-util-1.4.1.tar.gz
[root@station01 ~]# cd apr-util-1.4.1
[root@station01 apr-util-1.4.1]# ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr
[root@station01 apr-util-1.4.1]# make &&make install
[root@station01 apr-util-1.4.1]# cd
[root@station01 ~]# tar xf httpd-2.4.4.tar.bz2
[root@station01 ~]# cd httpd-2.4.4
[root@station01 httpd-2.4.4]# ./configure --prefix=/usr/local/apache --sysconfdir=/etc/httpd --enable-so --enable-ssl --enable-cgi --enable-rewrite --with-zlib --with-pcre=/usr/local/pcre --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util --enable-modules=most --enable-mpms-shared=all --with-mpm=event
[root@station01 httpd-2.4.4]# make &&make install
[root@station01 httpd-2.4.4]# cp build/rpm/httpd.init /etc/init.d/httpd
[root@station01 httpd-2.4.4]# vim /etc/init.d/httpd
httpd=${HTTPD-/usr/local/apache/bin/httpd}
pidfile=${PIDFILE-/usr/local/apache/logs/${prog}.pid}
lockfile=${LOCKFILE-/var/lock/subsys/${prog}}
RETVAL=0
CONFFILE=/etc/httpd/httpd.conf
[root@station01 httpd-2.4.4]# chkconfig --add httpd
[root@station01 httpd-2.4.4]# chkconfig httpd on
[root@station01 httpd-2.4.4]# service httpd start
編譯安裝PHP5.4
準備軟件包:
libmcrypt-2.5.7-5.el5.i386.rpm
libmcrypt-devel-2.5.7-5.el5.i386.rpm
php-5.4.13.tar.bz2
[root@station02 ~]# rpm -ivh *.rpm
[root@station02 ~]# tar xf php-5.4.13.tar.bz2
[root@station02 ~]# cd php-5.4.13
[root@station02 php-5.4.13]# ./configure --prefix=/usr/local/php --with-openssl --enable-mbstring --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir=/usr --enable-xml --enable-sockets --with-mcrypt --with-config-file-path=/etc --with-config-file-scan-dir=/etc/php.d --with-bz2 --enable-maintainer-zts --with-mysql=mysqlnd --with-pdo-mysql=mysqlnd --with-mysqli=mysqlnd --enable-fpm
[root@station02 php-5.4.13]# make &&make install
[root@station02 php-5.4.13]# cp php.ini-production /etc/php.ini
[root@station02 php-5.4.13]# cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
[root@station02 php-5.4.13]# chmod +x /etc/init.d/php-fpm
[root@station02 php-5.4.13]# chkconfig --add php-fpm
[root@station02 php-5.4.13]# chkconfig php-fpm on
[root@station02 php-5.4.13]# cd /usr/local/php/
[root@station02 php]# cp etc/php-fpm.conf.default etc/php-fpm.conf
[root@station02 php]# vim etc/php-fpm.conf
配置fpm的相關選項為你所需要的值,并啟用pid文件:
pm.max_children = 50
pm.start_servers = 5
pm.min_spare_servers = 2
pm.max_spare_servers = 8
pid = /usr/local/php/var/run/php-fpm.pid
[root@station02 php]# service php-fpm start
檢查php-fpm是否正常
[root@station02 php]# netstat -tunlp |grep 9000
[root@station02 php]# ps -ef |grep php-fpm
二進制配置MySQL
[root@station03 ~]# tar xf mysql-5.5.28-linux2.6-i686.tar.gz -C /usr/local/
[root@station03 ~]# cd /usr/local/
[root@station03 local]# groupadd -g 3306 mysql
[root@station03 local]# useradd -g mysql -u 3306 mysql -s /sbin/nologin -M
[root@station03 local]# ln -s mysql-5.5.28-linux2.6-i686/ mysql
[root@station03 local]# cd mysql
[root@station03 mysql]# chown -R mysql.root .
[root@station03 mysql]# chown -R mysql.mysql data/
[root@station03 mysql]# scripts/mysql_install_db --datadir=/usr/local/mysql/data/ --user=mysql
[root@station03 mysql]# cp support-files/mysql.server /etc/init.d/mysqld
[root@station03 mysql]# chmod +x /etc/init.d/mysqld
[root@station03 mysql]# chkconfig --add mysqld
[root@station03 mysql]# chkconfig mysqld on
[root@station03 mysql]# cp support-files/my-large.cnf /etc/my.cnf
[root@station03 mysql]# vim /etc/my.cnf
#如果data目錄更改,則需要在mysqld段中注明
[root@station03 mysql]# service mysqld start
[root@station03 mysql]# vim /etc/profile.d/mysqld.sh
export PATH=$PATH:/usr/local/mysql/bin
[root@station03 mysql]# . /etc/profile.d/mysqld.sh
[root@station03 ~]# mysql
mysql> update user set password=password('asdasd') where user='root';
mysql> flush privileges;
Apache與PHP整合工作
[root@station01 ~]# vim /etc/httpd/httpd.conf
#DocumentRoot "/usr/local/apache/htdocs"
DirectoryIndex index.html index.php
AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps
Include /etc/httpd/extra/httpd-vhosts.conf
LoadModule proxy_fcgi_module modules/mod_proxy_fcgi.so
LoadModule proxy_module modules/mod_proxy.so
[root@station01 ~]# vim /etc/httpd/extra/httpd-vhosts.conf
<VirtualHost *:80>
DocumentRoot "/web/html"
ServerName "www.neo.com"
ErrorLog "logs/www.neo.com_error_log"
CustomLog "logs/www.neo.com_access_log" combined
<Directory "/web/html">
Options None
Require all granted
</Directory>
ProxyRequests Off
ProxyPassMatch ^/(.*)\.php$ fcgi://192.168.100.12:9000/web/html/$1.php
</VirtualHost>
[root@station01 ~]# mkdir /web/html -p
[root@station02 ~]# mkdir /web/html -p
[root@station01 ~]# vim /web/html/index.php
<?php
phpinfo();
?>
瀏覽器訪問http://192.168.100.11/index.php
驗證PHP是否能連上MySQL
[root@station02 ~]# vim /web/html/test.php
<?php
$link=mysql_connect('192.168.100.13','root','asdasd');
if(!$link)
echo "<h2>connect failed !!!!</h2> ";
else
echo "<h2>success ....</h2>";
mysql_close();
?>
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。