Objective:
Lamp for the site to build a very basic architecture, if only a static web page files, we can be processed through the basic Web server. When we need to deal with dynamic content, such as putting user data in a database, extracting data from a database, and so on, we have to use CGI to connect to applications that handle dynamic requests. FastCGI, as a resident CGI, can be used independently of Apache services, enabling distributed deployment. Next we use a host to build phpMyAdmin and WordPress, and let WordPress implement HTTPS.
Body:
Before deployment we briefly introduce the architecture we use, not to mention that lamp is our familiar Linux system, Apache,mysql (MARIDB) and PHP, this deployment process we use the database is MARIDB, basically and MySQL is not much difference. When our web server receives a request, if a static resource is requested, the server returns a static resource, and if a dynamic resource is requested, the server itself is not able to handle it and needs to be sent to a program that can handle the dynamic request. CGI is the interface that the HTTP server talks to other programs.
First, install the necessary procedures,
Yum install httpd php php-mysql php-fpm mariadb-server mariadb php-mbstring
Where Php-mysql is the PHP connection MySQL, PHP-FPM is fastcgi. Then we start these services.
Systemctl start Httpdsystemctl start mariadbsystemctl start php-fpm
Then we have to download MyAdmin and WordPress, unzip and put into the/var/www/html directory, and renamed to Vhost1 and Vhost2 respectively
Mv/var/www/html/{myadmin*,vhost1} Mv/var/www/html/{wordpress*,vhost2}
A server up to two Web services, so we have to use the virtual host implementation, the implementation method is particularly simple.
Modify the httpd configuration file,/etc/httpd/conf/httpd.conf find DocumentRoot comment out.
vim/etc/httpd/conf/httpd.conf #DocumentRoot "/var/www/html"
And then we started building our first virtual host. Vhost1, under the/etc/httpd/conf.d/directory, create a new vhost.conf to record the configuration of the virtual host. Configuration content:
#/etc/httpd/conf.d/vhost.conf directoryindex index.php<virtualhost *:80> Servername www.a.com Documentroot /var/www/html/vhost1 proxyrequests off proxypassmatch ^/(. *\.php) fcgi://127.0.0.1:9000/var /www/html/vhost1/$1 <directory "/var/www/html/vhost1" > options None allowoverride none require all granted </directory ></VirtualHost>
By default when we enter the URL or IP, we can automatically identify the working directory of the index.html file as the home page, in order to also recognize index.php, we have to configure DirectoryIndex index.php. The following is the configuration of the first virtual host. Our first website is placed under/var/www/html/vhost1, and the index.php is loaded automatically. At this point we can visit our first website, just enter the IP or domain name.
Two interprocess communication is to rely on a socket called the east, IP and port number, HTTP service default port is 80, of course, IP address is still difficult to remember, so we use a more readable domain name to identify a site. So when we want to put several sites on a single server, how do the servers differentiate them?
Virtual hosts can be architected in three ways, IP-based, Port-based, and domain-based. The most used is based on the implementation of different domain names.
Next, we implement based on httpd WordPress, in general, we have to buy their own certificates, placed on the server, but since it is their own casual play, also did not think of the online, so we can build a CA, issued a certificate. We open another Linux system as a CA server. Implementing a CA server is also fairly straightforward, generating a private key, and then using this private key to generate a self-visa book. The HTTP server then sends a certificate signing request to the CA server, which is signed and then sent to the HTTP server. Well, let's go straight to the implementation.
#CA服务器端 (172.16.254.181) Cd/etc/pki/ca (umask 077;openssl genrsa -out private/cakey.pem 2048) #生成私钥, let Openssl req -new -x509 -key in the private directory private/cakey.pem -out cacert.pem# by the above private key generated from the visa book touch serial index.txt # Generate a Count file echo 01 > serial #初始话计数. #http端 (172.16.53.183) cd /etc/httpd mkdir ssl #在httpd的配置文件目录下, New SSL is used to hold the private key and certificate Cd ssl (umask 077;openssl genrsa -out httpd.key 1024) #建立私钥openssl req -new -key httpd.key -out httpd.csr# Establish certificate signing request file scp httpd.csr The 172.16.253.181:/tmp# is sent to the CA server side. #服务器端openssl ca -in /tmp/httpd.csr -out certs/httpd.crt #签字, and put the certificate in the Certs directory, if the error, Basically because your CA server forgot to create index.txt or serial inside no serial number. scp certs/httpd.crt 172.16.53.180:/etc/httpd/ssl/#把证书发送到httpd服务器端
With SSL-based HTTPS, we have to use a module, so we'll install the module first.
Yum Install Mod_ssl
Mod_ssl configuration file for/etc/httpd/conf.d/ssl.conf, we put the configuration of the virtual host in/etc/httpd/conf.d/ Vhost.conf, so we first copy the SSL configuration to vhost.conf, and save the ssl.conf as a backup.
grep ' ^[^#].* '/etc/httpd/conf.d/ssl.conf >>/etc/httpd/conf.d/vhost.confmv/etc/httpd/conf.d/ssl.conf{,.bak}
Then modify the virtual host's configuration file. Only the places that have been modified are shown below.
#/etc/httpd/conf.d/vhost.conf
<virtualhost *:443>documentroot/var/www/html/vhost2# The root directory of this virtual host is Wordpressservername www.b.com# This servername for us to request the domain name of the certificate, our domain name must be consistent with the domain name of the certificate sslcertificatefile/etc/httpd/ssl/httpd.crt #证书文件SSLCertificateKeyFile/etc/ httpd/ssl/httpd.key# private key file Proxyrequests offproxypassmatch ^/(. *\.php) fcgi://127.0.0.1:9000/var/www/html/vhost2/$1 </VirtualHost>
As a configuration of the Web server itself, this is the end. However, we are different domain names to distinguish between different virtual host, but how to get the domain name and IP mapping it? The simplest method must be to write the mapping entries to the host file, but the blogger likes Shejinqiuyuan. Let's build a DNS.
This article is from the "mechanism of small Wind" blog, please be sure to keep this source http://xiaofengfeng.blog.51cto.com/8193303/1885737
Build phpMyAdmin and WordPress based on Lamp+fastcgi+https