LNMP搭建多个虚拟主机(wordpress+discuz+dedecms)

LNMP搭建wordpress+discuz+dedecms

一、搭建wordpress

1.1 配置PHP+MYSQL 详细的安装PHP+MYSQL参照此站点

1.2 下载编译nginx

cd /usr/local/src

wget http://nginx.org/download/nginx-1.12.1.tar.gz  //下载地址会随时更新,建议直接到官网下载

tar zxf nginx-1.12.1.tar.gz

./configure --prefix=/usr/local/nginx

make &&  make install

echo $?

1.3 制作启动脚本

vim /etc/init.d/nginx

拷贝如下内容:

#!/bin/bash
# chkconfig: - 30 21
# description: http service.
# Source Function Library
. /etc/init.d/functions
# Nginx Settings
NGINX_SBIN="/usr/local/nginx/sbin/nginx"
NGINX_CONF="/usr/local/nginx/conf/nginx.conf"
NGINX_PID="/usr/local/nginx/logs/nginx.pid"
RETVAL=0
prog="Nginx"
start() 
{
    echo -n $"Starting $prog: "
    mkdir -p /dev/shm/nginx_temp
    daemon $NGINX_SBIN -c $NGINX_CONF
    RETVAL=$?
    echo
    return $RETVAL
}
stop() 
{
    echo -n $"Stopping $prog: "
    killproc -p $NGINX_PID $NGINX_SBIN -TERM
    rm -rf /dev/shm/nginx_temp
    RETVAL=$?
    echo
    return $RETVAL
}
reload()
{
    echo -n $"Reloading $prog: "
    killproc -p $NGINX_PID $NGINX_SBIN -HUP
    RETVAL=$?
    echo
    return $RETVAL
}
restart()
{
    stop
    start
}
configtest()
{
    $NGINX_SBIN -c $NGINX_CONF -t
    return 0
}
case "$1" in
  start)
        start
        ;;
  stop)
        stop
        ;;
  reload)
        reload
        ;;
  restart)
        restart
        ;;
  configtest)
        configtest
        ;;
  *)
        echo $"Usage: $0 {start|stop|reload|restart|configtest}"
        RETVAL=1
esac
exit $RETVAL

1.4 更改权限

chmod 755 /etc/init.d/nginx

1.5 配置开机启动

chkconfig --add nginx

chkconfig nginx on

1.6 编辑配置文件

cd /usr/local/nginx/conf/

mv nginx.conf nginx.conf.bak    //不使用系统自带的配置模板,把自带的备份下

vim nginx.conf
//拷贝如下配置文件:

user nobody nobody;
worker_processes 2;
error_log /usr/local/nginx/logs/nginx_error.log crit;
pid /usr/local/nginx/logs/nginx.pid;
worker_rlimit_nofile 51200;
events
{
    use epoll;
    worker_connections 6000;
}
http
{
    include mime.types;
    default_type application/octet-stream;
    server_names_hash_bucket_size 3526;
    server_names_hash_max_size 4096;
    log_format combined_realip '$remote_addr $http_x_forwarded_for [$time_local]'
    ' $host "$request_uri" $status'
    ' "$http_referer" "$http_user_agent"';
    sendfile on;
    tcp_nopush on;
    keepalive_timeout 30;
    client_header_timeout 3m;
    client_body_timeout 3m;
    send_timeout 3m;
    connection_pool_size 256;
    client_header_buffer_size 1k;
    large_client_header_buffers 8 4k;
    request_pool_size 4k;
    output_buffers 4 32k;
    postpone_output 1460;
    client_max_body_size 10m;
    client_body_buffer_size 256k;
    client_body_temp_path /usr/local/nginx/client_body_temp;
    proxy_temp_path /usr/local/nginx/proxy_temp;
    fastcgi_temp_path /usr/local/nginx/fastcgi_temp;
    fastcgi_intercept_errors on;
    tcp_nodelay on;
    gzip on;
    gzip_min_length 1k;
    gzip_buffers 4 8k;
    gzip_comp_level 5;
    gzip_http_version 1.1;
    gzip_types text/plain application/x-javascript text/css text/htm 
    application/xml;
    server
    {
        listen 80;
        server_name localhost;
        index index.html index.htm index.php;
        root /usr/local/nginx/html;
        location ~ \.php$ 
        {
            include fastcgi_params;
            fastcgi_pass unix:/tmp/php-fcgi.sock;
            fastcgi_index index.php;
            fastcgi_param SCRIPT_FILENAME /usr/local/nginx/html$fastcgi_script_name;
        }    
    }
}

