说明
有一天,心血来潮,又购买了华为云三年的服务,唉!刚开始装了WindowsServer,后来发现太占空间了,后又改了Linux。不过毕竟对Linux接触的比较少,光是环境布设就踩了很多坑,官方文档也有不少要改的,所以还是记录一下吧。
当然,开始前要装好Centos系统,并且设置好安全组,主要是开放80、443、22等端口,可以一键开通。
1.安装Nginx
a.登录云耀云服务器。
b.执行以下命令,下载对应当前系统版本的Nginx包。
wget http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm
c.执行以下命令,建立Nginx的yum仓库。
rpm -ivh nginx-release-centos-7-0.el7.ngx.noarch.rpm
d.执行以下命令,安装Nginx。
yum -y install nginx
e.执行以下命令,启动Nginx并设置开机启动。
systemctl start nginx
systemctl enable nginx
f.查看启动状态。
systemctl status nginx.service
g.使用浏览器访问 “http://服务器IP地址”,显示如下页面,说明Nginx安装成功
2.安装MySQL
a.依次执行以下命令,安装MySQL。
wget -i -c http://dev.mysql.com/get/mysql57-community-release-el7-10.noarch.rpm
yum -y install mysql57-community-release-el7-10.noarch.rpm
yum -y install mysql-community-server
b.依次执行以下命令,启动MySQL服务并设置开机自启动。
systemctl start mysqld
systemctl enable mysqld
c.查看MySQL运行状态。
systemctl status mysqld.service
[root@ecs-adc3 ~]# systemctl status mysqld.service
● mysqld.service - MySQL Server
Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled)
Active: active (running) since Mon 2021-08-16 19:33:40 CST; 36s ago
Docs: man:mysqld(8)
http://dev.mysql.com/doc/refman/en/using-systemd.html
Main PID: 7916 (mysqld)
CGroup: /system.slice/mysqld.service
└─7916 /usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid
Aug 16 19:33:35 ecs-adc3 systemd[1]: Starting MySQL Server...
Aug 16 19:33:40 ecs-adc3 systemd[1]: Started MySQL Server.
d.执行以下命令,获取安装MySQL时自动设置的root用户密码。
grep ‘temporary password’ /var/log/mysqld.log
回显如下类似信息……
2021-08-16T11:33:37.790533Z 1 [Note] A temporary password is generated for root@localhost: ;8nPd29lhs,k
e.执行以下命令,并按照回显提示信息进行操作,加固MySQL。
mysql_secure_installation
Securing the MySQL server deployment.
Enter password for user root: #输入上一步骤中获取的安装MySQL时自动设置的root用户密码
The existing password for the user account root has expired. Please set a new password.
New password: #设置新的root用户密码
Re-enter new password: #再次输入密码
The 'validate_password' plugin is installed on the server.
The subsequent steps will run with the existing configuration of the plugin.
Using existing password for root.
Estimated strength of the password: 100
Change the password for root ? ((Press y|Y for Yes, any other key for No) : N #是否更改root用户密码,输入N
... skipping.
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.
Remove anonymous users? (Press y|Y for Yes, any other key for No) : Y #是否删除匿名用户,输入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.
Disallow root login remotely? (Press y|Y for Yes, any other key for No) : Y #禁止root远程登录,输入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.
Remove test database and access to it? (Press y|Y for Yes, any other key for No) : Y #是否删除test库和对它的访问权限,输入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.
Reload privilege tables now? (Press y|Y for Yes, any other key for No) : Y #是否重新加载授权表,输入Y
Success.
All done!
3.安装PHP
a.依次执行以下命令,安装PHP 7和一些所需的PHP扩展。(目前PHP最新版本为7.2)
rpm -Uvh https://mirror.webtatic.com/yum/el7/epel-release.rpm
rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm
yum -y install php72w-tidy php72w-common php72w-devel php72w-pdo php72w-mysql php72w-gd php72w-ldap php72w-mbstring php72w-mcrypt php72w-fpm
b.执行以下命令,启动PHP服务并设置开机自启动。
systemctl start php-fpm
systemctl enable php-fpm
c.修改Nginx配置文件以支持PHP。
(1)执行以下命令打开配置文件/etc/nginx/nginx.conf。
vim /etc/nginx/nginx.conf
(2)修改打开的“nginx.conf”文件。
找到server段落,修改或添加下列配置信息。
server {
listen 80;
listen [::]:80;
server_name _;
root /usr/share/nginx/html;
# Load configuration files for the default server block.
include /etc/nginx/default.d/*.conf;
location / {
root /usr/share/nginx/html;
index index.php index.html index.htm; }
location ~ \.php$ {
root html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /usr/share/nginx/html$fastcgi_script_name;
include fastcgi_params;
}
error_page 404 /404.html;
location = /404.html {
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
}
}
d.执行以下命令,重新载入nginx的配置文件。
service nginx reload
4.创建数据库。
a.执行以下命令,并按照提示信息输入MySQL的root用户,登录到MySQL命令行。
mysql -u root -p
b.执行以下命令,创建一个新的数据库。
CREATE DATABASE wordpress;
其中,“wordpress”为数据库名,可以自行设置。
c.执行以下命令,为数据库创建用户并为用户分配数据库的完全访问权限。
GRANT ALL ON wordpress.* TO wordpressuser@localhost IDENTIFIED BY ‘BLOck@123’;
其中,“wordpressuser”为数据库用户名,“BLOck@123”为对应的帐户密码,可以自行设置。
d.执行以下命令,退出MySQL命令行。
exit
5.安装WordPress。
a.请自行获取WordPress软件包并上传至/usr/share/nginx/html目录。
后续操作软件包以“wordpress-4.9.8.tar.gz”为例。
b.执行以下命令,解压缩软件包。
tar -xvf wordpress-4.9.8.tar.gz
解压后生成一个“wordpress”的文件夹。
c.执行以下命令,设置解压后的文件权限。
chmod -R 777 wordpress
d.浏览器访问“http://服务器IP地址/wordpress”进入安装向导。
可以开始安装WordPress了!