LNMP+Discuz论坛

LNMP+Discuz论坛

LNMP指的是一个基于CentOS/Debian编写的Nginx、PHP、MySQL、phpMyAdmin、eAccelerator一键安装包。可以在独立主机上轻松的安装LNMP生产环境。
继上篇博客介绍的LAMP的Discuz论坛,本章博客为大家介绍基于LNMP的Discuz论坛的搭建。使用的软件基本上都是最新或者使用比较广泛的,毕竟学最新的知识,挨最毒的打,才会有成长。

环境介绍

系统 IP地址 内存 cpu
Centos 7 192.168.70.133 5G 4核

nginx版本1.8.1 http://nginx.org/download/nginx-1.8.1.tar.gz
php版本7.31 http://am1.php.net/distributions/php-7.3.1.tar.gz
mysql版本5.7.21 https://pan.baidu.com/s/11b_ccrosT0IPdnXhRrU4yQ 密码:ruh5
Discuz论坛版本3.3 https://pan.baidu.com/s/14ZPFy35pnpYpKeePDFoArw 密码:2olg

一、安装nginx

1、安装环境包

[root@localhost opt]# yum -y install gcc gcc-c++ gd-devel autoconf automake zlib zlib-devel openssl openssl-devel pcre*

2、解压软件包编译

[root@localhost opt]# tar zxf nginx-1.8.1.tar.gz
[root@localhost opt]# cd nginx-1.8.1/
./configure \
--prefix=/usr/local/nginx \
--user=nginx \
--group=nginx \
--with-http_ssl_module \
--with-http_gzip_static_module \
--with-http_image_filter_module \
--with-http_stub_status_module

编译注解
--prefix=指向安装目录
--user= 指定程序运行时的非特权用户
--group= 指定程序运行时的非特权用户组
--with-http_ssl_module 支持https请求,需已安装openssl
--with-http_gzip_static_module  在线实时压缩输出数据流
--with-http_image_filter_module 传输JPEG/GIF/PNG 图片的一个过滤器,默认为不启用。gd库要用到
--with-http_stub_status_module  获取nginx自上次启动以来的工作状态

3、安装

[root@localhost nginx-1.8.1]# make && make install

4、优化命令路径

[root@localhost nginx-1.8.1]# ln -s /usr/local/nginx/sbin/nginx /usr/sbin/

5、创建nginx用户,添加一下简单的优化

[root@localhost nginx-1.8.1]# cd /usr/local/nginx/conf/
[root@localhost conf]# useradd -M -s /sbin/nologin nginx
[root@localhost conf]# vim nginx.conf

#以下是我的设置的一些简单的优化,删除了部分注释语句
    user  nginx;
    worker_processes  4;
    worker_rlimit_nofile 65535;

    events {
            worker_connections  2048;
            use epoll;
    }
http {
        include       mime.types;
        default_type  application/octet-stream;

        server_tokens off;
sendfile   on;
tcp_nopush on;
tcp_nodelay on;
server_names_hash_bucket_size 128;
server_names_hash_max_size 512;
keepalive_timeout  65;
client_header_timeout 15s;
client_body_timeout 15s;
send_timeout 60s;

gzip  on;
gzip_buffers  4 64k;
gzip_http_version 1.1;
gzip_comp_level 2;
gzip_min_length 1k;
gzip_vary on;
gzip_types text/plain text/javascript application/x-javascript text/css text/xml application/xml applicatin/xml+rss;

server {
    listen       80;
    server_name  localhost;

   location / {
        root   html;
        index  index.html index.htm;
    }

    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   html;
    }

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

}

}

6、查看语法并启动nginx

[root@localhost conf]# nginx -t
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
[root@localhost conf]# nginx #启动nginx

7、关闭防火墙和selinux,网页中访问

[root@localhost conf]# systemctl stop firewalld.service
[root@localhost conf]# setenforce 0
网页中直接输入IP地址访问

