Yum搭建LNMP+部署Discuz论坛详细过程


一、环境要求


1.准备一台最小化安装的空机器。
2.系统我们安装的是CentOS7
3.关闭firewalld及selinux

二、首先下载一些我们会用到的工具包

yum install -y bash-completion vim wget  curl 

**

三、环境准备完我们首先来安装Nginx

3.1 设置Nginx源

[root@www ~]# yum install yum-utils -y
[root@www ~]# vi  /etc/yum.repos.d/nginx.repo  #添加以下内容
[nginx-stable]
name=nginx stable repo
baseurl=http://nginx.org/packages/centos/$releasever/$basearch/
gpgcheck=1
enabled=1
gpgkey=https://nginx.org/keys/nginx_signing.key
    
[nginx-mainline]
name=nginx mainline repo
baseurl=http://nginx.org/packages/mainline/centos/$releasever/$basearch/
gpgcheck=1
enabled=0
gpgkey=https://nginx.org/keys/nginx_signing.key

3.2 安装nginx服务

yum install nginx -y

3.3 设置nginx开机启动并开启nginx服务

[root@www ~]# systemctl enable  nginx.service
[root@www ~]# systemctl start  nginx.service 

3.4 下面我们查看Nginx的状态,如果显示“running”那就说明启动成功了

[root@www ~]# systemctl status  nginx.service 
    [root@www ~]# systemctl status  nginx.service 
    ● nginx.service - nginx - high performance web server
       Loaded: loaded (/usr/lib/systemd/system/nginx.service; enabled; vendor preset: disabled)
       Active: active (running) since Mon 2019-05-20 18:11:58 CST; 4s ago
         Docs: http://nginx.org/en/docs/
      Process: 1881 ExecStart=/usr/sbin/nginx -c /etc/nginx/nginx.conf (code=exited, status=0/SUCCESS)
     Main PID: 1882 (nginx)
       CGroup: /system.slice/nginx.service
               ├─1882 nginx: master process /usr/sbin/nginx -c /etc/nginx/nginx.conf
               └─1883 nginx: worker process
    
    May 20 18:11:58 www.lnmp.com systemd[1]: Starting nginx - high performance web server...
    May 20 18:11:58 www.lnmp.com systemd[1]: Started nginx - high performance web server.

3.5 测试是否可以访问Nginx 或使用浏览器访问IP地址

[root@www ~]# curl http://192.168.1.4  #(这里的IP要以你本机的IP为准)这里可以看到这样一个界面,说明你已经成功访问到Nginx了

Yum搭建LNMP+部署Discuz论坛详细过程_第1张图片**

四、更改Nginx的配置文件(更改默认html路径及增加一些内容)

**
4.1 替换Nginx配置文件(直接替换原文件即可)

root@lnmp conf.d]# cat /etc/nginx/nginx.conf
user nginx nginx;
worker_processes 4;
worker_cpu_affinity 00000001 00000010 00000100 00001000;
worker_rlimit_nofile 65535;

