LNMP+PHPMyAdmin+Discuz

LNMP环境部署

一、Linux操作系统

1.安装Linux

1.使用VMware workstation新建虚拟机
2.安装CentOS7.8系统,最小化安装,记得要选中“开发工具(development tools)”

2. 系统初始化设置

# 主机名
$ hostnamectl set-hostname lnmp

# Linux 系统资源调配
$ vim /etc/security/limits.conf
*                soft    nofile          65535
*                hard    nofile          65535
*                soft    noproc          65535
*                hard    noproc          65535

# Selinux
$ setenforce 0
$ vim /etc/selinux/config
ELINUX=disabled

3. yum源

$ yum install epel-release -y
$ rpm -ivh http://rpms.remirepo.net/enterprise/remi-release-7.rpm
$ vim /etc/yum.repos.d/remi.repo
[epel]
enabled=1

二、Nginx网站服务器

1. 添加yum源

$ yum install yum-utils -y
$ cat /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

2. nginx服务

# 安装
$ yum install nginx -y

# 开启服务
$ systemctl start nginx

# 开机自启
$ systemctl enable nginx
Created symlink from /etc/systemd/system/multi-user.target.wants/nginx.service to /usr/lib/systemd/system/nginx.service.

# 查看状态
$ systemctl status nginx
● nginx.service - nginx - high performance web server
   Loaded: loaded (/usr/lib/systemd/system/nginx.service; enabled; vendor preset: disabled)
   Active: active (running) since Mon 2021-03-15 07:17:26 EDT; 11s ago
     Docs: http://nginx.org/en/docs/
 Main PID: 2976 (nginx)
   CGroup: /system.slice/nginx.service
           ├─2976 nginx: master process /usr/sbin/nginx -c /etc/nginx/nginx.conf
           └─2977 nginx: worker process

Mar 15 07:17:26 lnmp systemd[1]: Starting nginx - high performance web server...
Mar 15 07:17:26 lnmp systemd[1]: Started nginx - high performance web server.

3. 防火墙

# 放行http服务
$ firewall-cmd --add-service=http --permanent 
$ firewall-cmd --reload

4. 访问nginx

$ curl 192.168.119.136
<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
<style>
    body {
        width: 35em;
        margin: 0 auto;
        font-family: Tahoma, Verdana, Arial, sans-serif;
    }
</style>
</head>
<body>
<h1>Welcome to nginx!</h1>
<p>If you see this page, the nginx web server is successfully installed and
working. Further configuration is required.</p>

<p>For online documentation and support please refer to
<a href="http://nginx.org/">nginx.org</a>.<br/>
Commercial support is available at
<a href="http://nginx.com/">nginx.com</a>.</p>

<p><em>Thank you for using nginx.</em></p>
</body>
</html>

5. 调整nginx主配置文件

$ cat /etc/nginx/nginx.conf 

user  nginx;
worker_processes  auto;
worker_cpu_affinity auto;
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;

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

6. default.conf

$ cat /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   /usr/share/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   /usr/share/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;
    #}
}

7. 重启服务

$ nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
$ systemctl restart nginx

三、MariaDB数据库

1. 安装MariaDB

$ yum install mariadb-server -y

2. mariadb服务

# 启动服务
$ systemctl start mariadb

# 开机自启
$ systemctl enable mariadb
Created symlink from /etc/systemd/system/multi-user.target.wants/mariadb.service to /usr/lib/systemd/system/mariadb.service.

# 查看状态
$ systemctl status mariadb
● mariadb.service - MariaDB database server
   Loaded: loaded (/usr/lib/systemd/system/mariadb.service; enabled; vendor preset: disabled)
   Active: active (running) since Mon 2021-03-15 07:34:25 EDT; 9s ago
 Main PID: 4047 (mysqld_safe)
   CGroup: /system.slice/mariadb.service
           ├─4047 /bin/sh /usr/bin/mysqld_safe --basedir=/usr
           └─4212 /usr/libexec/mysqld --basedir=/usr --datadir=/var/lib/mysql --plugin-dir=/usr/lib64/mysql/plugin --log-err...

Mar 15 07:34:22 lnmp mariadb-prepare-db-dir[3964]: MySQL manual for more instructions.
Mar 15 07:34:22 lnmp mariadb-prepare-db-dir[3964]: Please report any problems at http://mariadb.org/jira
Mar 15 07:34:22 lnmp mariadb-prepare-db-dir[3964]: The latest information about MariaDB is available at http://mariadb.org/.
Mar 15 07:34:22 lnmp mariadb-prepare-db-dir[3964]: You can find additional information about the MySQL part at:
Mar 15 07:34:22 lnmp mariadb-prepare-db-dir[3964]: http://dev.mysql.com
Mar 15 07:34:22 lnmp mariadb-prepare-db-dir[3964]: Consider joining MariaDB's strong and vibrant community:
Mar 15 07:34:22 lnmp mariadb-prepare-db-dir[3964]: https://mariadb.org/get-involved/
Mar 15 07:34:23 lnmp mysqld_safe[4047]: 210315 07:34:23 mysqld_safe Logging to '/var/log/mariadb/mariadb.log'.
Mar 15 07:34:23 lnmp mysqld_safe[4047]: 210315 07:34:23 mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql
Mar 15 07:34:25 lnmp systemd[1]: Started MariaDB database server.