LNMP+Discuz论坛

二、安装mysql

本文依旧使用解压版的mysql5.7.21,文章开头已经为大家提供解压版的下载地址,使用解压版大幅度减少我们使用的时间。

1、解压安装包并更名

[root@localhost opt]# tar zxf mysql-5.7.21-linux-glibc2.12-x86_64.tgz
[root@localhost opt]# mv mysql-5.7.21-linux-glibc2.12-x86_64 mysql

2、修改配置文件

root@localhost opt]# vim /etc/my.cnf #删除原本的内容,添加如下

[client]
port = 3306
socket = /tmp/mysql.sock

[mysqld]

character-set-server = utf8mb4
skip_name_resolve = 1
user = mysql
port = 3306
socket = /tmp/mysql.sock
basedir = /opt/mysql/
datadir = /opt/mysql/data
log-error = /opt/mysql/data/log-error.log
pid-file = /opt/mysql/data/mysql.pid
innodb_data_home_dir = /opt/mysql/data
slow-query-log-file=/opt/mysql/data/slow.log
relay-log-index = /opt/mysql/data/relaylog
relay-log-info-file = /opt/mysql/data/relaylog
relay-log = /opt/mysql/data/relaylog

open_files_limit = 10240
table_open_cache = 2048
back_log = 300
max_connections = 10000
max_connect_errors = 20
explicit_defaults_for_timestamp = 1
max_allowed_packet = 64M
thread_cache_size = 300
query_cache_size = 256M
query_cache_limit = 2M
query_cache_min_res_unit = 2k
default-storage-engine = InnoDB
thread_stack = 512K
transaction_isolation = READ-COMMITTED
tmp_table_size = 256M
max_heap_table_size = 256M
key_buffer_size = 2G
sort_buffer_size = 2M
join_buffer_size = 6M
read_buffer_size = 4M
read_rnd_buffer_size = 16M
bulk_insert_buffer_size = 64M
myisam_sort_buffer_size = 128M
myisam_max_sort_file_size = 15G
myisam_repair_threads = 1
interactive_timeout = 1800
wait_timeout = 28800
innodb_data_file_path = ibdata1:200M;ibdata2:200M;ibdata3:200M:autoextend
innodb_buffer_pool_size = 2G
innodb_thread_concurrency = 0
innodb_flush_log_at_trx_commit = 2
innodb_log_buffer_size = 16M
innodb_log_file_size = 512M
innodb_log_files_in_group = 3
innodb_max_dirty_pages_pct = 90
innodb_lock_wait_timeout = 120
innodb_purge_threads = 0
slow_query_log = 1
long_query_time = 3
replicate-ignore-db = mysql
replicate-ignore-db = test
replicate-ignore-db = information_schema
#slave-skip-errors = 1032,1062,1026,1114,1146,1048,1396
server-id = 1
sql_mode=STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION
[mysqldump]
quick
max_allowed_packet = 64M

3、创建mysql用户并初始化数据库

[root@localhost opt]# adduser -s /sbin/nologin mysql
[root@localhost opt]# /opt/mysql/bin/mysqld --initialize-insecure

4、启动数据库,设置数据库密码

[root@localhost opt]# /opt/mysql/bin/mysqld_safe &
[root@localhost opt]# /opt/mysql/bin/mysqladmin -uroot password '123123'

5、进入数据库查看

[root@localhost opt]# /opt/mysql/bin/mysql -uroot -p123123

LNMP+Discuz论坛

三、安装PHP7

1、安装依赖环境包

yum -y install pcre pcre-devel openssl openssl-devel libicu-devel gcc gcc-c++ autoconf libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel zlib zlib-devel glibc glibc-devel glib2 glib2-devel ncurses ncurses-devel curl curl-devel krb5-devel libidn libidn-devel openldap openldap-devel openldap-servers openldap-client nss_ldap jemalloc-devel cmake boost-devel bison automake libevent libevent-devel gd gd-devel libtool* libmcrypt libmcrypt-devel mcrypt mhash libxslt libxslt-devel readline readline-devel gmp gmp-devel libcurl libcurl-devel openjpeg-devel bzip2 bzip2-devel libxml2 libxml2-devel bzip2 bzip2-devel curl-devel gmp-devel readline-devel

