Implementation of LNMP by rpm packet
Rpm package lnmp
Nginx- host: 172.16.40.99
Php-fpm- host: 172.16.40.11
Mariadb- host: 172.16.40.88
one。 Install, configure nginx- host: 172.16.40.99
Installation:
# yum install nginx
# start nginx
# nginx-s stop stop
# nginx-t test whether the configuration file is correct
# nginx-s reload reload configuration file
Configure two virtual hosts:
# vim / etc/nginx/conf.d/vhosts1.conf
Server {
Listen 80
Server_name www1.ryanpeng.com
Root / data/vhost/www1
Location ~\ .php$ {
Fastcgi_index index.php
Fastcgi_pass 172.16.40.11:9000
Fastcgi_param SCRIPT_FILENAME / data/vhost/www1 $fastcgi_script_name
(indicates that files ending in .php are passed to php-fpm for processing, where the address is the php server address)
Include fastcgi_params
}
}
# vim / etc/nginx/conf.d/vhosts2.conf
Server {
Listen 80
Server_name www2.ryanpeng.com
Root / data/vhost/www2
Location ~\ .php$ {
Fastcgi_index index.php
Fastcgi_pass 172.16.40.11:9000
Fastcgi_param SCRIPT_FILENAME / data/vhost/www2 $fastcgi_script_name
Include fastcgi_params
}
}
# mkdir-pv / data/vhost/www {1pm 2}
Www {1 ~ 2} (add a test page under the directory to test whether nginx is running the virtual host properly)
Index.php (for switching to php-fpm hosts)
#-- Virtual host configuration file with cache entry-- #
Server {
Listen 80
Root / data/vhost/www1
Location ~\ .php$ {
Fastcgi_cache_valid 200 1m
Fastcgi_cache one
Fastcgi_cache_key $uri
Fastcgi_cache_min_uses 2
Fastcgi_cache_methods GET
Fastcgi_index index.php
Fastcgi_pass 172.16.40.11:9000
Fastcgi_param SCRIPT_FILENAME / data/vhost/www1 $fastcgi_script_name
Include fastcgi_params
}
Location / {
Rewrite / (. *) $https://www1.ryanpeng.com/$1;
}
}
#-- Port 80 of the virtual host profile of https becomes 443Murray configuration #
Server {
Listen 443 ssl
Root / data/data/www1
Ssl on
Ssl_certificate www1.cacert
Ssl_certificate_key www1.key
Ssl_session_cache shared:SSL:1m
Ssl_session_timeout 1m
Ssl_ciphers HIGH:!aNULL:!MD5
Location ~\ .php$ {
Fastcgi_cache_valid 200 1m
Fastcgi_cache one
Fastcgi_cache_key $uri
Fastcgi_cache_min_uses 2
Fastcgi_cache_methods GET
Fastcgi_index index.php
Fastcgi_pass 172.16.40.11:9000
Fastcgi_param SCRIPT_FILENAME / data/data/www1 $fastcgi_script_name
Include fastcgi_params
}
}
two。 Install and configure php-fpm host: 172.16.40.11
Installation:
# rpm-Q php # make sure there is no php program before
# yum install php-fpm php-mysql php-mbstring
# mkdir / var/lib/php/session
# useradd-r nginx
# chown nginx.nginx / var/lib/php/session/
Configuration:
# vim / etc/php-fpm.d/www.conf
Listen = 172.16.40.11 9000 (set the listening address of the php server, that is, the address that listens locally and can communicate with the outside world)
Listen.allowed_clients = 172.16.40.99 (listens for IP addresses with httpd services)
# mkdir-pv / data/vhost/www {1pm 2}
# vim / data/vhost/www1/index.php
This is vhost1
# vim / data/vhost/www2/index.php
This is vhost2
Test www1.ryanpeng.com,www2.ryanpeng.com separately to see if nginx and php-fpm are connected successfully.
three。 Install and configure mariadb host: 172.16.40.88
Installation startup:
# yum install mariadb-server
# systemctl start mariadb.service
Create a database and authorized users:
MariaDB [(none)] > grant all on db.* to 'dbuser'@'172.16.%.%' identified by "dbpasswd"
MariaDB [(none)] > CREATE DATABASE db
Set up a php test page on the php server (172.16.40.11) to test whether the php host can connect to the database host properly.
# vim / data/vhost/www1/index.php
Test whether the connection is successful. If ok is displayed, it is proved that the connection is successful.
four。 Deploy WordPress and phpMyadmin on the virtual host 1 and 2, respectively
On the php-fpm host (172.16.40.11), download phpMyAdmin-4.0.5-all-languages.zip and wordpress-4.3.1-zh_CN.zip
Move the extracted file wordpress phpMyAdmin-4.0.5-all-languages to the www1 and www2 directories under / data/vhost/, respectively.
Deploy WordPress
# cd / data/vhost/www1/wordpress/
# cp wp-config-sample.php wp-config.php
# vim wp-config.php
Define ('DB_NAME',' wpdb')
/ * * MySQL database user name * /
Define ('DB_USER',' wpuser')
/ * * MySQL database password * /
Define ('DB_PASSWORD',' wppasswd')
/ * * MySQL host * /
Define ('DB_HOST',' 172.16.40.88')
# scp-r wordpress/ 172.16.40.99:/data/vhost/www1/
Deploy phpMyadmin
# cd / data/vhost/www2
# ln-sv phpMyAdmin-4.0.5-all-languages phpMyAdmin (create soft links to facilitate rollback)
# cd phpMyAdmin
# cp config.sample.inc.php config.sample.php
# vim config.sample.php
$cfg ['blowfish_secret'] =' jACG7X2usbnwzg=='; (generated using openssl rand-base64 10)
$cfg ['Servers'] [$I] [' host'] = '172.16.40.88 address; (database server address)
$cfg ['Servers'] [$I] [' user'] = 'dbuser'
$cfg ['Servers'] [$I] [' password'] = 'dbpass'
# scp-r phpMyAdmin/ 172.16.40.99:/data/vhost/www2/
Log in to two virtual machines and test WordPress and phpMyadmin
five。 Install xcache on the php-fpm (172.16.40.11) host:
Install php-xache
# yum-y install php-xcache
# systemctl restart php-fpm.service
Configuration file for simple configuration
# vim / etc/php.d/xcache.ini
Xcache.size = 300m
Stress testing before and after loading xcache
# ab-n 10000-c 1000 http://www1.ryanpeng.com/wordpress | http://www2.ryanpeng.com/phpmyadmin