本文共 11209 字,大约阅读时间需要 37 分钟。
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
php版本7.31 mysql版本5.7.21 密码:ruh5Discuz论坛版本3.3 密码:2olg1、安装环境包
[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地址访问
本文依旧使用解压版的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 = 3306socket = /tmp/mysql.sock[mysqld]character-set-server = utf8mb4skip_name_resolve = 1user = mysqlport = 3306socket = /tmp/mysql.sockbasedir = /opt/mysql/datadir = /opt/mysql/datalog-error = /opt/mysql/data/log-error.logpid-file = /opt/mysql/data/mysql.pidinnodb_data_home_dir = /opt/mysql/dataslow-query-log-file=/opt/mysql/data/slow.logrelay-log-index = /opt/mysql/data/relaylogrelay-log-info-file = /opt/mysql/data/relaylogrelay-log = /opt/mysql/data/relaylogopen_files_limit = 10240table_open_cache = 2048back_log = 300max_connections = 10000max_connect_errors = 20explicit_defaults_for_timestamp = 1max_allowed_packet = 64Mthread_cache_size = 300query_cache_size = 256Mquery_cache_limit = 2Mquery_cache_min_res_unit = 2kdefault-storage-engine = InnoDBthread_stack = 512Ktransaction_isolation = READ-COMMITTEDtmp_table_size = 256Mmax_heap_table_size = 256Mkey_buffer_size = 2Gsort_buffer_size = 2Mjoin_buffer_size = 6Mread_buffer_size = 4Mread_rnd_buffer_size = 16Mbulk_insert_buffer_size = 64Mmyisam_sort_buffer_size = 128Mmyisam_max_sort_file_size = 15Gmyisam_repair_threads = 1interactive_timeout = 1800wait_timeout = 28800innodb_data_file_path = ibdata1:200M;ibdata2:200M;ibdata3:200M:autoextendinnodb_buffer_pool_size = 2Ginnodb_thread_concurrency = 0innodb_flush_log_at_trx_commit = 2innodb_log_buffer_size = 16Minnodb_log_file_size = 512Minnodb_log_files_in_group = 3innodb_max_dirty_pages_pct = 90innodb_lock_wait_timeout = 120innodb_purge_threads = 0slow_query_log = 1long_query_time = 3replicate-ignore-db = mysqlreplicate-ignore-db = testreplicate-ignore-db = information_schema#slave-skip-errors = 1032,1062,1026,1114,1146,1048,1396server-id = 1sql_mode=STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION[mysqldump]quickmax_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
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 distributiontar -zxvf libzip-1.2.0.tar.gzcd libzip-1.2.0./configuremake && 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 #用户phpgroup = php #组phppm.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
178591786017861178621786317864178651786617867.........查看端口:9000[root@localhost etc]# netstat -ntap | grep 9000tcp 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<?phpphpinfo();?>12、重启nginx,网页中访问
[root@localhost html]# nginx -s reload网页中输入192.168.70.133/index.php需要有如下mysql扩展模块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-MYSQL Success!!";else echo "PHP-link-MYSQL Fail!!";?>
◆刷新刚刚的页面,显示PHP-link-MYSQL Success!!即可以连接数据库
四、安装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[root@localhost upload]# vim /var/www/upload/source/class/class_core.php
再次刷新页面就好了,不然admin用户无法登陆哦
转载于:https://blog.51cto.com/13760226/2346027