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.178linux.com/18254


评论列表(1条)
图文并茂,突显认真特质。专业!