CVM部署WordPress

登录 CVM

  1. 执行以下命令,赋予私钥文件仅本人可读权限。
chmod 400 <下载的与云服务器关联的私钥的绝对路径>
  1. 执行下边命令登录
ssh -i <下载的与云服务器关联的私钥的绝对路径> <username>@<hostname or IP address>
# 例如腾讯云示例
ssh -i "Mac/Downloads/shawn_qcloud_stable" ubuntu@192.168.11.123
  • username 即为前提条件中获得的默认帐号。
  • hostname or IP address 为您的 Linux 实例公网 IP 或自定义域名。
    > 注意: 我之前的有问题,所以我重装了一遍,但是登录失败,提示如下,只要删掉 ~/.ssh/known_hosts中的对应 IP 的行就好了:
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@ WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED! @
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
IT IS POSSIBLE THAT SOMEONE IS DOING SOMETHING NASTY!
Someone could be eavesdropping on you right now (man-in-the-middle attack)!
It is also possible that a host key has just been changed.
The fingerprint for the ECDSA key sent by the remote host is
SHA256:MUZLNEoaqKSi/h37Fmef87lZ6TPwo2+7B/jJjtiX8UM.
Please contact your system administrator.
Add correct host key in /home/username/.ssh/known_hosts to get rid of this message.
Offending ECDSA key in /home/username/.ssh/known_hosts:1
ECDSA host key for 192.168.11.123 has changed and you have requested strict checking.
Host key verification failed.

手动搭建 LNMP

登录 Linux 实例

安装 Nginx

  1. 安装 nginx
yum install nginx -y
  1. 修改 nginx.conf 配置文件
  1. 添加 wordpress 配置文件,也可以直接添加在第2步的文件里
    vim /etc/nginx/conf.d/wordpress.conf
server {
listen 80;
server_name www.qlm.life;
# 其中 path 是 `wordpress` 的解压路径
root /path/wordpress;

# Load configuration files for the default server block.
include /etc/nginx/default.d/*.conf;

location / {
index index.php index.html;
}

error_page 404 /404.html;
location = /40x.html {
}

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

location ~ .php{
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAMEdocument_root$fastcgi_script_name;
include fastcgi_params;
}
}
  1. 验证 Nginx 配置是否正确
nginx -t
  1. 启动 Nginx
systemctl start nginx
  1. 设置 Nginx 开机启动
systemctl enable nginx
  1. 浏览器中打开 http://云服务器实例的公网 IP 验证 Nginx 是否正常运行
    腾讯云Nginx安装完成结果展示

安装数据库

  1. 查看是否已安装 MySQL
rpm -qa | grep -i mysql

# 如果显示结果不为空,则按照结果进行移除操作
yum -y remove 包名
  1. 下载 MySQLrepo
wget https://mirrors.cloud.tencent.com/mysql/yum/mysql-8.0-community-el7-x86_64/mysql80-community-release-el7-3.noarch.rpm
  1. 安装 MySQL
yum install mysql-server
  1. 权限错误导致的启动不了 1
[root@VM_0_11_centos ~]# mysql -u root
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)
[root@VM_0_11_centos ~]# chown -R mysql:mysql /var/lib/mysql/
  1. 安全设置,顺便设置密码 2
[root@VM_0_11_centos ~]# mysql_secure_installation

Securing the MySQL server deployment.

Connecting to MySQL using a blank password.

VALIDATE PASSWORD COMPONENT can be used to test passwords
and improve security. It checks the strength of password
and allows the users to set only those passwords which are
secure enough. Would you like to setup VALIDATE PASSWORD component?
# 是否修改root密码,y选择是
Press y|Y for Yes, any other key for No: y
Please set the password for root here.
# 新密码
New password:
# 再输一次新密码
Re-enter new password:
By default, a MySQL installation has an anonymous user,
allowing anyone to log into MySQL without having to have
a user account created for them. This is intended only for
testing, and to make the installation go a bit smoother.
You should remove them before moving into a production
environment.
# 是否删除匿名用户,建议选y
Remove anonymous users? (Press y|Y for Yes, any other key for No) : y
Success.

Normally, root should only be allowed to connect from
'localhost'. This ensures that someone cannot guess at
the root password from the network.
# 禁止root从远程登录,建议选y
Disallow root login remotely? (Press y|Y for Yes, any other key for No) : y
Success.

By default, MySQL comes with a database named 'test' that
anyone can access. This is also intended only for testing,
and should be removed before moving into a production
environment.

# 是否删除test数据库,y删除
Remove test database and access to it? (Press y|Y for Yes, any other key for No) : y
- Dropping test database...
Success.

- Removing privileges on test database...
Success.

Reloading the privilege tables will ensure that all changes
made so far will take effect immediately.
# 是否重新加载权限表,y重新加载
Reload privilege tables now? (Press y|Y for Yes, any other key for No) : y
Success.

All done!
  1. 重启 MySQL 服务
systemctl restart mysqld
相关目录或文件
# 配置文件目录
ls -lh /usr/share/mysql

# 数据库文件存放目录
ls -lh/var/lib/mysql

# mysql的启动配置文件
cat /etc/my.cnf
Tips
my.ini //windows操作系统下的配置文件
my.cnf //linux操作系统下的配置文件
mysqld //是后台守护进程,即mysql daemon
mysql //是客户端命令行

安装 PHP

yum module install php:7.2
systemctl start php-fpm
systemctl enable php-fpm

验证环境配置

安装 WordPress

配置数据库

mysql -uroot -p
CREATE DATABASE wordpress;
CREATE USER 'user'@'localhost' IDENTIFIED BY '123456';
GRANT ALL PRIVILEGES ON wordpress.* TO 'user'@'localhost';
FLUSH PRIVILEGES;

下载 WordPress

wget https://cn.wp.xz.cn/latest-zh_CN.tar.gz
tar -zxvf latest-zh_CN.tar.gz

参考


  1. https://cloud.tencent.com/document/product/213/38056 "手动搭建 LNMP 环境(CentOS 7)" ↩︎
  2. https://cloud.tencent.com/document/product/213/8044 "手动搭建 WordPress 个人站点(Linux)" ↩︎

版权声明:
作者:Sunrise
链接:https://www.qlm.life/?p=49
来源:迷迭记录
文章版权归作者所有,未经允许请勿转载。

THE END
分享
二维码
< <上一篇
下一篇>>