Linux 簡單部署LAMP:
實驗環境:
1、主機系統Centos6.7_X86_64
2、DNS&CA:192.168.3.10
3、LAMP安裝方式為rpm
4、主機IP:192.168.3.11提供web站點:
http://wp.neolinux.com #phpMyAdmin-4.0.5-all-languages
https://pma.neolinux.com #wordpress-3.3.1-zh_CN.zip
http://dz.neolinux.com #Discuz_X3.2_SC_UTF8.zip
5、安裝過程:
準備DNS環境
YUM方式安裝httpd,php,mysql
配置httpd
配置mysql
測試httpd—php—mysql的關聯
準備測試網站文件
配置網站文件
測試訪問
SSL配置
測試效果
=================================
一、準備DNS環境:
[root@ns1 ~]# vi /var/named/neolinux.com.zone pma IN A 192.168.3.20 wp IN A 192.168.3.20 dz IN A 192.168.3.20 [root@ns1 ~]# ping wp -c 1 [root@ns1 ~]# ping pma -c 1 [root@ns1 ~]# ping dz -c 1
二、YUM方式安裝LAMP:
[root@case1 ~]# yum install httpd php php-mysql mysql-server php-mbstring php-mcrypt php5-zts -y #httpd:2.2.15-53.el6.centos #php:5.3.3-47.el6 #mysql-server:5.1.73-7.el6
三、配置httpd:
[root@case1 ~]##mkdir -p /www/vhosts/{wp,pma,dz} [root@case1 ~]# mv /etc/httpd/conf.d/welcome.conf{,.bk} [root@case1 ~]#vi /etc/httpd/conf/httpd.conf ServerName localhost:80 KeepAlive on Listen 192.168.3.11:80 #DocumentRoot "/var/www/html" NameVirtualHost 192.168.3.11:80 <VirtualHost 192.168.3.11:80> ServerAdmin wpadmin@neolinux.com DocumentRoot /www/vhosts/wp ServerName wp.neolinux.com ErrorLog logs/wp-error_log CustomLog logs/wp-access_log common </VirtualHost> <VirtualHost 192.168.3.11:80> ServerAdmin pmaadmin@neolinux.com DocumentRoot /www/vhosts/pma ServerName pma.neolinux.com ErrorLog logs/pma-error_log CustomLog logs/pma-access_log common </VirtualHost> <VirtualHost 192.168.3.11:80> ServerAdmin dzadmin@neolinux.com DocumentRoot /www/vhosts/dz ServerName dz.neolinux.com ErrorLog logs/dz-error_log CustomLog logs/dz-access_log common </VirtualHost> [root@case1 conf]# httpd -t Syntax OK [root@case1 conf]#
四、配置MYSQL:
[root@case1 ~]# service mysqld start [root@case1 ~]# mysql mysql> SHOW DATABASES; +--------------------+ | Database | +--------------------+ | information_schema | | mysql | | test | +--------------------+ 3 rows in set (0.00 sec) mysql> use mysql; Database changed mysql> SELECT user,host,password FROM user; +------+--------------------+----------+ | user | host | password | +------+--------------------+----------+ | root | localhost | | | root | case1.neolinux.com | | | root | 127.0.0.1 | | | | localhost | | | | case1.neolinux.com | | +------+--------------------+----------+ 5 rows in set (0.00 sec) mysql> DELETE FROM user where user=''; Query OK, 2 rows affected (0.01 sec) mysql> DELETE FROM user where user='root' and host='case1.neolinux.com'; Query OK, 1 row affected (0.01 sec) mysql> UPDATE user SET password=PASSWORD("manager1") where user='root'; Query OK, 2 rows affected (0.00 sec) Rows matched: 2 Changed: 2 Warnings: 0 mysql> CREATE DATABASE wpdb; Query OK, 1 row affected (0.00 sec) mysql> GRANT ALL ON wpdb.* TO 'wpuser'@'localhost' IDENTIFIED BY 'wppasswd'; Query OK, 0 rows affected (0.00 sec) mysql> GRANT ALL ON wpdb.* TO 'wpuser'@'127.0.0.1' IDENTIFIED BY 'wppasswd'; Query OK, 0 rows affected (0.00 sec) mysql> FLUSH PRIVILEGES; Query OK, 0 rows affected (0.00 sec)
五、測試httpd—php—mysql關聯
HTTPD與PHP有三種方式關聯:module,CGI,FPM(fast CGI),這里我們是采用module方式
[root@case1 ~]# rpm -ql php #檢查PHP安裝的文件 /etc/httpd/conf.d/php.conf #在HTTPD配置目錄下生成了PHP.CONF的配置文件,當我們啟動HTTPD時,會加載此配置文件,這樣PHP就以模塊化的方式與HTTP結合工作 /usr/lib64/httpd/modules/libphp5.so #HTTP2.2與PHP關聯的模塊, /var/lib/php/session /var/www/icons/php.gif [root@case1 ~]# less /etc/httpd/conf.d/php.conf <IfModule prefork.c> LoadModule php5_module modules/libphp5.so #這里說明了,當HTTP工作在prefork模式當中,需要用到libphp5.so這樣的PHP模塊,默認PHP安裝 </IfModule> <IfModule worker.c> LoadModule php5_module modules/libphp5-zts.so #當HTTP工作在worker模式當中,需要用libphp5-zts.so模塊,在php5-zts當中 </IfModule> [root@case1 ~]# vi /www/vhosts/wp/index.php #建立測試頁面 <?php $link = mysql_connect('127.0.0.1','root','manager1'); if ($link) echo "sucess"; else echo "failure"; mysql_close(); phpinfo(); ?> [root@case1 ~]# service httpd start #啟動httpd服務 Starting httpd: [ OK ] [root@case1 ~]#
六、準備測試網站文件
[root@case1 src]# ll -rw-r--r-- 1 root root 12486773 Jun 14 19:20 Discuz_X3.2_SC_UTF8.zip -rw-r--r-- 1 root root 8004371 Jun 14 19:20 phpMyAdmin-4.0.5-all-languages.zip -rw-r--r-- 1 root root 4657514 Jun 14 19:20 wordpress-3.3.1-zh_CN.zip [root@case1 src]# unzip wordpress-3.3.1-zh_CN.zip [root@case1 src]# unzip Discuz_X3.2_SC_UTF8.zip [root@case1 src]# unzip phpMyAdmin-4.0.5-all-languages.zip [root@case1 src]# ls phpMyAdmin-4.0.5-all-languages.zip upload wordpress Discuz_X3.2_SC_UTF8.zip phpMyAdmin-4.0.5-all-languages readme utility wordpress-3.3.1-zh_CN.zip [root@case1 src]# cp -r wordpress/* /www/vhosts/wp/ cp: overwrite `/www/vhosts/wp/index.php'? y [root@case1 src]# cp -r upload/* /www/vhosts/dz/ [root@case1 src]# cp -r phpMyAdmin-4.0.5-all-languages/* /www/vhosts/pma/ =====WP配置===== [root@case1 wp]# cp wp-config-sample.php wp-config.php #網頁開發者定義好了關聯mysql的數據配置文件 [root@case1 wp]# vi wp-config.php /** WordPress 數據庫的名稱 */ define('DB_NAME', 'wpdb'); #我們之前在MYSQL定義好的數據庫名字,wpdb /** MySQL 數據庫用戶名 */ define('DB_USER', 'wpuser'); #管理wpdb數據庫的帳號,root也可以 /** MySQL 數據庫密碼 */ define('DB_PASSWORD', 'wppasswd'); #管理wpdb數據庫的密碼, /** MySQL 主機 */ define('DB_HOST', '127.0.0.1'); #localhost也可以
七、配置各網站并測試
登錄網站:
=====PMA=====
[root@case1 ~]# cd /www/vhosts/pma/libraries/ #phpmyadmin配置默認登錄的信息配置文件位置 [root@case1 libraries]# vi config.default.php #配置文件還有很多可以針對連接MYSQL做限制 $cfg['Servers'][$i]['host'] = '127.0.0.1'; $cfg['Servers'][$i]['user'] = 'root'; $cfg['Servers'][$i]['password'] = 'manager1';
登錄網頁測試:http://pma.neolinux.com
=====DZ=====直接打開http://dz.neolinux.com 安裝DZ即可
安裝DZ
需要創建與修改文件屬性
[root@case1 dz]# chmod 777 config data data/cache data/avatar data/plugindata data/download data/addonmd5 data/template data/threadcache data/attachment data/attachment/album data/attachment/forum data/attachment/group data/log uc_client/data/cache uc_server/data/ uc_server/data/cache uc_server/data/avatar uc_server/data/backup uc_server/data/logs uc_server/data/tmp uc_server/data/view
DZ安裝完成:
八、SSL配置https://pma.neolinux.com
SSl配置需要安裝mod_ssl,然后創建密鑰,創建證書請求,并于CA簽署
[root@case1 ~]# yum install mod_ssl
CA配置:(192.168.3.10),也是DNS服務器
[root@ns1 CA]# touch /etc/pki/CA/{index.txt,serial} #我遇到的情況是在沒有此兩個文件的情況下,給客戶端簽發證書的時候,會報錯。 [root@ns1 CA]# (umask 077; openssl genrsa -out ./private/cakey.pem 2048) #創建密鑰(私鑰,公鑰是從私鑰中提取出來), [root@ns1 CA]# openssl req -new -x509 -key ./private/cakey.pem -out ./cacert.pem -days 3650 #為CA自己簽署證書,casert.pem根據openssl的配置文件/etc/pki/tls/openssl.cnf,必須放在此目錄,否則會出錯 You are about to be asked to enter information that will be incorporated #或者自己修改配置文件也可 into your certificate request. What you are about to enter is what is called a Distinguished Name or a DN. There are quite a few fields but you can leave some blank For some fields there will be a default value, If you enter '.', the field will be left blank. ----- Country Name (2 letter code) [XX]:CN State or Province Name (full name) []:GD Locality Name (eg, city) [Default City]:ShenZhen Organization Name (eg, company) [Default Company Ltd]:neolinux Organizational Unit Name (eg, section) []:neolinux Common Name (eg, your name or your server's hostname) []:ns1.neolinux.com Email Address []:caadmin@neolinux.com [root@ns1 CA]#
web服務器生成證書請求:
[root@case1 ~]# mkdir /etc/httpd/ssl [root@case1 ~]# cd /etc/httpd/ssl [root@case1 ssl]# (umask 077; openssl genrsa -out ./httpd.pem 2048) Generating RSA private key, 2048 bit long modulus .....................+++ ...........+++ e is 65537 (0x10001) [root@case1 ssl]# openssl req -new -key ./httpd.pem -out ./httd.csr -days 365 You are about to be asked to enter information that will be incorporated into your certificate request. What you are about to enter is what is called a Distinguished Name or a DN. There are quite a few fields but you can leave some blank For some fields there will be a default value, If you enter '.', the field will be left blank. ----- Country Name (2 letter code) [XX]:CN State or Province Name (full name) []:GD Locality Name (eg, city) [Default City]:ShenZhen Organization Name (eg, company) [Default Company Ltd]:neolinux Organizational Unit Name (eg, section) []:neolinux Common Name (eg, your name or your server's hostname) []:pma.neolinux.com #web服務器名字,客戶端訪問服務器的名字 Email Address []:pmaadmin@neolinux.com Please enter the following 'extra' attributes to be sent with your certificate request A challenge password []: An optional company name []: [root@case1 ssl]#
web服務器將證書簽署請求發送到CA服務器
[root@case1 ssl]# scp httpd.csr root@192.168.3.10:/tmp The authenticity of host '192.168.3.10 (192.168.3.10)' can't be established. RSA key fingerprint is 42:b8:1a:11:b4:43:da:8d:5b:5a:2b:1b:35:ab:64:56. Are you sure you want to continue connecting (yes/no)? yes Warning: Permanently added '192.168.3.10' (RSA) to the list of known hosts. root@192.168.3.10's password: httpd.csr 100% 1066 1.0KB/s 00:00 [root@case1 ssl]#
CA服務器簽署請求,在把簽署的證書發送至客戶端:
[root@ns1 CA]# openssl ca -in /tmp/httpd.csr -out ./certs/pma.neolinux.com.crt -days 365 Using configuration from /etc/pki/tls/openssl.cnf Check that the request matches the signature Signature ok Certificate Details: Serial Number: 2 (0x2) Validity Not Before: Jun 8 21:42:38 2016 GMT Not After : Jun 8 21:42:38 2017 GMT Subject: countryName = CN stateOrProvinceName = GD organizationName = neolinux organizationalUnitName = neolinux commonName = pma.neolinux.com emailAddress = pmaadmin@neolinux.com X509v3 extensions: X509v3 Basic Constraints: CA:FALSE Netscape Comment: OpenSSL Generated Certificate X509v3 Subject Key Identifier: 26:A8:87:EC:9E:48:1D:EB:02:4C:7B:A3:0F:BC:7E:ED:AC:AC:02:5E X509v3 Authority Key Identifier: keyid:BD:DF:31:79:2D:BC:8E:7A:8C:94:07:C4:28:EC:9A:5B:8C:F1:27:AB Certificate is to be certified until Jun 8 21:42:38 2017 GMT (365 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@ns1 CA]# [root@ns1 CA]# scp certs/pma.neolinux.com.crt root@192.168.3.11:/etc/httpd/ssl root@192.168.3.11's password: pma.neolinux.com.crt 100% 4651 4.5KB/s 00:00 [root@ns1 CA]#
配置SSL服務器:
[root@case1 ssl]# vi /etc/httpd/conf.d/ssl.conf <VirtualHost pma.neolinux.com:443> DocumentRoot "/www/vhosts/pma" ServerName pma.neolinux.com:443 SSLCertificateFile /etc/httpd/ssl/pma.neolinux.com.crt SSLCertificateKeyFile /etc/httpd/ssl/httpd.pem
將CA簽署自己的證書,傳送至測試客戶端并且安裝在受信任的證書頒發機構:
重新登錄網頁檢查:
SHA1谷歌瀏覽器會認為是不安全的。
pma.neolinux.com既然已經采用ssl加密,那么我們應該把如下注釋:
#<VirtualHost 192.168.3.11:80> # ServerAdmin pmaadmin@neolinux.com # DocumentRoot /www/vhosts/pma # ServerName pma.neolinux.com # ErrorLog logs/pma-error_log # CustomLog logs/pma-access_log common #</VirtualHost>
實驗告一段落
原創文章,作者:nice_neo_linux,如若轉載,請注明出處:http://www.www58058.com/18254
圖文并茂,突顯認真特質。專業!