Ubuntu系统搭建过程目录
- 一、检查环境
- 1.1 检查是否安装Apache
- 1.2 检查是否安装Mysql
- 1.3 检查是否安装PHP
- 二、安装Apache
- 截图
- 三、安装Mysql
- 3.1 安全安装配置
- 3.2 修改权限和密码
- 3.3 重启MySQL服务
- 四、安装PHP
- 4.1 测试
- 截图
- 五、下载并安装wordpress以及配置
- 5.1 下载并解压移动
- 5.2 创建wordpress数据库以及wordpress用户
- 5.3 重启Apache和mysql
Wordpress推荐 PHP 7.4+ 以及 MySQL 版本 8.0+
一、检查环境
1.1 检查是否安装Apache
[root@huaweiyun:~]# systemctl status apache2
/ 或者
[root@huaweiyun:~]# apache2 -v
1.2 检查是否安装Mysql
[root@huaweiyun:~]# mysql --version
/ 或者
[root@huaweiyun:~]#systemctl status mysql
1.3 检查是否安装PHP
[root@huaweiyun:~]# php -v
二、安装Apache
[root@huaweiyun:~]# apt -y install apache2
[root@huaweiyun:~]# apache2 -v
Server version: Apache/2.4.41 (Ubuntu)
Server built: 2024-07-17T18:58:09
截图
三、安装Mysql
[root@huaweiyun:~]# apt -y install mysql-server
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following additional packages will be installed:
libcgi-fast-perl libcgi-pm-perl libencode-locale-perl libevent-core-2.1
libevent-pthreads-2.1-7 libfcgi-perl libhtml-parser-perl libhtml-tagset
libhtml-template-perl libhttp-date-perl libhttp-message-perl libio-html
liblwp-mediatypes-perl libmecab2 libtimedate-perl liburi-perl mecab-ipa
mecab-ipadic-utf8 mecab-utils mysql-client-8.0 mysql-client-core-8.0 my
mysql-server-8.0 mysql-server-core-8.0
Suggested packages:
libdata-dump-perl libipc-sharedcache-perl libwww-perl mailx tinyca
The following NEW packages will be installed:
libcgi-fast-perl libcgi-pm-perl libencode-locale-perl libevent-core-2.1
libevent-pthreads-2.1-7 libfcgi-perl libhtml-parser-perl libhtml-tagset
libhtml-template-perl libhttp-date-perl libhttp-message-perl libio-html
liblwp-mediatypes-perl libmecab2 libtimedate-perl liburi-perl mecab-ipa
mecab-ipadic-utf8 mecab-utils mysql-client-8.0 mysql-client-core-8.0 my
mysql-server mysql-server-8.0 mysql-server-core-8.0
..............................省略....................................
[root@huaweiyun:~]# apt install -y php-mysql
[root@huaweiyun:~]# mysql --version
mysql Ver 8.0.40-0ubuntu0.20.04.1 for Linux on x86_64 ((Ubuntu))
3.1 安全安装配置
[root@huaweiyun:~]# 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? # 是否检查并设置密码的强度 yes or no ,这边建议选yes
Press y|Y for Yes, any other key for No: y
There are three levels of password validation policy:
LOW Length >= 8 # 低长度>= 8
MEDIUM Length >= 8, numeric, mixed case, and special characters # 支持数字、混合大小写和特殊字符
STRONG Length >= 8, numeric, mixed case, special characters and dictionary # 数字,混合大小写,特殊字符和字典文件
file
# 0 1 2 分别代表LOW,MEDIUM ,STRONG
Please enter 0 = LOW, 1 = MEDIUM and 2 = STRONG: 1
# 默认情况下使用auth_socket跳过为root设置的密码作为身份验证。如果您希望使用密码身份验证,可以使用“ALTER_USER”命令。
Skipping password set for root as authentication with auth_socket is used by default.
If you would like to use password authentication instead, this can be done with the "ALTER_USER" command.
See https://dev.mysql.com/doc/refman/8.0/en/alter-user.html#alter-user-password-management for more information.
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
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用户远程登录
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.
# 是否删除测试数据库
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.
# 是否现在重新加载特权表
Reload privilege tables now? (Press y|Y for Yes, any other key for No) : y
Success.
All done!
3.2 修改权限和密码
# 进入mysql
[root@huaweiyun:~]# mysql
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 8.0.40-0ubuntu0.20.04.1 (Ubuntu)
Copyright (c) 2000, 2024, Oracle and/or its affiliates.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
# 选择mysql数据库
mysql> use mysql;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
# 查询MySQL中root用户的用户名、允许登录的主机和认证插件
mysql> SELECT user, host, plugin FROM user WHERE user='root';
+------+-----------+-------------+
| user | host | plugin |
+------+-----------+-------------+
| root | localhost | auth_socket |
+------+-----------+-------------+
1 row in set (0.00 sec)
# 如果plugin列显示为auth_socket,则需要将其更改为mysql_native_password
mysql> UPDATE user SET plugin='mysql_native_password' WHERE User='root';
Query OK, 1 row affected (0.01 sec)
Rows matched: 1 Changed: 1 Warnings: 0
mysql> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.00 sec)
# 再次查询
mysql> SELECT user, host, plugin, authentication_string FROM mysql.user WHERE user='root';
+------+-----------+-----------------------+-----------------------+
| user | host | plugin | authentication_string |
+------+-----------+-----------------------+-----------------------+
| root | localhost | mysql_native_password | |
+------+-----------+-----------------------+-----------------------+
1 row in set (0.00 sec)
# 修改root密码
mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY '你自己的数据库密码‘;
# 刷新权限
mysql> FLUSH PRIVILEGES;
mysql> exit
Bye
3.3 重启MySQL服务
[root@huaweiyun:~]# systemctl restart mysql
四、安装PHP
[root@huaweiyun:~]# apt -y install php
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following additional packages will be installed:
libapache2-mod-php7.4 php-common php7.4 php7.4-cli php7.4-common php7.4-json php7.4-opcache php7.4-readline
Suggested packages:
php-pear
The following NEW packages will be installed:
libapache2-mod-php7.4 php php-common php7.4 php7.4-cli php7.4-common php7.4-json php7.4-opcache php7.4-readline
0 upgraded, 9 newly installed, 0 to remove and 67 not upgraded.
Need to get 4,034 kB of archives.
After this operation, 18.0 MB of additional disk space will be used.
Get:1 http://repo.huaweicloud.com/ubuntu focal/main amd64 php-common all 2:75 [11.9 kB]
..............................省略....................................
[root@huaweiyun:~]# php -v
PHP 7.4.3-4ubuntu2.24 (cli) (built: Sep 30 2024 18:16:20) ( NTS )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies
with Zend OPcache v7.4.3-4ubuntu2.24, Copyright (c), by Zend Technologies
4.1 测试
[root@huaweiyun:~]# cd /var/www/html
[root@huaweiyun:/var/www/html]# ls
index.html
[root@huaweiyun:/var/www/html]# vim info.php
[root@huaweiyun:/var/www/html]# cat info.php
<?
phpinfo();
>
截图
五、下载并安装wordpress以及配置
5.1 下载并解压移动
官网下载 https://cn.wordpress.org/download/releases/
复制链接地址
[root@huaweiyun:~/downloads]# wget https://cn.wordpress.org/wordpress-6.7.1-zh_CN.tar.gz # 下载
--2024-12-07 14:26:41-- https://cn.wordpress.org/wordpress-6.7.1-zh_CN.tar.gz
Resolving cn.wordpress.org (cn.wordpress.org)... 198.143.164.252
Connecting to cn.wordpress.org (cn.wordpress.org)|198.143.164.252|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 33984315 (32M) [application/octet-stream]
Saving to: ‘wordpress-6.7.1-zh_CN.tar.gz’
wordpress-6.7.1-zh_CN.tar.gz 100%[============================================================================>] 32.41M 689KB/s in 78s
2024-12-07 14:28:02 (428 KB/s) - ‘wordpress-6.7.1-zh_CN.tar.gz’ saved [33984315/33984315]
[root@huaweiyun:~/downloads]# ll
total 33196
drwxr-xr-x 2 root root 4096 Dec 7 14:26 ./
drwx------ 6 root root 4096 Dec 7 14:29 ../
-rw-r--r-- 1 root root 33984315 Nov 24 19:00 wordpress-6.7.1-zh_CN.tar.gz
[root@huaweiyun:~/downloads]# tar -zxvf wordpress-6.7.1-zh_CN.tar.gz # 解压
[root@huaweiyun:~/downloads]# ll
total 33200
drwxr-xr-x 3 root root 4096 Dec 7 14:40 ./
drwx------ 6 root root 4096 Dec 7 14:29 ../
drwxr-xr-x 5 1006 1006 4096 Nov 24 19:00 wordpress/
-rw-r--r-- 1 root root 33984315 Nov 24 19:00 wordpress-6.7.1-zh_CN.tar.gz
[root@huaweiyun:~/downloads]# cd wordpress/
[root@huaweiyun:~/downloads/wordpress]# ll
total 244
drwxr-xr-x 5 1006 1006 4096 Nov 24 19:00 ./
drwxr-xr-x 3 root root 4096 Dec 7 14:40 ../
-rw-r--r-- 1 1006 1006 405 Feb 6 2020 index.php
-rw-r--r-- 1 1006 1006 19915 Jan 1 2024 license.txt
-rw-r--r-- 1 1006 1006 7409 Jun 18 19:59 readme.html
-rw-r--r-- 1 1006 1006 7387 Feb 13 2024 wp-activate.php
drwxr-xr-x 9 1006 1006 4096 Nov 24 19:00 wp-admin/
-rw-r--r-- 1 1006 1006 351 Feb 6 2020 wp-blog-header.php
-rw-r--r-- 1 1006 1006 2323 Jun 14 2023 wp-comments-post.php
-rw-r--r-- 1 1006 1006 3336 Oct 15 23:24 wp-config-sample.php
drwxr-xr-x 5 1006 1006 4096 Nov 24 19:00 wp-content/
-rw-r--r-- 1 1006 1006 5617 Aug 3 03:40 wp-cron.php
drwxr-xr-x 30 1006 1006 16384 Nov 24 19:00 wp-includes/
-rw-r--r-- 1 1006 1006 2502 Nov 27 2022 wp-links-opml.php
-rw-r--r-- 1 1006 1006 3937 Mar 11 2024 wp-load.php
-rw-r--r-- 1 1006 1006 51367 Oct 1 03:12 wp-login.php
-rw-r--r-- 1 1006 1006 8543 Sep 19 06:37 wp-mail.php
-rw-r--r-- 1 1006 1006 29032 Oct 1 01:08 wp-settings.php
-rw-r--r-- 1 1006 1006 34385 Jun 20 2023 wp-signup.php
-rw-r--r-- 1 1006 1006 5102 Oct 18 23:56 wp-trackback.php
-rw-r--r-- 1 1006 1006 3246 Mar 2 2024 xmlrpc.php
# 将 wordpress目录下的文件移动到/var/www/html目录下
[root@huaweiyun:~/downloads/wordpress]# mv * /var/www/html/
[root@huaweiyun:~/downloads/wordpress]# ll /var/www/html
total 260
drwxr-xr-x 5 root root 4096 Dec 7 14:51 ./
drwxr-xr-x 3 root root 4096 Dec 3 12:26 ../
-rw-r--r-- 1 root root 10918 Dec 3 12:26 index.html
-rw-r--r-- 1 1006 1006 405 Feb 6 2020 index.php
-rw-r--r-- 1 root root 20 Dec 7 14:29 info.php
-rw-r--r-- 1 1006 1006 19915 Jan 1 2024 license.txt
-rw-r--r-- 1 1006 1006 7409 Jun 18 19:59 readme.html
-rw-r--r-- 1 1006 1006 7387 Feb 13 2024 wp-activate.php
drwxr-xr-x 9 1006 1006 4096 Nov 24 19:00 wp-admin/
-rw-r--r-- 1 1006 1006 351 Feb 6 2020 wp-blog-header.php
-rw-r--r-- 1 1006 1006 2323 Jun 14 2023 wp-comments-post.php
-rw-r--r-- 1 1006 1006 3336 Oct 15 23:24 wp-config-sample.php
drwxr-xr-x 5 1006 1006 4096 Nov 24 19:00 wp-content/
-rw-r--r-- 1 1006 1006 5617 Aug 3 03:40 wp-cron.php
drwxr-xr-x 30 1006 1006 16384 Nov 24 19:00 wp-includes/
-rw-r--r-- 1 1006 1006 2502 Nov 27 2022 wp-links-opml.php
-rw-r--r-- 1 1006 1006 3937 Mar 11 2024 wp-load.php
-rw-r--r-- 1 1006 1006 51367 Oct 1 03:12 wp-login.php
-rw-r--r-- 1 1006 1006 8543 Sep 19 06:37 wp-mail.php
-rw-r--r-- 1 1006 1006 29032 Oct 1 01:08 wp-settings.php
-rw-r--r-- 1 1006 1006 34385 Jun 20 2023 wp-signup.php
-rw-r--r-- 1 1006 1006 5102 Oct 18 23:56 wp-trackback.php
-rw-r--r-- 1 1006 1006 3246 Mar 2 2024 xmlrpc.php
# 将/var/www/html/下面所有者修改为www-data
[root@huaweiyun:/var/www/html]# chown -R www-data.www-data /var/www/html
[root@huaweiyun:/var/www/html]# ll
total 260
drwxr-xr-x 5 www-data www-data 4096 Dec 7 14:51 ./
drwxr-xr-x 3 root root 4096 Dec 3 12:26 ../
-rw-r--r-- 1 www-data www-data 10918 Dec 3 12:26 index.html
-rw-r--r-- 1 www-data www-data 405 Feb 6 2020 index.php
-rw-r--r-- 1 www-data www-data 20 Dec 7 14:29 info.php
-rw-r--r-- 1 www-data www-data 19915 Jan 1 2024 license.txt
-rw-r--r-- 1 www-data www-data 7409 Jun 18 19:59 readme.html
-rw-r--r-- 1 www-data www-data 7387 Feb 13 2024 wp-activate.php
drwxr-xr-x 9 www-data www-data 4096 Nov 24 19:00 wp-admin/
-rw-r--r-- 1 www-data www-data 351 Feb 6 2020 wp-blog-header.php
-rw-r--r-- 1 www-data www-data 2323 Jun 14 2023 wp-comments-post.php
-rw-r--r-- 1 www-data www-data 3336 Oct 15 23:24 wp-config-sample.php
drwxr-xr-x 5 www-data www-data 4096 Nov 24 19:00 wp-content/
-rw-r--r-- 1 www-data www-data 5617 Aug 3 03:40 wp-cron.php
drwxr-xr-x 30 www-data www-data 16384 Nov 24 19:00 wp-includes/
-rw-r--r-- 1 www-data www-data 2502 Nov 27 2022 wp-links-opml.php
-rw-r--r-- 1 www-data www-data 3937 Mar 11 2024 wp-load.php
-rw-r--r-- 1 www-data www-data 51367 Oct 1 03:12 wp-login.php
-rw-r--r-- 1 www-data www-data 8543 Sep 19 06:37 wp-mail.php
-rw-r--r-- 1 www-data www-data 29032 Oct 1 01:08 wp-settings.php
-rw-r--r-- 1 www-data www-data 34385 Jun 20 2023 wp-signup.php
-rw-r--r-- 1 www-data www-data 5102 Oct 18 23:56 wp-trackback.php
-rw-r--r-- 1 www-data www-data 3246 Mar 2 2024 xmlrpc.php
# 赋予文件的执行权限
[root@huaweiyun:/var/www/html]# chmod -R 755 /var/www/html
[root@huaweiyun:/var/www/html]# ll
total 260
drwxr-xr-x 5 www-data www-data 4096 Dec 7 14:51 ./
drwxr-xr-x 3 root root 4096 Dec 3 12:26 ../
-rwxr-xr-x 1 www-data www-data 10918 Dec 3 12:26 index.html*
-rwxr-xr-x 1 www-data www-data 405 Feb 6 2020 index.php*
-rwxr-xr-x 1 www-data www-data 20 Dec 7 14:29 info.php*
-rwxr-xr-x 1 www-data www-data 19915 Jan 1 2024 license.txt*
-rwxr-xr-x 1 www-data www-data 7409 Jun 18 19:59 readme.html*
-rwxr-xr-x 1 www-data www-data 7387 Feb 13 2024 wp-activate.php*
drwxr-xr-x 9 www-data www-data 4096 Nov 24 19:00 wp-admin/
-rwxr-xr-x 1 www-data www-data 351 Feb 6 2020 wp-blog-header.php*
-rwxr-xr-x 1 www-data www-data 2323 Jun 14 2023 wp-comments-post.php*
-rwxr-xr-x 1 www-data www-data 3336 Oct 15 23:24 wp-config-sample.php*
drwxr-xr-x 5 www-data www-data 4096 Nov 24 19:00 wp-content/
-rwxr-xr-x 1 www-data www-data 5617 Aug 3 03:40 wp-cron.php*
drwxr-xr-x 30 www-data www-data 16384 Nov 24 19:00 wp-includes/
-rwxr-xr-x 1 www-data www-data 2502 Nov 27 2022 wp-links-opml.php*
-rwxr-xr-x 1 www-data www-data 3937 Mar 11 2024 wp-load.php*
-rwxr-xr-x 1 www-data www-data 51367 Oct 1 03:12 wp-login.php*
-rwxr-xr-x 1 www-data www-data 8543 Sep 19 06:37 wp-mail.php*
-rwxr-xr-x 1 www-data www-data 29032 Oct 1 01:08 wp-settings.php*
-rwxr-xr-x 1 www-data www-data 34385 Jun 20 2023 wp-signup.php*
-rwxr-xr-x 1 www-data www-data 5102 Oct 18 23:56 wp-trackback.php*
-rwxr-xr-x 1 www-data www-data 3246 Mar 2 2024 xmlrpc.php*
5.2 创建wordpress数据库以及wordpress用户
[root@huaweiyun:~]# mysql -uroot -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 11
Server version: 8.0.40-0ubuntu0.20.04.1 (Ubuntu)
Copyright (c) 2000, 2024, Oracle and/or its affiliates.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
# 创建数据库
mysql> create database wordpress;
Query OK, 1 row affected (0.01 sec)
# 创建wordpress数据库管理员
mysql> create user wordpressUser;
ERROR 1819 (HY000): Your password does not satisfy the current policy requirements
mysql> create user wordpressUser identified by '数据库密码';
Query OK, 0 rows affected (0.01 sec)
# 给wordpress创建一个账号,方便管理wordpress数据库,并输入密码
mysql> grant all on wordpress.* to wordpressUser;
Query OK, 0 rows affected (0.01 sec)
# 刷新权限,配置生效
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
mysql> exit
Bye
5.3 重启Apache和mysql
[root@huaweiyun:~]# systemctl restart apache2
[root@huaweiyun:~]# systemctl restart mysql
1、输入域名或者ip,会出现以下页面,点击现在开始
2、输入数据库名、用户名以及密码(这里的输入的信息要与上面安装数据库时的信息一致)
3、接下来,会出现这个画面
找到这个文件,并打开
[root@huaweiyun:/var/www/html]# vim wp-config-sample.php
这里需要把手动创建文件wp-config.php
不然就会出现以下问题
[root@huaweiyun:/var/www/html/wordpress]# vim wp-config.php
[root@huaweiyun:/var/www/html/wordpress]# chown www-data.www-data wp-config.php
[root@huaweiyun:/var/www/html/wordpress]# chmod -R 755 wp-config.php
[root@huaweiyun:~]# systemctl restart mysql # 重启数据库
[root@huaweiyun:~]# systemctl restart apache2 # 重启数据库
4、重启服务刷新页面之后,就安装成功了,设置账号密码等等
随后,可以自己在网上寻找主题,以下链接可以找找
https://blog.csdn.net/feiying0canglang/article/details/129671505
换主题操作文档https://www.yuque.com/applek/corepress/setup