error_log /var/log/nginx/error.log warn;
pid /var/run/nginx.pid;
events {
	use epoll;
	worker_connections 10240;
}
http {
	include /etc/nginx/mime.types;
	default_type application/octet-stream;
	server_names_hash_bucket_size 128;
	client_header_buffer_size 2k;
	large_client_header_buffers 4 4k;
	client_max_body_size 8m;
	
	log_format main '$remote_addr - $remote_user [$time_local] "$request" '
			'$status $body_bytes_sent "$http_referer" '
			'"$http_user_agent" "$http_x_forwarded_for"';
			
	access_log /var/log/nginx/access.log main;
	
	sendfile off;
	tcp_nopush on;
	tcp_nodelay on;
	keepalive_timeout 65;
	fastcgi_cache_path /etc/nginx/fastcgi_cache levels=1:2 keys_zone=TEST:10m inactive=5m;
	fastcgi_cache_key http://$host$request_uri;
	fastcgi_connect_timeout 300;
	fastcgi_send_timeout 300;
	fastcgi_read_timeout 300;
	fastcgi_buffer_size 4k;
	fastcgi_buffers 8 4k;
	fastcgi_busy_buffers_size 8k;
	fastcgi_temp_file_write_size 8k;
	fastcgi_cache TEST;
	fastcgi_cache_valid 200 302 1h;
	fastcgi_cache_valid 301 1d;
	fastcgi_cache_valid any 1m;
	fastcgi_cache_min_uses 1;
	fastcgi_cache_use_stale error timeout invalid_header http_500;
	open_file_cache max=204800 inactive=20s;
	open_file_cache_min_uses 1;
	open_file_cache_valid 30s;
	
	gzip on;
	gzip_min_length 1K;
	gzip_buffers 4 16K;
	gzip_http_version 1.0;
	gzip_comp_level 2;
	gzip_types text/plain application/x-javascript text/css application/xml;
	gzip_vary on;
	
	include /etc/nginx/conf.d/*.conf;
}

4.2 替换default.conf(替换即可)

[root@www nginx]# vim /etc/nginx/conf.d/default.conf
 server {
     listen       80;
     server_name  www.lnmp.com;
    #charset koi8-r;
    #access_log  /var/log/nginx/host.access.log  main;
location / {
    root   /opt/nginx/html;
    index  index.html index.htm;
}
location /status
{
    stub_status on;
}

#error_page  404              /404.html;

# redirect server error pages to the static page /50x.html
#
error_page   500 502 503 504  /50x.html;

location = /50x.html {
    root   /opt/nginx/html;
}
location ~ .*/.(gif|jpg|jpeg|png|bmp|swf|js|css)$
{
    expires 30d;
}

# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
#    proxy_pass   http://127.0.0.1;
#}

# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
#location ~ \.php$ {
#    root           html;
#    fastcgi_pass   127.0.0.1:9000;
#    fastcgi_index  index.php;
#    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
#    include        fastcgi_params;
#}
  # deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
#    deny  all;
#}
}

4.3 由于更改了根目录,所以需要创建新的根目录

[root@lnmp nginx]# mkdir /opt/nginx/html -p
[root@lnmp nginx]# cp /usr/share/nginx/html/* /opt/nginx/html/
[root@lnmp nginx]# ll /opt/nginx/html/
total 8
-rw-r--r-- 1 root root 494 May 22 20:33 50x.html
-rw-r--r-- 1 root root 612 May 22 20:33 index.html

4.4 改变了服务配置文件,所以需要重新启动服务

[root@lnmp ~]# systemctl restart nginx.service 
[root@lnmp ~]# systemctl status nginx.service

五、安装配置MySQL数据库服务器并更改默认密码

5.1 下载安装MySQL

wget https://dev.mysql.com/get/mysql80-community-release-el7-2.noarch.rpm
rpm -Uvh mysql80-community-release-el7-2.noarch.rpm
yum install mysql-community-server

5.2 启动MySQL

[root@lnmp ~]# systemctl start mysqld.service 

5.3 更改MySQL默认密码
首先通过grep过滤出他的默认密码

