您好,登錄后才能下訂單哦!
LAMP的搭建:
準(zhǔn)備前提:
虛擬機:Centos7 172.18.250.77 安裝httpd,通過Fcgi模塊來跟php互動,只處理靜態(tài)網(wǎng)頁。
虛擬機:Centos7 172.18.250.78 安裝php-fpm程序,php-5.3.3的版本已經(jīng)包含了php-fpm,不需要在打補丁,但CentOS6上官方源沒有php-fpm包,所以用CentOS 7 實驗。
虛擬機:CentOS6 172.18.250.76 安裝mysql,實現(xiàn)php跟mysql的互動。
httpd提供兩個虛擬主機,分別安裝wordpress博客及discuz論壇。
一、yum安裝httpd
[root@localhost local]# yum -y install httpd
1、編輯主配置文件,注釋DocumentRoot
[root@localhost httpd]# vim conf/httpd.conf #DocumentRoot "/var/www/html"
2、創(chuàng)建虛擬主機文件
[root@localhost httpd]# cd /etc/httpd/conf.d/ [root@localhost conf.d]# vim vhost.conf <VirtualHost *:80> ServerName www.a.com DocumentRoot "/www/blog" <Directory "/www/blog"> Options None Allowoverride None Require all granted <Directory> ProxyRequests Off ProxyPassMatch ^/(.*\.php)$ fcgi://172.18.250.78:9000/www/blog/$1 </VirtualHost> <VirtualHost *:80> ServerName www.b.net DocumentRoot "/www/php" <Directory "/www/php"> Options None Allowoverride None Require all granted <Directory> ProxyRequests Off ProxyPassMatch ^/(.*\.php)$ fcgi://172.18.250.78:9000/www/php/$1 </VirtualHost>
3、創(chuàng)建虛擬主機需要的目錄
[root@localhost conf.d]# mkdir -p /www/blog [root@localhost conf.d]# mkdir -p /www/php
4、啟動httpd服務(wù),查看監(jiān)聽端口
[root@localhost conf.d]# systemctl start httpd.service [root@localhost conf.d]# ss -tan LISTEN 0 128 :::80 :::*
5、在虛擬主機目錄創(chuàng)建測試頁,看httpd是否正常
[root@localhost conf.d]# echo "www.a.com" >/www/blog/index.html [root@localhost conf.d]# echo "www.b.net" >/www/php/index.html
OK,虛擬主機正常
二、yum安裝PHP
[root@localhost ~]# yum -y install php-fpm
PHP-FPM是一個PHPFastCGI管理器,是只用于PHP的,httpd通過Fcgi模塊來把php的文件傳送給php-fpm進(jìn)行處理
1、編輯php-fpm文件
[root@localhost ~]# vim /etc/php-fpm.d/www.conf listen = 172.18.250.78:9000 //本機IP listen.allowed_clients = 172.18.250.77 //httpd端IP
2、重啟php-fpm程序,查看監(jiān)聽端口
[root@localhost ~]# systemctl start php-fpm.service [root@localhost ~]# ss -tan LISTEN 0 128 172.18.250.78:9000 *:*
3、在php端上創(chuàng)建和httpd上一樣的目錄
[root@localhost ~]# mkdir -p /www/blog [root@localhost ~]# mkdir -p /www/php
4、創(chuàng)建測試頁,驗證看httpd能不能轉(zhuǎn)發(fā)過來
[root@localhost ~]# mkdir -p /www/blog [root@localhost ~]# mkdir -p /www/php [root@localhost ~]# vim /www/blog/index.php [root@localhost ~]# vim /www/php/index.php <?php phpinfo(); ?>
OK,httpd能讀到.php結(jié)尾的文件并轉(zhuǎn)發(fā)給php處理
三、yum安裝mysql
[root@localhost ~]# yum -y install mysql-server
1、啟動mysql,并對數(shù)據(jù)庫就行安全加固
[root@localhost ~]# service mysqld start [root@localhost ~]# mysql_secure_installation Enter current password for root (enter for none): //默認(rèn)數(shù)據(jù)庫密碼為空 Set root password? [Y/n] y //設(shè)置新密碼 Remove anonymous users? [Y/n] y //移除匿名用戶 Disallow root login remotely? [Y/n] n //是否禁止用戶遠(yuǎn)程登錄 Remove test database and access to it? [Y/n] y //是否移除test數(shù)據(jù)庫 Reload privilege tables now? [Y/n] y //是否重啟加載權(quán)限列表
2、創(chuàng)建用戶和數(shù)據(jù)庫,并授權(quán)php端能遠(yuǎn)程登錄
mysql> grant all on *.* to 'admin'@'172.18.250.78' identified by "admin"; Query OK, 0 rows affected (0.00 sec) mysql> flush privileges; Query OK, 0 rows affected (0.00 sec) mysql> create database mytest; Query OK, 1 row affected (0.00 sec) mysql> create database bbs; Query OK, 1 row affected (0.01 sec)
3、測試php能不能登錄數(shù)據(jù)庫
[root@localhost ~]# yum -y install php-mysql //安裝mysql驅(qū)動 [root@localhost ~]# vim /www/blog/index.php [root@localhost ~]# vim /www/php/index.php <?php $conn = mysql_connect ('172.18.250.76','admin','admin'); if( $conn ) echo "SUCCESS"; else echo "Failure"; ?> [root@localhost ~]# systemctl restart php-fpm.service
OK,測試正常,可以安裝wordpress和Discuz論壇
1、分別在php服務(wù)器上和httpd上解壓wordpress包
[root@localhost blog]# unzip wordpress-4.3.1-zh_CN.zip [root@localhost blog]# unzip wordpress-4.3.1-zh_CN.zip [root@localhost blog]# cd wordpress //只需在php上改動 [root@localhost wordpress]# cp wp-config-sample.php wp-config.php /** WordPress數(shù)據(jù)庫的名稱 */ define('DB_NAME', 'mytest'); /** MySQL數(shù)據(jù)庫用戶名 */ define('DB_USER', 'admin'); /** MySQL數(shù)據(jù)庫密碼 */ define('DB_PASSWORD', 'admin'); /** MySQL主機 */ define('DB_HOST', '172.18.250.76');
出現(xiàn)這個頁面的話只需要修改httpd主配置文件,讓httpd能識別php的文件代碼
[root@localhost blog]# vim /etc/httpd/conf/httpd.conf AddType application/x-httpd-php .php //添加下面的語句就行 AddType aaplication/x-httpd-source .phps <IfModule dir_module> DirectoryIndex index.php index.html </IfModule>
重啟httpd服務(wù),再次測試下
登錄wordPress博客:
OK,WordPress博客能正常加載
1、分別在php服務(wù)器上和httpd上解壓Discuz包
[root@localhost php]# unzip Discuz_X3.2_SC_UTF8.zip [root@localhost php]# unzip Discuz_X3.2_SC_UTF8.zip [root@localhost php]# cd upload //在php服務(wù)器上
修改目錄的權(quán)限即可:
[root@localhost upload]# chown -R apache config/ [root@localhost upload]# chown -R apache uc_client/ //httpd和php上都需要改 [root@localhost upload]# chown -R apache data [root@localhost upload]# chown -R apache template/ [root@localhost upload]# chown -R apache uc_server/
根據(jù)步驟一步步執(zhí)行就行:
注冊完后登錄論壇:
。。。。。發(fā)現(xiàn)論壇只有文字,這是因為php安裝了Discuz后修改了程序的文件導(dǎo)致的,這時httpd上的靜態(tài)程序文件跟php上的動態(tài)程序文件不一致,所以只需要同步下就行。
[root@localhost php]# scp -r upload/* root@172.18.250.77:/www/php/upload/
再次刷新:OK
如果想要實現(xiàn)自動同步的話,可以使用initory+rsync、sersync等工具。
四:安裝Xcahe對php進(jìn)行加速
[root@localhost src]# tar -xf xcache-3.2.0.tar.bz2 //只需在PHP服務(wù)器上 [root@localhost src]# ls xcache-3.2.0 xcache-3.2.0.tar.bz2 [root@localhost src]# cd xcache-3.2.0 [root@localhost xcache-3.2.0]# yum -y install php-devel //安裝php開發(fā)工具包 [root@localhost xcache-3.2.0]# phpize //檢查php的版本及api接口 Configuring for: PHP Api Version: 20100412 Zend Module Api No: 20100525 Zend Extension Api No: 220100525 [root@localhost xcache-3.2.0]# ./configure --enable-xcache --with-php-config=/usr/bin/php-config [root@localhost xcache-3.2.0]# make && make install [root@localhost xcache-3.2.0]# cp xcache.ini /etc/php.d/
[root@localhost upload]# ab -n100 -c10 http://172.18.250.77/wordpress/index.php Benchmarking 172.18.250.77 (be patient).....done Server Software: Apache/2.4.6 Server Hostname: 172.18.250.77 Server Port: 80 Document Path: /wordpress/index.php Document Length: 0 bytes Concurrency Level: 10 Time taken for tests: 3.908 seconds Complete requests: 100 Failed requests: 0 Write errors: 0 Non-2xx responses: 100 Total transferred: 34900 bytes HTML transferred: 0 bytes Requests per second: 25.59 [#/sec] (mean) //ab壓力測試每秒請求個數(shù) Time per request: 390.849 [ms] (mean) Time per request: 39.085 [ms] (mean, across all concurrent requests) Transfer rate: 8.72 [Kbytes/sec] received Connection Times (ms) min mean[+/-sd] median max Connect: 0 0 0.3 0 1 Processing: 104 369 95.7 368 589 Waiting: 104 367 94.8 367 589 Total: 105 369 95.7 368 589 Percentage of the requests served within a certain time (ms) 50% 368 66% 410 75% 443 80% 455 90% 502 95% 536 98% 589 99% 589 100% 589 (longest request)
重啟php-fpm服務(wù),看xcache有沒有加載:
[root@localhost blog]# php -m [Zend Modules] //表明xcache已經(jīng)開啟 XCache XCache Cacher
再一次做ab壓力測試:
[root@localhost upload]# ab -n100 -c10 http://172.18.250.77/wordpress/index.php Benchmarking 172.18.250.77 (be patient).....done Server Software: Apache/2.4.6 Server Hostname: 172.18.250.77 Server Port: 80 Document Path: /wordpress/index.php Document Length: 0 bytes Concurrency Level: 10 Time taken for tests: 1.489 seconds Complete requests: 100 Failed requests: 0 Write errors: 0 Non-2xx responses: 100 Total transferred: 34900 bytes HTML transferred: 0 bytes Requests per second: 67.18 [#/sec] (mean) //加載xcache后有了提升 Time per request: 148.853 [ms] (mean) Time per request: 14.885 [ms] (mean, across all concurrent requests) Transfer rate: 22.90 [Kbytes/sec] received Connection Times (ms) min mean[+/-sd] median max Connect: 0 0 0.2 0 1 Processing: 38 141 31.0 139 240 Waiting: 37 141 31.0 138 240 Total: 38 141 31.0 139 240 Percentage of the requests served within a certain time (ms) 50% 139 66% 152 75% 160 80% 168 90% 179 95% 194 98% 216 99% 240 100% 240 (longest request)
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。