2、解压安装包

[root@localhost opt]# tar zxf php-7.3.1.tar.gz

3、编译

[root@localhost opt]# cd php-7.3.1/
./configure \
--prefix=/usr/local/php7 \
--with-pdo-mysql=/opt/mysql \
--enable-mysqlnd \
--with-pdo-mysql=mysqlnd \
-with-mysqli=mysqlnd \
--with-mysql-sock=/tmp/mysql.sock \
--with-config-file-path=/usr/local/php7 \
--enable-fpm \
--enable-inline-optimization \
--disable-debug \
--disable-rpath \
--enable-shared \
--enable-soap \
--with-libxml-dir \
--with-xmlrpc \
--with-openssl \
--with-mhash \
--with-pcre-regex \
--with-sqlite3 \
--with-zlib \
--enable-bcmath \
--with-iconv \
--with-bz2 \
--enable-calendar \
--with-curl \
--with-cdb \
--enable-dom \
--enable-exif \
--enable-fileinfo \
--enable-filter \
--with-pcre-dir \
--enable-ftp \
--with-gd \
--with-openssl-dir \
--with-jpeg-dir \
--with-png-dir \
--with-zlib-dir \
--with-freetype-dir \
--enable-gd-jis-conv \
--with-gettext \
--with-gmp \
--with-mhash \
--enable-json \
--enable-mbstring \
--enable-mbregex \
--enable-mbregex-backtrack \
--with-onig \
--enable-pdo \
--with-zlib-dir \
--with-pdo-sqlite \
--with-readline \
--enable-session \
--enable-shmop \
--enable-simplexml \
--enable-sockets \
--enable-sysvmsg \
--enable-sysvsem \
--enable-sysvshm \
--enable-wddx \
--with-libxml-dir \
--with-xsl \
--enable-zip \
--with-pear \
--enable-opcache

编译会遇到几个小问题
●configure: error: Please reinstall the libzip distribution
tar -zxvf libzip-1.2.0.tar.gz
cd libzip-1.2.0
./configure
make && make install

●configure: error: off_t undefined; check your library configuration
解决方法
echo '/usr/local/lib64
/usr/local/lib
/usr/lib
/usr/lib64'>>/etc/ld.so.conf&&ldconfig -v

●/usr/local/include/zip.h:59:21: 致命错误:zipconf.h:没有那个文件或目录
cp /usr/local/lib/libzip/include/zipconf.h /usr/local/include/zipconf.h
++++系统不同缺包也不同,总而言之,缺什么装什么~

4、安装

[root@localhost php-7.3.1]# make && make install

5、复制php配置文件到指定目录,并优化命令路径

[root@localhost php-7.3.1]# cp php.ini-development /usr/local/php7/php.ini
[root@localhost opt]# cd /usr/local/php7/etc/
[root@localhost etc]# cp php-fpm.conf.default php-fpm.conf
[root@localhost php-7.3.1]# ln -s /usr/local/php7/bin/ /usr/local/bin/
[root@localhost php-7.3.1]# ln -s /usr/local/php7/sbin/
/usr/local/sbin/

6、创建php用户

useradd -M -s /sbin/nologin php

7、修改conf文件

[root@localhost php-7.3.1]# cd /usr/local/php7/etc/php-fpm.d
[root@localhost php-fpm.d]# cp www.conf.default www.conf
[root@localhost php-fpm.d]# vim www.conf
#修改以下几个参数
user = php #用户php
group = php #组php
pm.max_children = 50 # php-fpm 能启动的子进程的最大数量
pm.start_servers = 20 #动态方式下的起始php-fpm进程数量
pm.min_spare_servers = 5 #动态方式空闲状态下的最小php-fpm进程数量
pm.max_spare_servers = 35 #动态方式空闲状态下的最大php-fpm进程数量。

