CentOS 7, lamp (php-fpm)
阿新 • • 發佈:2018-04-16
fpmCentOS 7, lamp (php-fpm);
要求:(1) 三者分離於三臺主機;
(2) 一個虛擬主機用於提供phpMyAdmin;另一個虛擬主機用於提供wordpress;
(3) xcache
要求:(1) 三者分離於三臺主機;
(2) 一個虛擬主機用於提供phpMyAdmin;另一個虛擬主機用於提供wordpress;
(3) xcache
實驗環境:
主機 | 系統 | ip地址 | 部署服務 |
a | CentOS 7 | 192.168.2.110 | apache2.4 |
b | CentOS 7 | 192.168.2.111 | mariadb |
c | CentOS 7 | 192.168.2.112 | php-fpm |
一、主機a上部署apache
(1)在主機1上安裝httpd服務
[root@localhost ~]# yum install httpd -y
(2)檢查fcgi模塊是否加載
[root@localhost ~]# httpd -M | grep fcgi proxy_fcgi_module (shared)
(3)創建配置文件
[root@localhost ~]# vim /etc/httpd/conf.d/fcgi.conf DirectoryIndex index.php ProxyRequests off
(4)創建虛擬主機配置文件
[root@localhost ~]# vim /etc/httpd/conf.d/vhosts.conf <VirtualHost 192.168.2.110:80> DocumentRoot /www/htdocs/web1/pma ServerName pma.mylinuxops.com ProxyPassMatch ^/(.*\.php)$ fcgi://192.168.2.112:9000/www/htdocs/web1/pma/$1 <Directory /www/htdocs/web1/pma> Options none AllowOverRide none Require all granted </Directory> </VirtualHost> <VirtualHost 192.168.2.110:80> DocumentRoot /www/htdocs/web2/wordpress ServerName wp.mylinuxops.com ProxyPassMatch ^/(.*\.php)$ fcgi://192.168.2.112:9000/www/htdocs/web2/wordpress/$1 <Directory /www/htdocs/web2/wordpress> Options none AllowOverRide none Require all granted </Directory> </VirtualHost>
(5)啟動httpd服務
[root@localhost ~]# systemctl start httpd
二、在主機b上部署mariadb
(1)安裝mariadb-server
[root@localhost ~]# yum install -y mariadb-server
(2)啟動mariadb
[root@localhost ~]# systemctl start mariadb
(3)對mariadb執行安全環境部署
[root@localhost ~]# mysql_secure_installation NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB SERVERS IN PRODUCTION USE! PLEASE READ EACH STEP CAREFULLY! In order to log into MariaDB to secure it, we'll need the current password for the root user. If you've just installed MariaDB, and you haven't set the root password yet, the password will be blank, so you should just press enter here. Enter current password for root (enter for none): OK, successfully used password, moving on... Setting the root password ensures that nobody can log into the MariaDB root user without the proper authorisation. Set root password? [Y/n] y New password: Re-enter new password: Password updated successfully! Reloading privilege tables.. ... Success! By default, a MariaDB installation has an anonymous user, allowing anyone to log into MariaDB without having to have a user account created for them. This is intended only for testing, and to make the installation go a bit smoother. You should remove them before moving into a production environment. Remove anonymous users? [Y/n] y ... Success! Normally, root should only be allowed to connect from 'localhost'. This ensures that someone cannot guess at the root password from the network. Disallow root login remotely? [Y/n] n ... skipping. By default, MariaDB comes with a database named 'test' that anyone can access. This is also intended only for testing, and should be removed before moving into a production environment. Remove test database and access to it? [Y/n] n ... skipping. Reloading the privilege tables will ensure that all changes made so far will take effect immediately. Reload privilege tables now? [Y/n] y ... Success! Cleaning up... All done! If you've completed all of the above steps, your MariaDB installation should now be secure. Thanks for using MariaDB!
(4)創建wordpress及pma所需的用戶及數據庫
[root@localhost ~]# mysql -uroot -proot Welcome to the MariaDB monitor. Commands end with ; or \g. Your MariaDB connection id is 8 Server version: 5.5.56-MariaDB MariaDB Server Copyright (c) 2000, 2017, Oracle, MariaDB Corporation Ab and others. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. MariaDB [(none)]> CREATE DATABASE wpdb; Query OK, 1 row affected (0.00 sec) MariaDB [(none)]> USE wpdb; Database changed MariaDB [wpdb]> GRANT ALL ON wpdb to 'wpuser'@'192.168.2.112' IDENTIFIED BY 'wpuser'; Query OK, 0 rows affected (0.00 sec)
三、在主機c上部署php-fpm
(1)安裝php-fpm php-mysql php-mbstring
[root@localhost ~]# yum install php-fpm php-mysql php-mbstring -y
(2)修改php-fpm配置文件
[root@localhost ~]# vim /etc/php-fpm.d/www.conf listen = 192.168.2.112:9000 listen.allowed_clients = 192.168.2.110
(3)創建/var/lib/php/session目錄
[root@localhost ~]# mkdir -pv /var/lib/php/session 默認/var/lib/php/session目錄不存在,所以我們要創建此目錄 [root@localhost ~]# chown apache:apache /var/lib/php/session 修改屬主屬組為apache
(4)啟動php-fpm
[root@localhost ~]# systemctl start php-fpm
四、安裝部署應用
註意:因為此次試驗是將apache 和 php-fpm 分開部署的, 用戶訪問的動態資源請求會直接轉到 [192.168.2.112 php-fpm]主機上, 因此我們的網站目錄也需要部署到 [192.168.2.112 php-fpm]主機上 也就是說,網站目錄在[192.168.2.112 php-fpm]和[192.168.2.110 apache]各有一份 那麽我們怎麽做呢.只需要在[192.168.2.110 apache]部署完成以後直接推送到[192.168.2.112 php-fpm]主機上
(1)在主機c上創建網站目錄
[root@localhost ~]# mkdir -pv /www/htdocs/web{1,2} mkdir: 已創建目錄 "/www" mkdir: 已創建目錄 "/www/htdocs" mkdir: 已創建目錄 "/www/htdocs/web1" mkdir: 已創建目錄 "/www/htdocs/web2"
(2)安裝pma
1.解壓pma文件 [root@localhost ~]# unzip phpMyAdmin-4.0.10.20-all-languages.zip 2.將文件復制到網站目錄下 [root@localhost ~]# cp -a phpMyAdmin-4.0.10.20-all-languages /www/htdocs/web1/phpMyAdmin-4.0.10.20-all-languages 3.創建鏈接文件 [root@localhost ~]# cd /www/htdocs/web1/ [root@localhost web1]# ln -sv phpMyAdmin-4.0.10.20-all-languages pma "pma" -> "phpMyAdmin-4.0.10.20-all-languages" 4.修改配置文件 [root@localhost web1]# cd pma [root@localhost pma]# cp config.sample.inc.php config.inc.php [root@localhost pma]# vim config.inc.php $cfg['blowfish_secret'] = 'a8b7c6d'; /* YOU MUST FILL IN THIS FOR COOKIE AUTH! */ $cfg['Servers'][$i]['host'] = '192.168.2.111';
(3)安裝wordpress
1.解壓wordpress [root@localhost ~]# tar -xf wordpress-4.9.4-zh_CN.tar.gz 2.將文件復制到網站目錄下 [root@localhost ~]# cp -a wordpress /www/htdocs/web2/ [root@localhost ~]# cd /www/htdocs/web2/wordpress/ 3.修改配置文件 [root@localhost wordpress]# cp wp-config-sample.php wp-config.php [root@localhost wordpress]# vim wp-config.php define('DB_NAME', 'wpdb'); define('DB_USER', 'wpuser'); define('DB_PASSWORD', 'wpuser'); define('DB_HOST', '192.168.2.111');
(4)將主機C上/www目錄推送至主機a上
[root@localhost wordpress]# scp -rp /www [email protected]:/www
(5)連接pma及wordpress
安裝成功
五、xcache
[root@localhost wordpress]# yum install php-xcache -y
CentOS 7, lamp (php-fpm)