编程知识 cdmana.com

Linux RedHat 7.4 build LNMP (deploy discuz Forum)

What is? LNMP?

Linux+Nginx+MySQL+PHP

Experimental results

use LNMP Building a Discuz Forum

Experiment preparation ( stay VMware Experiment in )

RedHat(RHEL)7.4

It's online


One 、 Change to alicloud yum Source

Query for installed yum

[root@localhost ~]# rpm -qa | grep yum
PackageKit-yum-1.1.5-1.el7.x86_64
yum-3.4.3-154.el7.noarch
yum-rhn-plugin-2.0.1-9.el7.noarch
yum-utils-1.1.31-42.el7.noarch
yum-metadata-parser-1.1.4-10.el7.x86_64
yum-langpacks-0.4.2-7.el7.noarch

Use root Permission to uninstall installed yum Source

[root@localhost ~]# rpm -qa | grep yum | xargs rpm -e --nodeps
warning: /etc/yum/pluginconf.d/langpacks.conf saved as /etc/yum/pluginconf.d/langpacks.conf.rpmsave

Download and install Alibaba's yum Source rpm package

( Browser open web address :https://mirrors.aliyun.com/centos/7/os/x86_64/Packages
And then one by one, search and download to local
The last to Linux Build one inside rpm file , Then copy the downloaded package into it )

wget https://mirrors.aliyun.com/centos/7/os/x86_64/Packages/yum-metadata-parser-1.1.4-10.el7.x86_64.rpm
wget https://mirrors.aliyun.com/centos/7/os/x86_64/Packages/yum-3.4.3-161.el7.centos.noarch.rpm
wget https://mirrors.aliyun.com/centos/7/os/x86_64/Packages/yum-plugin-fastestmirror-1.1.31-50.el7.noarch.rpm
wget https://mirrors.aliyun.com/centos/7/os/x86_64/Packages/yum-utils-1.1.31-50.el7.noarch.rpm
wget https://mirrors.aliyun.com/centos/7/os/x86_64/Packages/python-urlgrabber-3.10-9.el7.noarch.rpm

see rpm package

[root@localhost ~]#  mkdir rpm
[root@localhost ~]# cd rpm/
[root@localhost rpm]# ls
python-urlgrabber-3.10-10.el7.noarch.rpm
yum-3.4.3-168.el7.centos.noarch.rpm
yum-metadata-parser-1.1.4-10.el7.x86_64.rpm
yum-plugin-fastestmirror-1.1.31-54.el7_8.noarch.rpm
yum-utils-1.1.31-54.el7_8.noarch.rpm

install ( You have to force the installation of )

[root@localhost rpm]# rpm -ivh *.rpm  --force --nodeps
warning: python-urlgrabber-3.10-10.el7.noarch.rpm: Header V3 RSA/SHA256 Signature, key ID f4a80eb5: NOKEY
Preparing...                          ################################# [100%]
Updating / installing...
   1:yum-metadata-parser-1.1.4-10.el7 ################################# [ 20%]
   2:python-urlgrabber-3.10-10.el7    ################################# [ 40%]
   3:yum-plugin-fastestmirror-1.1.31-5################################# [ 60%]
   4:yum-3.4.3-168.el7.centos         ################################# [ 80%]
   5:yum-utils-1.1.31-54.el7_8        ################################# [100%]

Download Ali image to /etc/yum.repos.d/ Under the table of contents

[root@localhost ~]# cd /etc/yum.repos.d/
[root@localhost yum.repos.d]# wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
--2020-12-21 14:36:48--  http://mirrors.aliyun.com/repo/Centos-7.repo
Resolving mirrors.aliyun.com (mirrors.aliyun.com)... 112.19.3.184, 112.19.3.182, 112.19.3.183, ...
Connecting to mirrors.aliyun.com (mirrors.aliyun.com)|112.19.3.184|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 2523 (2.5K) [application/octet-stream]
Saving to: ‘/etc/yum.repos.d/CentOS-Base.repo’

100%[======================================>] 2,523       --.-K/s   in 0s      