1.7 启动nginx服务

/usr/local/nginx/sbin/nginx -t

/etc/init.d/nginx start

curl localhost  //本地测试 nginx

1.8 Nginx默认主机

编辑配置文件:

vim /usr/local/nginx/conf/nginx.conf

events
{
    use epoll;
    worker_connections 6000;
}
http
{
    include mime.types;
    default_type application/octet-stream;
    server_names_hash_bucket_size 3526;
    server_names_hash_max_size 4096;
    log_format combined_realip '$remote_addr $http_x_forwarded_for [$time_local]'
    ' $host "$request_uri" $status'
    ' "$http_referer" "$http_user_agent"';
    sendfile on;
    tcp_nopush on;
    keepalive_timeout 30;
    client_header_timeout 3m;
    client_body_timeout 3m;
    send_timeout 3m;
    connection_pool_size 256;
    client_header_buffer_size 1k;
    large_client_header_buffers 8 4k;
    request_pool_size 4k;
    output_buffers 4 32k;
    postpone_output 1460;
    client_max_body_size 10m;
    client_body_buffer_size 256k;
    client_body_temp_path /usr/local/nginx/client_body_temp;
    proxy_temp_path /usr/local/nginx/proxy_temp;
    fastcgi_temp_path /usr/local/nginx/fastcgi_temp;
    fastcgi_intercept_errors on;
    tcp_nodelay on;
    gzip on;
    gzip_min_length 1k;
    gzip_buffers 4 8k;
    gzip_comp_level 5;
    gzip_http_version 1.1;
    gzip_types text/plain application/x-javascript text/css text/htm
    application/xml;
    include vhost/*.conf;
}

1.9 创建虚拟server

cd /usr/local/nginx/conf

mkdir vhost

cd vhost/

vim zhdy01.com.conf
//增加如下配置:

server
{
    listen 80 default_server;  
    server_name haha.com;
    index index.html index.htm index.php;
    root /data/wwwroot/www.zhdy01.com;
}

1.10 创建测试页面

vim zhdy01.com.conf
完整目录为:牢记
(/usr/local/nginx/conf/vhost/zhdy01.com.conf
)

mkdir -p /data/wwwroot/www.zhdy01.com

cd /data/wwwroot/www.zhdy01.com

vim index.html

1.11 重载并测试

/usr/local/nginx/sbin/nginx -t

/usr/local/nginx/sbin/nginx -s reload

1.12 添加PHP解析

在我们没有添加PHP文件解析前,访问一个PHP文件会直接全部输出:

在配置文件中(zhdy01.com.conf)添加如下:

server
{
    listen 80 default_server;
    server_name www.zhdy01.com;
    index index.html index.htm index.php;
    root /data/wwwroot/www.zhdy01.com;

location ~ \.php$
      {
        include fastcgi_params;
        fastcgi_pass unix:/tmp/zhdy01.sock;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME /data/wwwroot/www.zhdy01.com$fastcgi_script_name;
      }

}

测试+重载 (-t && -s reload)

1.13 配置php-fpm

vim /usr/local/php-fpm/etc/php-fpm.conf 添加如下配置:

[global]
pid = /usr/local/php-fpm/var/run/php-fpm.pid
error_log = /usr/local/php-fpm/var/log/php-fpm.log
[www]
listen = /tmp/zhdy01.sock
listen.mode = 666
user = php-fpm
group = php-fpm
pm = dynamic
pm.max_children = 50
pm.start_servers = 10
pm.min_spare_servers = 5
pm.max_spare_servers = 15
pm.max_requests = 50
rlimit_files = 1024

1.14 设置本地hosts 我这是本地是,所以必须要添加hosts

1.15 上传wordpress文档到server,上传的具体位置就是咱们刚刚创建的:

/data/wwwroot/www.zhdy01.com

[[email protected]03 www.zhdy01.com]# ls
index.php    readme.html      wp-admin            wp-comments-post.php  wp-config-sample.php  wp-cron.php  wp-links-opml.php  wp-login.php  wp-settings.php  wp-trackback.php
license.txt  wp-activate.php  wp-blog-header.php  wp-config.php         wp-content            wp-includes  wp-load.php        wp-mail.php   wp-signup.php    xmlrpc.php

注意:一定要把wordpress下的目录+文件上传到这儿

1.16 关闭firewalld或者添加80端口

systemctl disable firewalld

systemctl stop firewalld

iptables -I INPUT -p tcp --dport 80 -j ACCEPT

1.17 进入下一步,出现如下信息。 进入我们的虚拟机,输入: (首次进入数据库)

/usr/local/mysql/bin/mysql -uroot

设置mysql用户root的密码为:
SET password for 'root'@'localhost'=password('zhangduanya');

create database zhdy01; //创建一个数据库为zhdy01

grant all on zhdy01.* to 'zhdy01'@'127.0.0.1' identified by 'zhangduanya';
针对zhdy01这个数据库表授权,授权zhdy01用户且密码为zhangduanya

quit   //退出

再次测试:

/usr/local/mysql/bin/mysql -uzhdy01 -pzhangduanya -h127.0.0.1 //指定用户名haha+密码+主机再次测试登录。

1.18 验证wordpress

出错:

抱歉,我不能写入wp-config.php文件。

您可以手工创建wp-config.php文件并将以下信息贴入其中。

然后我们手动把下面的配置文件写入到wp-config.php中。

vim wp-config.php

1.19 填写信息后,大功告成!


二、安装discuz

2.1 配置vhost

cd /usr/local/nginx/conf/vhost/

vim zhdy02.com.conf

添加如下配置:

server
{
    listen 80;  
    server_name www.zhdy02.com;
    index index.html index.htm index.php;
    root /data/wwwroot/www.zhdy02.com;

##add php jiexi
location ~ \.php$
      {
        include fastcgi_params;
        fastcgi_pass unix:/tmp/zhdy02.sock;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME /data/wwwroot/www.zhdy02.com$fastcgi_script_name;
      }
}

2.2 配置php-fpm

vim /usr/local/php-fpm/etc/php-fpm.conf

添加如下配置:

[global]
pid = /usr/local/php-fpm/var/run/php-fpm.pid
error_log = /usr/local/php-fpm/var/log/php-fpm.log
[www]
listen = /tmp/php-fcgi.sock
listen.mode = 666
user = php-fpm
group = php-fpm
pm = dynamic
pm.max_children = 50
pm.start_servers = 10
pm.min_spare_servers = 5
pm.max_spare_servers = 15
pm.max_requests = 50
rlimit_files = 1024

[zhdy02]
listen = /tmp/zhdy02.sock
listen.mode = 666
user = php-fpm
group = php-fpm
pm = dynamic
pm.max_children = 50
pm.start_servers = 10
pm.min_spare_servers = 5
pm.max_spare_servers = 15
pm.max_requests = 50
rlimit_files = 1024

注意:第一个是我们添加的zhdy01;
zhdy02才是我们配置的第二个。

测试&重载:

/usr/local/php-fpm/sbin/php-fpm -t

/etc/init.d/php-fpm restart

ps aux | grep php-fpm

2.3 下载并移动站点文件+目录到vhost下的www.zhdy02.com

[[email protected] www.zhdy02.com]# ls
admin.php  api.php   config       crossdomain.xml  favicon.ico  group.php  index.php  member.php  plugin.php  robots.txt  source  template   uc_server
api        archiver  connect.php  data             forum.php    home.php   install    misc.php    portal.php  search.php  static  uc_client

2.4 创建discuz数据库

登录mysql:

/usr/local/mysql/bin/mysql -uroot -pzhangduanya -h127.0.0.1

创建discuz

create database zhdy02; //创建一个数据库为zhdy02

grant all on zhdy02.* to 'zhdy02'@'127.0.0.1' identified by 'zhangduanya';
针对zhdy02这个数据库表授权,授权zhdy02用户且密码为zhangduanya

quit   //退出

遇到的问题:

查看错误日志:

[[email protected]03 www.zhdy02.com]# cat /usr/local/nginx/logs/error.log 
2017/08/19 14:21:04 [notice] 6150#0: signal process started
2017/08/19 14:34:45 [notice] 6393#0: signal process started
2017/08/19 15:53:35 [emerg] 7711#0: a duplicate default server for 0.0.0.0:80 in /usr/local/nginx/conf/vhost/zhdy02.com.conf:3
2017/08/19 15:54:04 [emerg] 7738#0: a duplicate default server for 0.0.0.0:80 in /usr/local/nginx/conf/vhost/zhdy02.com.conf:3
2017/08/19 15:54:52 [emerg] 7793#0: a duplicate default server for 0.0.0.0:80 in /usr/local/nginx/conf/vhost/zhdy02.com.conf:3
2017/08/19 15:55:50 [emerg] 7815#0: a duplicate default server for 0.0.0.0:80 in /usr/local/nginx/conf/vhost/zhdy02.com.conf:3

原因就是:

第二个问题是:

[[email protected]03 www.zhdy02.com]# /usr/local/nginx/sbin/nginx -s reload
nginx: [error] invalid PID number "" in "/usr/local/nginx/logs/nginx.pid"

解决方法是:

/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf

/usr/local/nginx/sbin/nginx -s reload

即可!!!

第三个错误:

解决方法:

chmod -R 777 /data/wwwroot/www.zhdy02.com/

再次刷新安装即可!

三、安装dedecms

3.1 配置vhost

vim /usr/local/nginx/conf/vhost/zhdy03.com.conf

添加如下配置:

server
{
    listen 80;
    server_name www.zhdy03.com;
    index index.html index.htm index.php;
    root /data/wwwroot/www.zhdy03.com;

##add php jiexi
location ~ \.php$
      {
        include fastcgi_params;
        fastcgi_pass unix:/tmp/zhdy03.sock;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME /data/wwwroot/www.zhdy03.com$fastcgi_script_name;
      }
}

3.2 把站点程序全部上传到www.zhdy03.com

[[email protected]03 DedeCMS-V5.7-GBK-SP2-Full]# cp -r uploads/* /data/wwwroot/www.zhdy03.com/

[[email protected]03 www.zhdy03.com]# ls
a  data  dede  docs  favicon.ico  images  include  index.php  install  m  member  plus  robots.txt  special  tags.php  templets  uploads

3.3 配置php-fpm

[[email protected]03 www.zhdy03.com]# vim /usr/local/php-fpm/etc/php-fpm.conf

[global]
pid = /usr/local/php-fpm/var/run/php-fpm.pid
error_log = /usr/local/php-fpm/var/log/php-fpm.log
[www]
listen = /tmp/php-fcgi.sock
listen.mode = 666
user = php-fpm
group = php-fpm
pm = dynamic
pm.max_children = 50
pm.start_servers = 10
pm.min_spare_servers = 5
pm.max_spare_servers = 15
pm.max_requests = 50
rlimit_files = 1024

[zhdy02]
listen = /tmp/zhdy02.sock
listen.mode = 666
user = php-fpm
group = php-fpm
pm = dynamic
pm.max_children = 50
pm.start_servers = 10
pm.min_spare_servers = 5
pm.max_spare_servers = 15
pm.max_requests = 50
rlimit_files = 1024

[zhdy03]
listen = /tmp/zhdy03.sock
listen.mode = 666
user = php-fpm
group = php-fpm
pm = dynamic
pm.max_children = 50
pm.start_servers = 10
pm.min_spare_servers = 5
pm.max_spare_servers = 15
pm.max_requests = 50
rlimit_files = 1024

3.4 测试&&重载

测试重载ngix:

[[email protected] www.zhdy03.com]# /usr/local/nginx/sbin/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

[[email protected] www.zhdy03.com]# /usr/local/nginx/sbin/nginx -s reload

测试重载php-fpm:

[[email protected]03 www.zhdy03.com]# /usr/local/php-fpm/sbin/php-fpm -t
[19-Aug-2017 17:25:52] NOTICE: configuration file /usr/local/php-fpm/etc/php-fpm.conf test is successful

[[email protected]03 www.zhdy03.com]# /etc/init.d/php-fpm reload
Reload service php-fpm  done

3.5 创建dedecms数据库

登录mysql:

/usr/local/mysql/bin/mysql -uroot -pzhangduanya -h127.0.0.1

创建dedecms

create database zhdy03; //创建一个数据库为zhdy03

grant all on zhdy03.* to 'zhdy03'@'127.0.0.1' identified by 'zhangduanya';
针对zhdy03这个数据库表授权,授权zhdy03用户且密码为zhangduanya

quit   //退出

遇到的错误

解决方法:(给权限呗)

chmod -R  777 /data/wwwroot/www.zhdy03.com/

第二个错误:

解决方法:

解决方法很简单,在填写数据库信息的步骤中,我只要把默认的数据库名称dedecmsXXX修改为我们自己的数据库名就可以解决了。(当我们输入自己的数据库名会提示将覆盖原有数据,我们一般的mysql数据库的数据库用户名和数据库名是一样的)


本文参与腾讯云自媒体分享计划,欢迎正在阅读的你也加入,一起分享。

发表于

我来说两句

0 条评论
登录 后参与评论

相关文章

来自专栏Java帮帮-微信公众号-技术文章全总结

Centos6.5安装配置nginx

出现如下代码: nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is...

1123
来自专栏linux运维学习

linux学习第四十四篇:Nginx安装,Nginx默认虚拟主机,Nginx域名重定向

Nginx安装 进入存放源码包的目录: cd /usr/local/src 下载源码包: wget http://nginx.org/download/...

3376
来自专栏云计算教程系列

如何使用Python-GnuPG和Python 3验证代码和加密数据

GnuPG包提供用于生成和存储加密密钥的完整解决方案。它还允许您加密和签名数据和通信。

7078
来自专栏安恒信息

安全漏洞公告

1 Apache HTTP Server多个拒绝服务漏洞 Apache HTTP Server多个拒绝服务漏洞发布时间:2014-03-20漏洞编号:BUG...

3656
来自专栏Laoqi's Linux运维专列

安装配置Nginx-01

一、下载配置安装Nginx 1.1 前言: 进入官网下载nginx安装包,截止到目前最新版为nginx1.12.1,本站使用的nginx版本为1.12也属于新版...

39810
来自专栏Android相关

Gradle解决多lib冲突

在引入第三方jar包的时候,可能会遇到很多库的冲突,例如均使用了OkHttp,RxJava等等,在打包的时候就会遇到Class多个定义的问题。而目前Androi...

2572
来自专栏緣來來來

申请Let's Encrypt通配符证书

Let's Encrypt支持通配符证书了,也就是说你只需要为你的网站申请*.example.com这样一个证书,所有的子域名都可以支持,下面介绍下申请方法:

5552
来自专栏北京马哥教育

批量管理自动化运维100台小规模服务器

---- 目录 1.脚本背景介绍 2.脚本技术需求分析 2.1 SSH免登陆认证 2.2 Expect实现key分发 2.2 PSSH家族命...

2.2K15
来自专栏张戈的专栏

Linux系统编译安装Redis以及主从复制配置小记

Redis 的安装配置很简单,而且很早之前就装过 Redis,可这几天再次安装时居然又遗忘了一些细节,看来好记性不如烂笔头,还是在博客记录一下比较好,至少不用总...

2833
来自专栏云计算教程系列

如何在Ubuntu 18.04上为用户目录设置vsftpd

FTP是文件传输协议的缩写,是一种曾经广泛用于在客户端和服务器之间移动文件的网络协议。它已被更快,更安全,更方便的文件传输方式所取代。许多普通网民希望通过htt...

1240

扫码关注云+社区

领取腾讯云代金券