LAMP平臺的構成組件:php
本文講解Linux+apache+mariadb+PHP組合的架構,架構圖以下:
如圖所示,一次完整的訪問過程服務器主要經歷:Apache處理請求—>經過CGI接口訪問PHP的的應用程序—>PHP應用程序調用PHP解釋器執行PHP代碼—>PHP程序訪問調用數據庫—>最後給客戶端返回響應。
apache主要實現以下功能:前端
mariadb主要實現以下功能:mysql
php主要實現以下功能:linux
環境準備:sql
[root@centos7 ~]# yum -y install httpd php mariadb-server php-mysql
[root@centos7 ~]# systemctl stop firewalld; setenforce 0
[root@centos7 ~]# vim /etc/httpd/conf.d/vhost.conf <VirtualHost *:80> DocumentRoot "/app/blog/htdocs" #訪問的根目錄 CustomLog "logs/blog.com_access_log" combined #開啓日誌 <Directory "/app/blog/htdocs"> Require all granted #全部人能夠訪問 </Directory> </VirtualHost> [root@centos7 ~]# systemctl restart httpd
[root@centos7 ~]# vim /etc/my.cnf [mysqld] …… skip_name_resolve #禁止域名解析,解決遠程主機訪問慢 [root@centos7(nanyibo) ~]# systemctl restart mariadb.service
[root@centos7 blog]# mkdir -pv /app/blog [root@centos7 blog]# tar xvf wordpress-4.9.4-zh_CN.tar.gz -C /app/blog/ [root@centos7 blog]# mv wordpress wordpress-4.9.4 [root@centos7 blog]# ln -sv wordpress-4.9.4 htdocs #建立連接方便之後項目變動 [root@centos7 ~]# cd /app/blog/ [root@centos7 blog]# setfacl -m u:apache:rwx htdocs/ #設置指望值
[root@centos7 ~]# mysql MariaDB [(none)]> create database wpdb; MariaDB [(none)]> grant all on wpdb.* to 'wpuser'@'172.18.153.%' identified by 'wppass';
在瀏覽器輸入IP地址測試數據庫
搭建到這裏你點擊安裝便可,不演示。apache
咱們如今用的http協議,網頁顯示不安全,那麼咱們本身模擬作CA中心,本身給本身籤網頁證書
8.本機模擬搭建CA中心編程
[root@centos7 ~]# yum -y install mod_ssl #安裝依賴包 [root@centos7 ~]# cd /etc/pki/CA [root@centos7 ~]# (umask 066;openssl genrsa -out private/cakey.pem 4096) #生成CA的公鑰 [root@centos7 ~]# openssl req -new -x509 -key private/cakey.pem -out cacert.pem -days 3650 #生成CA的私鑰 Country Name (2 letter code) [XX]:CN State or Province Name (full name) []:HeNan Locality Name (eg, city) [Default City]:ZhengZhou Organization Name (eg, company) [Default Company Ltd]:cyn.com Organizational Unit Name (eg, section) []:opt Common Name (eg, your name or your server's hostname) []:ca.cyn.com #這一項不同便可,其餘隨意寫 Email Address []: [root@centos7 ~]# touch index.txt [root@centos7 ~]# echo 00 > serial
9.本身給本身頒發證書vim
[root@centos7 ~]# mkdir /etc/httpd/conf.d/ssl [root@centos7 ~]# cd /etc/httpd/conf.d/ssl [root@centos7 ~]# (umask 066;openssl genrsa -out httpd.key 1024) [root@centos7 ~]# openssl req -new -key httpd.key -out httpd.csr Country Name (2 letter code) [XX]:CN State or Province Name (full name) []:HeNan Locality Name (eg, city) [Default City]:ZhengZhou Organization Name (eg, company) [Default Company Ltd]:cyn.com Organizational Unit Name (eg, section) []:opt Common Name (eg, your name or your server's hostname) []:bbs.cyn.com#這一項與CA不同 Email Address []: Please enter the following 'extra' attributes to be sent with your certificate request A challenge password []: An optional company name []: [root@centos7 ~]# openssl ca -in httpd.csr -out httpd.crt -days 365 Certificate Details: #證書信息 ... Subject: countryName = CN stateOrProvinceName = HeNan organizationName = cyn.com organizationalUnitName = opt commonName = bbs.cyn.com ... Certificate is to be certified until Jun 30 12:47:06 2032 GMT (5000 days) Sign the certificate? [y/n]:y 1 out of 1 certificate requests certified, commit? [y/n]y Write out database with 1 new entries Data Base Updated [root@centos7 ~]# cp /etc/pki/CA/cacert.pem .
10.配置https後端
[root@centos7 ~]# vim /etc/httpd/conf.d/ssl.conf SSLCertificateFile /etc/httpd/conf.d/ssl/httpd.crt SSLCertificateKeyFile /etc/httpd/conf.d/ssl/httpd.key SSLCACertificateFile /etc/pki/CA/cacert.pem
11.瀏覽器再次測試
這個時候說明咱們本身的證書已經生效(紅色警告是由於本身作本身的CA中心,人家正宗的不認可。。。因此紅色警告)
12.如今把cacert.pem,放在window裏,該後綴名爲cacert.crt,把httpd.crt也放到window上,雙擊安裝證書
再去瀏覽器設置裏把證書設置爲信任證書
再去查看證書的詳細信息
12.瀏覽器輸入再次檢查https,不出現「不安全」字樣,則說明咱們作的CA證書生效
13.既然是我的博客,咱們也能夠給這個網頁加密碼
[root@centos7 ~]# vim /etc/httpd/conf.d/vhost.conf <VirtualHost *:80> DocumentRoot "/app/blog/htdocs" CustomLog "logs/blog.com_access_log" combined AllowOverride none AuthType Basic AuthName "Please login" AuthUserfile "/etc/httpd/conf/.htpasswd" Require user xiaofan #登錄用戶 <Directory "/app/blog/htdocs"> Require all granted #全部人能夠訪問 </Directory> </VirtualHost> [root@centos7 ~]# htpasswd -b -c -m /etc/httpd/conf/.htpasswd xiaofan centos #給yong'hu'she'zhi'm Adding password for user xiaofan
你再次登錄就會提示你輸入用戶帳號和密碼至此完成了lamp模式的我的博客搭建,完成https的認證