2020-12-21 14:36:48 (140 MB/s) - ‘/etc/yum.repos.d/CentOS-Base.repo’ saved [2523/2523]

modify Centos-7.repo File will be all $releasever Replace with 7

[root@localhost yum.repos.d]# vim CentOS-Base.repo 

 Press Ctrl+:
 Input :%s/$releasever/7/g

Clear the cache and regenerate

[root@localhost yum.repos.d]# yum clean all
[root@localhost yum.repos.d]# yum makecache 

to update yum package

[root@localhost yum.repos.d]# yum update

Two 、 install Nginx

Download the kit you will use

[root@localhost ~]# yum install -y bash-completion vim wget  curl 

Set up Nginx Source

[root@localhost ~]# vim /etc/yum.repos.d/nginx.repo   --- Write the following configuration file 
[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
    
[nginx-mainline]
name=nginx mainline repo
baseurl=http://nginx.org/packages/mainline/centos/7/$basearch/
gpgcheck=1
enabled=0
gpgkey=https://nginx.org/keys/nginx_signing.key

[root@localhost ~]# yum clean all

[root@localhost ~]# yum makecache 

install Nginx

[root@localhost ~]# yum install nginx -y

restart

[root@localhost ~]# systemctl restart nginx
[root@localhost ~]# systemctl enable nginx

Set up firewall

[root@localhost ~]# systemctl stop firewalld.service 
[root@localhost ~]# systemctl disable firewalld.service 
[root@localhost ~]# setenforce 0

[root@localhost ~]# vim /etc/selinux/config 
SELINUX=disabled   --- Change it to disabled

Open the browser

Access... On the client side :192.168.112.131
 Insert picture description here


Four 、 change Nginx Configuration file for ( Change default html Path and add some content )

Replace Nginx The configuration file ( Delete the original file , Replace with the following )

[root@localhost ~]# vim /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;
}

Replace default.conf( Delete the original file , Replace with the following )

[root@localhost ~]# vim /etc/nginx/conf.d/default.conf

 server {
     listen       80;
     server_name  192.168.112.131;   --- Here's my own IP Address 
    #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;
#}
}

Because the root directory has been changed , So you need to create a new root directory

[root@localhost ~]# mkdir /opt/nginx/html -p
[root@localhost ~]# cp /usr/share/nginx/html/* /opt/nginx/html/
[root@localhost ~]# ll /opt/nginx/html/
total 8
-rw-r--r--. 1 root root 494 Dec 21 15:01 50x.html
-rw-r--r--. 1 root root 612 Dec 21 15:01 index.html

Changed the service profile , So you need to restart the service

[root@localhost ~]# systemctl restart nginx
[root@localhost ~]# systemctl status nginx


5、 ... and 、 Installation configuration MySQL database server

Download and install MySQL

[root@localhost ~]# wget https://dev.mysql.com/get/mysql80-community-release-el7-2.noarch.rpm
[root@localhost ~]# rpm -Uvh mysql80-community-release-el7-2.noarch.rpm
[root@localhost ~]# yum install mysql-community-server -y

start-up MySQL

[root@localhost ~]# systemctl restart mysqld
[root@localhost ~]# systemctl status mysqld

adopt grep Filter out his default password

[root@localhost ~]# grep 'password' /var/log/mysqld.log
2020-12-21T07:09:12.309082Z 6 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: =Wei9rR%io)P

Log in to the database with the default password

[root@localhost ~]# mysql -uroot -p'=Wei9rR%io)P'
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.22

Copyright (c) 2000, 2020, 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> 

Change password

mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'XXGC.lab123';
Query OK, 0 rows affected (0.01 sec)

mysql> exit
Bye

restart MySQL Database and set the boot up

[root@localhost ~]# systemctl restart mysqld
[root@localhost ~]# systemctl enable mysqld


6、 ... and 、 Installation configuration PHP Environmental Science

install php7 Of YUM Source

[root@localhost ~]# rpm -Uvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
[root@localhost ~]# rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm

install PHP7.2

[root@localhost ~]# yum install  php72w php72w-cli php72w-common php72w-gd php72w-ldap php72mbstring php72w-mcrypt php72w-mysql php72w-pdow -y

