CentOS7上搭建lamp
部署三台虚拟主机
vhost1:pma.dyz16.com, phpMyAdmin,
vhost2:wp.dyz16.com, wordpress
vhost3:dz.dyz16.com, Discuz 同时提供https服务;
一、搭建LAMP平台
yum安装软件无需手动解决依赖关系
1、最好按照如下次序安装,
yum install httpd Installed: httpd.x86_640:2.4.6-31.el7.centos #yum install php Installed php-common-5.4.16-23.el7_0.3.x86_64 php-cli-5.4.16-23.el7_0.3.x86_64 php-5.4.16-23.el7_0.3.x86_64 #yum install �Cy php-mysql php-pdo-5.4.16-23.el7_0.3.x86_64 php-mysql-5.4.16-23.el7_0.3.x86_64 # php和mysql的连接软件)
#yum install mariadb-server Installed: mariadb-server.x86_641:5.5.41-2.el7_0 Dependency Installed: mariadb.x86_641:5.5.41-2.el7_0 # mariadb-server是mariadb 服务器端,其依赖于mariadb的客户端 #启动httpd 、mariadb ~]# systemctl start httpd.service ~]# systemctl start mariadb.service
将wordpress压缩包解压
移动至/var/www/html目录下
unzip wordpress-4.3.1.tar.zip mv wordpress /var/www/html cd /var/www/wordpress
复制样例配置文件,
cp wp-config-sample.php wp-config.php
修改配置文件
vim wp-config.php 23 define('DB_NAME', 'wpdb'); 24 25 /** MySQL数据库用户名 */ 26 define('DB_USER', 'dyz'); 27 28 /** MySQL数据库密码 */ 29 define('DB_PASSWORD', '123456'); 30 31 /** MySQL主机 */ 32 define('DB_HOST', 'localhost'); 33
安全初始化脚本为管理员添加密码,删除匿名用户。生产环境中,最好禁止管理员远程登录!
~]# /usr/bin/mysql_secure_installation
创建数据库wpdb
添加 dyz用户,并授于全部权限 至wpdb数据库
MariaDB [(none)]> grant all on wpdb.* to 'dyz'@'localhost'identified by '123456'; Query OK, 0 rows affected (0.00 sec) MariaDB [(none)]> grant all on wpdb.* to 'dyz'@'127.0.0.1'identified by '123456'; Query OK, 0 rows affected (0.01 sec) MariaDB [(none)]> create database wpdb; Query OK, 1 row affected (0.00 sec) MariaDB [(none)]> flush privileges; Query OK, 0 rows affected (0.00 sec) MariaDB [(none)]> exit Bye
用dyz用户登录
[root@localhost wordpress]# mysql -udyz -p123456 Welcome to the MariaDB monitor. Commands end with ; or \g. Your MariaDB connection id is 21 Server version: 5.5.41-MariaDB MariaDB Server Copyright (c) 2000, 2014, Oracle, MariaDB Corporation Ab and others. Type 'help;' or '\h' for help. Type '\c' to clear the current inputstatement. MariaDB [(none)]> show databases -> ; +-----------------------------------+ | Database | +-----------------------------------+ | information_schema | | test | | wpdb | +----------------------------------+ 3 rows in set (0.00 sec)
设定数据库数据库管理员密码
MariaDB [(none)]> set password for 'root'@'localhost'=123456; ERROR 1064 (42000): You have an error in your SQL syntax; check themanual that corresponds to your MariaDB server version for the right syntax touse near '123456' at line 1 MariaDB [(none)]> set password for'root'@'localhost'=password('123456'); Query OK, 0 rows affected (0.00 sec)
wordpress部署
编辑配置文件; 基于域名的虚拟主机
vim /etc/httpd/conf/httpd.conf 119 #DocumentRoot "/var/www/html" 350 <Virtualhost *:80> 351 Servernamewp.dyz16.com 352 DocumentRoot/var/www/html 353 CustomLog/etc/httpd/logs/wp_access.log 354 ErrorLog/etc/httpd/logs/wp_err 355 356 </Virtualhost>
重启服务
systemctl restart htttpd systemctl restart mariadb
用浏览器打开测试
phpMyadmin
phpMyadmin是mysql的web接口,
将压缩包解压至httpd的根目录(/var/www/html/)下
unzip
mv /usr/local/phpadmin /var/www/html/ cd /var/www/html/phpmyadmin
复制样例配置文件 修改之 写一串随机数至。。
17 $cfg['blowfish_secret'] = 'f3389a71aad7d6ab883ac58c6fa561b6';
修改httpd配置文件,将php站点配置成基于域名的虚拟主机,以便在浏览器端访问
119 #DocumentRoot "/var/www/html" <Virtualhost *:80> 358 Servernamepma.dyz16.com 359 DocumentRoot/var/www/html 360 CustomLog/etc/httpd/logs/pma_access.log combined 361 ErrorLog/etc/httpd/logs/pma_err 362 </Virtualhost>
上面wordpress时,已为mariadb添加完成管理员密码了,此处不做赘述!
输入为用户登录设置的密码,即可登录!
此处是管理员登录的
登录后,即可在图形化界面对数据库进行操作,
Discuz 部署
在官网上可轻易下载到Discuz 包,解压即可使用
~]# unzip Discuz_X3.2_SC_UTF8.zip
readme upload utility
~]# cp �Cr upload /var/www/html
修改配置文件/etc/httpd/conf/httpd.conf,添加虚拟主机
vim /etc/httpd/conf/httpd.conf <Virtualhost *:80> 365 Servername dz.dyz16.com 366 DocumentRoot /var/www/html/discuz 367 CustomLog /etc/httpd/logs/dz_access.logcombined 368 ErrorLog /etc/httpd/logs/dz_err 370 </Virtualhost>
说明:域名servername 为dz.dyz16.com
根目录为/var/www/html/discuz
访问日志和错误日志目录指定,(重读配置文件可以自动生成)
修改/var/www/html/discuz的属主,属组为apache
修改目录的权限,为700
修改客户机上的hosts文件,就可以测试了,
win 的hosts文件的目录在C:\Windows\System32\drivers\etc
若是用linux 作为客户机测试只需 修改/etc/hosts
在hosts文件中添加一行
172.16.255.253 dz.dyz16.com
数据库上面已做初始化了,此处不作赘述!
重启httptd服务
systemctl restart httpd.service
因为上面已修改过hosts文件,此处可以直接用域名进行测试了。
(以下未做特殊说明,则默认next)
添写完整信息就可以下一步了,数据库安装完成就可以使用了
MariaDB [(none)]> grant all on ultrax.*to 'tom'@'localhost';
Query OK, 0 rows affected (0.00 sec)
MariaDB [(none)]> grant all on ultrax.*to 'tom'@'127.0.0.1';
Query OK, 0 rows affected (0.00 sec)
为数据库添加 用户tom ,赋予对数据库ultrax的所有权限
为dz.dyz16.com提供安全http服务
确保openssl软件已安装!
1.创建文件,索引文件,给一个初始序列号
cd /etc/pki/CA touch index.txt echo 01 > /serial
作为CA,想给别人发证,自己要有证书,因此自己要先创建私钥,向自己申请,为自己发证,路径不能改变
(umask 077;openssl genrsa -out/etc/pki/CA/private/cakey.pem 2048) openssl req -new -x509 -key/etc/pki/CA/private/cakey.pem -days 7300 -out /etc/pki/CA/cacert.pem
web端生成申请,推动给CA
(umask 077;openssl genrsa -out/etc/httpd/ssl/httpd.key 2048) oenpssl req -new -key/etc/httpd/ssl/httpd.key -out /etc/httpd/ssl/httpd.csr scp /etc/httpd/ssl/httpd.csr [email protected]:/ openssl ca -in /httpd.csr -out /httpd.crt-days 365
注:申请证书时,CA和web服务器端填写信息时,位置及公司信息要保持一致!域名信息要是你的主机名和webserver的信息
60 ServerNamedz.dyz16.com 100SSLCertificateFile /etc/httpd/ssl/dzdyz16.crt 101 102 # Server Private Key: 103 # If the key is not combined with thecertificate, use this 104 # directive to point at the key file. Keep in mind that if 105 # you've both a RSA and a DSA private key youcan configure 106 # both in parallel (to also allow the use ofDSA ciphers, etc.) 107SSLCertificateKeyFile /etc/httpd/ssl/httpd.key
确保ssl模块已安装且已启用!
重启服务
systemctl restart httpd.service
可以在CA端作为测试端,运行如下命令测试!
openssl s_client-connect 172.16.255.253:443 -CAfile /etc/pki/CA/cacert.pem
也可以将CA的证书放在客户端处,进行https://。。。
测试了