一 、搭建LNMP-02
1.配置官方源
[root@web01 ~]# cat /etc/yum.repos.d/nginx.repo
[nginx-stable]
name=nginx stable repo
baseurl=http://nginx.org/packages/centos/7/$basearch/
gpgcheck=1
enabled=1
gpgkey=https://nginx.org/keys/nginx_signing.key
module_hotfixes=true
2.yum安装nginx
[root@web01 ~]# yum install -y nginx
3.配置nginx
[root@web01 ~]# vim /etc/nginx/nginx.conf
user www;
...
http {
client_max_body_size 200m;
}
4.创建用户
[root@web01 ~]# groupadd www -g 666
[root@web01 ~]# useradd www -u 666 -g 666 -s /sbin/nologin -M
## 检查语法是否错误 nginx -t
5.启动nginx并开机自启
[root@web01 yum.repos.d]# systemctl restart nginx
[root@web01 yum.repos.d]# systemctl enable nginx
6.上传php包
[root@web01 ~]# rz
[root@web01 ~]# ll
-rw-r--r-- 1 root root 19889622 Nov 22 15:52 php.tar.gz
7.安装
[root@web01 ~]# tar xf php.tar.gz
[root@web01 ~]# yum localinstall -y *.rpm
8.配置PHP
[root@web01 ~]# vim /etc/php-fpm.d/www.conf
user = www
group = www
[root@web01 ~]# vim /etc/php.ini
upload_max_filesize = 500M
post_max_size = 500M
9.启动php并开机自启
[root@web01 ~]# systemctl start php-fpm
[root@web01 ~]# systemctl enable php-fpm
10.安装mariadb
[root@web01 ~]# yum install -y mariadb-server
11.启动mariadb并开机自启
[root@web01 ~]# systemctl start mariadb
[root@web01 ~]# systemctl enable mariadb
12.设置mysql数据库密码
[root@web01 ~]# mysqladmin -uroot password '123'
13.使用密码连接数据库测试
[root@web01 ~]# mysql -uroot -p123
二、搭建wordpress、知乎
1.上传代码包
[root@web01 ~]# mkdir /mm/
[root@web01 mm]# rz
[root@web01 mm]# ll
-rw-r--r-- 1 root root 8451194 Dec 1 09:07 WeCenter_3-2-1.zip
2.解压代码包
[root@web01 mm]# ll
drwxr-xr-x 5 1006 1006 4096 Jan 11 2019 wordpress
drwxr-xr-x 14 root root 296 Jun 4 2018 zhihu
3.授权代码
[root@web01 mm]# chown -R www.www /mm/
4.配置nginx
1、配置wordpress的nginx
[root@web01 conf.d]# cat 12mm.wp.com.conf
server {
listen 80;
server_name 12mm.wp.com;
location / {
root /mm/wordpress;
index index.php;
}
location ~* \.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_param SCRIPT_FILENAME /mm/wordpress/$fastcgi_script_name;
include fastcgi_params;
}
}
2、配置知乎的nginx配置
[[root@web01 conf.d]# cat 12mm.zh.com.conf
server {
listen 80;
server_name 12mm.zh.com;
root /mm/zhihu;
location / {
index index.php;
}
location ~* \.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
4、重启nginx
[root@web01 ~]# nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
[root@web01 ~]# systemctl restart nginx
5.配置本地hosts访问测试
10.0.0.9 12mm.zh.com
10.0.0.9 12mm.wp.com
6.数据库建库
[root@web01 ~]# mysql -uroot -p123
MariaDB [(none)]> show databases;
| information_schema |
| mysql |
| performance_schema |
| test |
+--------------------+
4 rows in set (0.01 sec)
MariaDB [(none)]> create database wordpress;
Query OK, 1 row affected (0.00 sec)
MariaDB [(none)]> create database zhihu;
Query OK, 1 row affected (0.00 sec)
MariaDB [(none)]> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| test |
| wordpress |
| zhihu |
+--------------------+
7.创建数据库用户并授权
MariaDB [(none)]> grant all on wordpress.* to wp@'localhost' identified by '123';
Query OK, 0 rows affected (0.07 sec)
MariaDB [(none)]> grant all on zhihu.* to zh@'localhost' identified by '123';
Query OK, 0 rows affected (0.00 sec)
#查看用户
MariaDB [(none)]> select user,host from mysql.user;
+------+------------+
| user | host |
+------+------------+
| wp | localhost |
| zh | localhost |
+------+------------+
8.根据页面提示操作
wp
账号:xx
密码:xxx
知乎zh
账号:xx
密码:xxx