install php-fpm And start the

[root@localhost ~]# yum install php72w-fpm php72w-opcache -y
[root@localhost ~]# systemctl restart php-fpm.service 
[root@localhost ~]# systemctl enable php-fpm.service

modify php-fpm The configuration file

[root@localhost ~]# vim /etc/php-fpm.d/www.conf 
[www]
user = nginx    --- Change it to nginx
group = nginx   --- Change it to nginx
adjustment nginx The configuration file ( It is divided into the following two parts , It's all in the same configuration file )

1、 First modify the content of this block

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

2、 Add content to location ~ .php$ In this block

First, uncomment these lines , And then add something new

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;
}

establish MySQL Database administrator

[root@localhost ~]# mysql -uroot -p'XXGC.lab123'
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.22 MySQL Community Server - GPL

Copyright (c) 2000, 2020, 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 user 'dbadmin'@'%' identified with mysql_native_password by 'XXGC.lab123';
Query OK, 0 rows affected (0.01 sec)

mysql> grant all on *.* to 'dbadmin'@'%';
Query OK, 0 rows affected (0.01 sec)

mysql> grant GRANT OPTION  on *.* to 'dbadmin'@'%';
Query OK, 0 rows affected (0.00 sec)

mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)

mysql> exit
Bye


7、 ... and 、LNMP Environmental testing

Write profile

[root@localhost ~]# vim /etc/nginx/conf.d/default.conf
[root@localhost ~]# cd /opt/nginx/html/
[root@localhost html]# vim test.php   --- Write the following 
<?php
phpinfo();
?>
[root@localhost html]# systemctl restart php-fpm.service 
[root@localhost html]# systemctl restart nginx

Access... On the client side :192.168.112.131/test.php

( You can see php Test interface for What specific components can you see )
 Insert picture description here


Test if you can connect MySQL Database files

[root@localhost ~]# cd /opt/nginx/html/
[root@localhost html]# vim mysql.php
<?PHP
    $conn=mysqli_connect("192.168.112.131","dbadmin","XXGC.lab123");
    if($conn){
        echo"ok";
    }else{
        echo"error";    
    }
?>

Access... On the client side :192.168.112.131/mysql.php

If php And mysql Connect correctly, browser access will feedback OK Field of
 Insert picture description here

8、 ... and 、 download Discuz Forum documents

Discuz Now in gitee.com For maintenance

The address is :https://gitee.com/ComsenzDiscuz/DiscuzX

You can go to the website and download it by yourself Or upload Discuz Compress package to virtual machine

[root@localhost ~]# cd rpm/
[root@localhost rpm]# ls
Discuz_X3.4_SC_UTF8【20200818】.zip
python-urlgrabber-3.10-10.el7.noarch.rpm
yum-3.4.3-168.el7.centos.noarch.rpm
yum-metadata-parser-1.1.4-10.el7.x86_64.rpm
yum-plugin-fastestmirror-1.1.31-54.el7_8.noarch.rpm
yum-utils-1.1.31-54.el7_8.noarch.rpm

decompression

[root@localhost rpm]# unzip Discuz_X3.4_SC_UTF8【20200818】.zip 
[root@localhost rpm]# mv upload/ /opt/nginx/html/   --- Move the bag to nginx Under the webpage 

establish Discuz The database used by the Forum

[root@localhost ~]# mysql -uroot -p'XXGC.lab123'
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 12
Server version: 8.0.22 MySQL Community Server - GPL

Copyright (c) 2000, 2020, 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.01 sec)

mysql> exit
Bye

Resolve all file permissions , Writable permissions are required

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

On the client side, use the browser to open

Web site address :http://192.168.112.131/upload/install/

The following installation interface will be displayed :

Choose a new installation , Click next

Add information about the installation database , It must be added according to the actual situation .

Start installing Forum
 Insert picture description here

After installation, you can visit the forum
 Insert picture description here

版权声明
本文为[osc_ 7dwwmolq]所创,转载请带上原文链接,感谢
https://cdmana.com/2020/12/20201224105508501A.html

Scroll to Top