个人博客

在服务器里安装多个Wordpress

14 12月
作者:西洪室|分类:技术
一、首先安装运行环境:nginx、php、mysql


1、编译安装nginx:
yum install -y gcc gcc-c++ pcre pcre-devel openssl openssl-devel zlib zlib-devel #安装编译依赖
useradd -s /bin/false -M nginx #创建nginx用户
wget http://nginx.org/download/nginx-1.14.2.tar.gz #下载nginx 1.14.2
tar -zxf nginx-1.14.2.tar.gz && cd nginx-1.14.2 #解压并进入nginx目录

./configure --user=nginx --group=nginx --prefix=/opt/nginx/ --with-compat --with-file-aio --with-threads --with-http_addition_module --with-http_auth_request_module --with-http_dav_module --with-http_flv_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_mp4_module --with-http_random_index_module --with-http_realip_module --with-http_secure_link_module --with-http_slice_module --with-http_ssl_module --with-http_stub_status_module --with-http_sub_module --with-http_v2_module --with-mail --with-mail_ssl_module --with-stream --with-stream_realip_module --with-stream_ssl_module --with-stream_ssl_preread_module --with-cc-opt='-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic -fPIC' --with-ld-opt='-Wl,-z,relro -Wl,-z,now -pie' --with-http_stub_status_module'

make && make install #编译安装


2、修改配置文件:
    在/opt/nginx/conf/nginx.conf的http段中添加一行:
http {
.....
.......
include /opt/nginx/conf/vhosts/*.conf;
}


    创建多主机配置文件目录:
mkdir /opt/nginx/conf/vhosts


    创建单域名配置文件:
vim /opt/nginx/conf/vhosts/example1.conf
vim /opt/nginx/conf/vhosts/example2.conf
....
    配置文件范本(http访问跳转到https):
server {
    listen 443;
    server_name www.example1.com;

    ssl on;
    ssl_certificate /etc/letsencrypt/live/www.example1.com/fullchain.pem; # managed by Certbot
    ssl_certificate_key /etc/letsencrypt/live/www.example1.com/privkey.pem; # managed by Certbot
    ssl_session_timeout 5m;
    ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4;
    ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
    ssl_prefer_server_ciphers on;

    location =/.htaccess{
        return 404;
    }

    location / {
    root /var/www;
    index index.php index.html index.htm;
       try_files $uri $uri/ /index.php?$args;
    }

    location ~ \.php$ {
      root /var/www;
      fastcgi_pass   127.0.0.1:9000;
      fastcgi_index  index.php;
      fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
      include        fastcgi_params;
    }

#     access_log    /var/log/nginx/example1.log  main;
}

server {
    listen 80;
    server_name www.example1.com;
    rewrite ^(.*)$ https://$host$1 permanent;
}


二、安装php:


rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm #安装PHP7的新库
yum install epel-release #安装环境
yum -y install php72w php72w-cli php72w-common php72w-devel php72w-embedded php72w-fpm php72w-gd php72w-mbstring php72w-mysqlnd php72w-opcache php72w-pdo php72w-xml
systemctl enable php-fpm #加载服务
systemctl start php-fpm #启动服务

vim /etc/php-fpm.d/www.conf #编辑配置,将用户名和组改为前面的nginx
user = nginx
group = nginx


三、安装mysql:
    由于vps内存较小,yum安装mysql8无法初始化,故而安装了mysql5.7
yum localinstall http://dev.mysql.com/get/mysql57-community-release-el7-8.noarch.rpm #安装mysql5.7的库
yum install mysql-community-server #安装mysql
systemctl enable mysqld #加载服务
systemctl start mysqld #启动服务
grep 'password' /var/log/mysqld.log #查看mysql的root初始化密码

修改密码:
mysql -uroot -p
Enter password:
mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'MyNewPass1!'; #修改root密码
创建数据库和用户(创建两个数据库和两个授权用户)
mysql> create database wordpress1 default character set utf8; #创建wordpress1的数据库
mysql> GRANT ALL PRIVILEGES ON wordpress1.* TO 'word1'@'127.0.0.1' IDENTIFIED BY 'MyNewPass2!' WITH GRANT OPTION; #创建用户和密码并授权拥有数据库wordpress所有权限
mysql> flush privileges;

mysql> create database wordpress2 default character set utf8; #创建wordpress2的数据库
mysql> GRANT ALL PRIVILEGES ON wordpress2.* TO 'word2'@'127.0.0.1' IDENTIFIED BY 'MyNewPass3!' WITH GRANT OPTION; #创建用户和密码并授权拥有数据库wordpress所有权限
mysql> flush privileges;
mysql> exit


四、安装wordpress:

     

wget https://cn.wordpress.org/wordpress-5.0-zh_CN.tar.gz #下载wordpress
tar zxvf  wordpress-5.0-zh_CN.tar.gz #解压wordpress

mv wordpress1 /var/www #移动到nginx配置的主机目录

chmod 755 -R /var/www/wordpress1 #修改目录权限

chown nginx.nignx /var/www/wordpress1 #修改目录所属用户和组

cd /var/www/wordpress1

mv wp-config-sample.php wp-config.php #创建配置文件

vi wp-config.php #修改文件里的数据库连接地址、名字、账号、密码

按照上面的步骤进行wordpress2的安装

.....


访问域名:www.example1.com和www.example2.com,按照提示填写数据库名和用户密码,正常开启wordpress。




浏览930 评论0
返回
目录
返回
首页
wordpress隐藏后台登陆界面,自动跳转首页或404 Zabbix shell 钉钉报警脚本

发表评论

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。