[root@lnmp conf.d]#  grep 'password' /var/log/mysqld.log
2019-06-20T17:55:27.747610Z 5 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: iX9VGrCulX(&

5.4 使用默认密码登录数据库

[root@lnmp conf.d]# mysql -uroot -p'iX9VGrCulX(&'
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 8.0.16 MySQL Community Server - GPL

Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

5.5 更改密码

mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'NewPassWord2!';
mysql>exit

5.6 重启MySQL数据库并设置开机自启

[root@lnmp conf.d]# systemctl restart mysqld.service 
[root@lnmp conf.d]# systemctl enable mysqld.service

六、安装配置PHP环境

6.1 安装php7的YUM源

rpm -Uvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm

6.2 安装PHP7.2

yum install  php72w php72w-cli php72w-common php72w-gd php72w-ldap php72mbstring php72w-mcrypt php72w-mysql php72w-pdow

6.3 安装php-fpm并启动

[root@lnmp ~]# yum install php72w-fpm php72w-opcache
[root@lnmp ~]# systemctl enable php-fpm.service 
Created symlink from /etc/systemd/system/multi-user.target.wants/php-fpm.service to /usr/lib/systemd/system/php-fpm.service.
[root@lnmp ~]# systemctl start php-fpm.service 
[root@lnmp ~]# systemctl status php-fpm.service 
● php-fpm.service - The PHP FastCGI Process Manager
   Loaded: loaded (/usr/lib/systemd/system/php-fpm.service; enabled; vendor preset: disabled)
   Active: active (running) since Sat 2019-05-25 22:30:23 CST; 5s ago
 Main PID: 2368 (php-fpm)
   Status: "Ready to handle connections"
   CGroup: /system.slice/php-fpm.service
           ├─2368 php-fpm: master process (/etc/php-fpm.conf)
           ├─2369 php-fpm: pool www
           ├─2370 php-fpm: pool www
           ├─2371 php-fpm: pool www
           ├─2372 php-fpm: pool www
           └─2373 php-fpm: pool www

May 25 22:30:22 www.lnmp.com systemd[1]: Starting The PHP FastCGI Process Manager...
May 25 22:30:23 www.lnmp.com systemd[1]: Started The PHP FastCGI Process Manager.

6.4 修改php-fpm配置文件

[root@lnmp ~]# vim /etc/php-fpm.d/www.conf 
[www]
user = nginx
group = nginx

6.5 调整nginx配置文件
6.5.1 修改这一区块的内容

 [root@lnmp conf.d]# vi  /etc/nginx/conf.d/default.conf
    location / {
        root   /opt/nginx/html;
        index  index.php index.html index.htm;
    }

添加内容到location ~ .php$ 这个区块内 修改目录位置并取消注释

[root@lnmp conf.d]# vi  /etc/nginx/conf.d/default.conf
location ~ \.php$ {
root /opt/nginx/html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /opt/nginx/html$fastcgi_script_name;
include fastcgi_params;
}

如图:Yum搭建LNMP+部署Discuz论坛详细过程_第2张图片6.6 创建MySQL数据库管理员

mysql -uroot -p'NewPassWord2!';
mysql> create user 'dbadmin'@'%' identified with mysql_native_password by 'Com.123456';
mysql> grant all on *.* to 'dbadmin'@'%';
mysql> grant GRANT OPTION  on *.* to 'dbadmin'@'%';
mysql> flush privileges;
mysql>exit

七、LNMP环境测试

[root@lnmp html]# pwd
/opt/nginx/html
[root@lnmp html]# vi test.php

在客户端访问:192.168.1.4/test.php (可以看到php的测试界面 可以看到你少哪些具体的组件)
Yum搭建LNMP+部署Discuz论坛详细过程_第3张图片

7.1 测试是否可以连接MySQL数据库文件

这里的your_dbpasswd是dbadmin用户的密码如果全程复制我的代码那么是Com.123456 自行修改

[root@www html]# cat mysql_test.php 

如果php与mysql连接正确浏览器访问会反馈OK的字段

如图:
Yum搭建LNMP+部署Discuz论坛详细过程_第4张图片

八、下载Discuz论坛文件

Discuz现在在gitee.com进行维护,地址为:https://gitee.com/ComsenzDiscuz/DiscuzX #可进入网站自行下载 或上传Discuz压缩包到虚拟机
#也可以通过网盘下载链接:https://pan.baidu.com/s/1Fp2VMMIpdaM1F706S9gKUg
提取码:nmzc

[root@www lnmp]# unzip master.zip
[root@www lnmp# cd DiscuzX/
[root@www DiscuzX]# ls
readme  README.md  upload  utility
[root@www DiscuzX]# mv upload/ /opt/nginx/html/

8.1 建立Discuz论坛所用数据库

[root@lnmp ~]# mysql -u dbadmin -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 11
Server version: 8.0.16 MySQL Community Server - GPL

Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> create database discuz;
Query OK, 1 row affected (0.03 sec)

mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| discuz             |
| information_schema |
| mysql              |
| performance_schema |
| sys                |
+--------------------+
5 rows in set (0.00 sec)

mysql> exit
Bye

8.2 安装Discuz论坛
解决所有文件权限,需要可写权限

[root@www ~]# cd /opt/nginx/html/upload/
[root@www upload]# chmod -R 777 ./config/ ./data/ ./uc_client/ ./uc_server/
[root@www upload]# chown  nginx:nginx -R /opt/nginx/html/upload/

8.3 在客户端使用浏览器打开
网站地址:http://192.168.1.4/upload/install/, 会显示以下安装界面:
选择全新安装,点击下一步
添加安装数据库有关信息,必须要按照实际情况添加。
开始安装论坛,安装完毕后就可以访问论坛了。
成品图:
Yum搭建LNMP+部署Discuz论坛详细过程_第5张图片
感谢浏览

你可能感兴趣的:(Yum搭建LNMP)