3. 修改密码

$ mysqladmin -uroot password Com.123456
$ mysql -uroot -pCom.123456
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 3
Server version: 5.5.68-MariaDB MariaDB Server

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

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

MariaDB [(none)]> 

4. 创建数据库用户

MariaDB [(none)]> create user "dbadmin"@"localhost" identified by "Com.123456";
Query OK, 0 rows affected (0.00 sec)

MariaDB [(none)]> grant all on *.* to "dbadmin"@"localhost";
Query OK, 0 rows affected (0.00 sec)

MariaDB [(none)]> create user "dbadmin"@"%" identified by "Com.123456";
Query OK, 0 rows affected (0.01 sec)

MariaDB [(none)]> grant all on *.* to "dbadmin"@"%";
Query OK, 0 rows affected (0.00 sec)

四、PHP环境

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

2. 安装PHP7

$ yum install php72w php72w-cli php72w-common php72w-gd php72w-ldap php72w-mbstring php72w-mcrypt php72w-mysql php72w-pdo -y

3. 安装php-fpm

$ yum install php72w-fpm php72w-opcache -y

4. php-fpm服务

$ systemctl start php-fpm.service 
$ 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.
$ 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 Mon 2021-03-15 08:41:18 EDT; 13s ago
 Main PID: 2396 (php-fpm)
   Status: "Processes active: 0, idle: 5, Requests: 0, slow: 0, Traffic: 0req/sec"
   CGroup: /system.slice/php-fpm.service
           ├─2396 php-fpm: master process (/etc/php-fpm.conf)
           ├─2398 php-fpm: pool www
           ├─2399 php-fpm: pool www
           ├─2400 php-fpm: pool www
           ├─2401 php-fpm: pool www
           └─2402 php-fpm: pool www

Mar 15 08:41:18 lnmp systemd[1]: Starting The PHP FastCGI Process Manager...
Mar 15 08:41:18 lnmp systemd[1]: Started The PHP FastCGI Process Manager.

5. php-fpm配置文件

$ vim /etc/php-fpm.d/www.conf
[www]
user = nginx
group = nginx

6. nginx配置文件

$ vim /etc/nginx/conf.d/default.conf
    location / {
        root   /opt/nginx/html;
        index  index.php index.html index.htm;
    }
    # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
    #
    location ~ \.php$ {
        root           /opt/nginx/html;
        fastcgi_pass   127.0.0.1:9000;
        fastcgi_index  index.php;
        fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
        include        fastcgi_params;
        fastcgi_cache TEST;
        fastcgi_cache_valid 200 302 1h;
        fastcgi_cache_valid 301 1d;
        fastcgi_cache_valid any 1m;
    }
    
# 重启服务
$ systemctl restart nginx

五、测试

1. 测试LNMP环境

$ vim /usr/share/nginx/html/index.php
<?php
phpinfo();
?>

2. 数据库测试

$ vim /usr/share/nginx/html/dbtest.php
<?PHP
    $conn=mysqli_connect("localhost","dbadmin","Com.123456");
    if($conn){
        echo"ok";
    }else{
        echo"error";
    }
?>

$ curl http://192.168.119.136/dbtest.php
ok⏎             

六、安装phpMyAdmin

# 下载源码包
https://files.phpmyadmin.net/phpMyAdmin/5.1.0/phpMyAdmin-5.1.0-all-languages.tar.gz

# 解压
$ tar -zxvf phpMyAdmin-5.1.0-all-languages.tar.gz -C /usr/share/nginx/html/

# 使用前配置
$ cd /usr/share/nginx/html/
$ mv phpMyAdmin-5.1.0-all-languages/ phpmyadmin
$ cd phpmyadmin/
$ cp config.sample.inc.php config.inc.php
$ vim config.inc.php 
	cfg['blowfish_secret'] = 'dbadmin'; /* YOU MUST FILL IN THIS FOR COOKIE AUTH! */

七、部署Discuz开源论坛

1. 下载文件及设置

# 下载
$ wget -c https://gitee.com/Discuz/DiscuzX/attach_files/591819/download

# 解压
$ cd /usr/share/nginx/html/
$ mkdir discuz
$ unzip download -d /usr/share/nginx/html/discuz/
$ chown -R nginx /usr/share/nginx/html/discuz/

2. 创建Discuz数据库

# mysql -uroot -pCom.123456
MariaDB [(none)]> create database discuz;
Query OK, 1 row affected (0.00 sec)

MariaDB [(none)]> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| discuz             |
| mysql              |
| performance_schema |
| test               |
+--------------------+
5 rows in set (0.00 sec)

3. 安装

# 访问网站,根据提示安装
$ http://192.168.119.136/discuz/upload/install/

4. 测试

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值