8、启动php-fpm

[root@localhost etc]# /usr/local/php7/sbin/php-fpm

9、查看php进程

[root@localhost etc]# pgrep php
17859
17860
17861
17862
17863
17864
17865
17866
17867
.........
查看端口:9000
[root@localhost etc]# netstat -ntap | grep 9000
tcp 0 0 127.0.0.1:9000 0.0.0.0:* LISTEN 17859/php-fpm: mast

10、php连接nginx

[root@localhost etc]# cd /usr/local/nginx/conf/
[root@localhost conf]# vim nginx.conf

#添加index.php,识别默认首页
   location / {
                root   html;
                index  index.html index.htm index.php;
        }
#去掉如下注释,这里需要将/scripts改成$document_root,否则nginx返回空白页面
    location ~ \.php$ {
        root           html;
        fastcgi_pass   127.0.0.1:9000;
        fastcgi_index  index.php;
        fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
        include        fastcgi_params;
    }

11、修改默认首页
[root@localhost conf]# cd ../html/
[root@localhost html]# vim index.php
<?php
phpinfo();
?>

12、重启nginx,网页中访问
[root@localhost html]# nginx -s reload
网页中输入192.168.70.133/index.php
LNMP+Discuz论坛
需要有如下mysql扩展模块
LNMP+Discuz论坛
LNMP+Discuz论坛

13、php连接mysql
◆进数据库创建库并授权

/opt/mysql/bin/mysql -uroot -p123123
mysql> create database bbs;
mysql> grant all privileges on bbs.* to 'root'@'192.168.70.%' identified by '123123' with grant option;
mysql> flush privileges;

◆再次修改index.php文件

<?php
$link=mysqli_connect('192.168.70.133','root','123123');
if($link) echo "<h1>PHP-link-MYSQL  Success!!</h1>";
else echo "PHP-link-MYSQL Fail!!";
?>

◆刷新刚刚的页面,显示PHP-link-MYSQL Success!!即可以连接数据库
LNMP+Discuz论坛

四、安装Discuz论坛
1、修改nginx.conf文件,设置我们指定的安装目录
[root@localhost html]# cd /usr/local/nginx/conf/
[root@localhost conf]# vim nginx.conf

#这里将root后面原本的html换成/var/www
        location  ~ \.(gif|jepg|png|bmp|ico)$ {
            root   /var/www;
            index  index.html index.htm index.php;
            expires 1d;
        }
#将$document_root换成/var/www/
        location ~ \.php$ {
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.php;
            fastcgi_param  SCRIPT_FILENAME   /var/www/$fastcgi_script_name;
            include        fastcgi_params;
        }

2、创建指定的目录

[root@localhost conf]# mkdir /var/www

3、解压Discuz项目包,将upload移动到/var/www下

[root@localhost opt]# unzip Discuz_X3.3_SC_UTF8.zip
[root@localhost opt]# mv upload/ /var/www/

4、授权,放大目录权限

[root@localhost opt]# cd /var/www/upload/
[root@localhost upload]# chown -R php config data uc_client/data uc_server/data/
[root@localhost upload]# chmod -R 777 ../upload

5、重启nginx,网页中访问安装
[root@localhost upload]# nginx -s reload
网页中访问192.168.70.133/upload/install
LNMP+Discuz论坛
LNMP+Discuz论坛
LNMP+Discuz论坛
LNMP+Discuz论坛
LNMP+Discuz论坛
LNMP+Discuz论坛
LNMP+Discuz论坛

[root@localhost upload]# vim /var/www/upload/source/class/class_core.php

LNMP+Discuz论坛

再次刷新页面就好了,不然admin用户无法登陆哦

LNMP+Discuz论坛

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章