WordPress是世界上最受欢迎的网站建设平台,无论是博客、电子商务网站、商业网站、投资组合网站、在线商业目录等等。它是免费和开源的,易于安装、学习和使用,具有高度可插拔性和可定制性。
另请阅读:如何在 Ubuntu 20.04 中使用 Nginx 安装 WordPress
本指南展示了如何在Ubuntu 20.04中使用Apache安装最新版本的WordPress。它假设您已安装LAMP堆栈并为托管网站进行了良好配置,否则,请参阅我们的指南:
- 如何在 Ubuntu 20.04 中使用 PhpMyAdmin 安装 LAMP Stack
在 Ubuntu 20.04 中安装 WordPress
1.在 Ubuntu 20.04 服务器上安装并配置LAMP堆栈(Apache、MariaDB和PHP )后,您可以使用以下wget 命令进一步下载最新版本的 WordPress 。
$ wget -c http://wordpress.org/latest.tar.gz
![](https://www.alaica.com/wp-content/uploads/linux-868.png)
2.下载完成后,使用tar 命令解压缩存档文件,如图所示。
$ tar -xzvf 最新.tar.gz
![](https://www.alaica.com/wp-content/uploads/linux-869.png)
3.接下来,将解压的 WordPress 目录移动到您的文档根目录/var/www/html/
即您的网站下,如图所示(将mysite.com替换为您的网站名称或域名)。以下命令将创建一个mysite.com目录并将 WordPress 文件移动到该目录下。
$ ls -l $ sudo cp -R wordpress /var/www/html/mysite.com $ ls -l /var/www/html/
![](https://www.alaica.com/wp-content/uploads/linux-870.png)
4.现在在网站 ( /var/www/html/mysite.com ) 目录上设置适当的权限。它应该由Apache2用户和名为www-data 的组拥有。
$ sudo chown -R www-data:www-data /var/www/html/mysite.com $ sudo chmod -R 775 /var/www/html/mysite.com
![](https://www.alaica.com/wp-content/uploads/linux-871.png)
为网站创建 WordPress 数据库
5.首先,使用以下mysql命令登录 MariaDB 数据库 shell,并-u
提供用户名(应为root)并-p
输入您在安装 MariaDB 软件时为 MySQL root 帐户设置的密码。
$ sudo mysql -u root -p
6. After login, run the following commands to create your site’s database and a database user with privileges as shown. Remember to replace “mysite”, “mysiteadmin” and “SecureP@ssHere!” with your database name, database username, and the user’s password.
MariaDB [(none)]> CREATE DATABASE mysite; MariaDB [(none)]> GRANT ALL PRIVILEGES ON mysite.* TO 'mysiteadmin'@'localhost' IDENTIFIED BY 'SecureP@ssHere!'; MariaDB [(none)]> FLUSH PRIVILEGES; MariaDB [(none)]> EXIT
![](https://www.alaica.com/wp-content/uploads/linux-872.png)
7. Next, move into your website’s document root, create a wp-config.php file from the sample configuration file provided as shown.
$ cd /var/www/html/mysite.com $ sudo mv wp-config-sample.php wp-config.php
8. Then open the wp-config.php configuration file for editing.
$ sudo vim wp-config.php
and update the database connection parameters (database name, database user, and the user’s password created above) as shown in the following screenshot.
![](https://www.alaica.com/wp-content/uploads/linux-873.png)
Creating Apache VirtualHost for WordPress Website
9. Next, you need to configure Apache webserver to serve your WordPress site using your fully qualified domain name, by creating a Virtual Host for it under the Apache configuration.
To create and activate a new Virtual Host, create a new file under the /etc/apache2/sites-available/ directory. In this example, we will call the file mysite.com.conf (it should end with the .conf
extension).
$ sudo vim /etc/apache2/sites-available/mysite.com.conf
Then copy and paste the following configuration in it (replacing the ServerName and ServerAdmin emails with your values).
<VirtualHost *:80> ServerName mysite.com ServerAdmin webmaster@localhost DocumentRoot /var/www/html/mysite.com ErrorLog ${APACHE_LOG_DIR}/error.log CustomLog ${APACHE_LOG_DIR}/access.log combined </VirtualHost>
![](https://www.alaica.com/wp-content/uploads/linux-874.png)
Save the file and close it.
10. Then check the Apache configuration for syntax correctness. If the syntax is OK, enable the new site and reload the apache2 service to apply the new changes.
$ apache2ctl -t $ sudo a2ensite mysite.com.conf $ sudo systemctl reload apache2
![](https://www.alaica.com/wp-content/uploads/linux-875.png)
11. Also, disable the default virtual host to allow your new site to load properly from a web browser.
$ sudo a2dissite 000-default.conf $ sudo systemctl reload apache2
![](https://www.alaica.com/wp-content/uploads/linux-876.png)
Completing the WordPress Installation via Web Interface
12.最后一部分演示如何使用 Web 安装程序完成 WordPress 安装。因此,打开浏览器并使用您网站的域名进行导航:
http://mysite.com。
WordPress Web 安装程序加载后,选择您想要用于安装的语言,然后单击继续。
![](https://www.alaica.com/wp-content/uploads/linux-877.png)
13.接下来,设置站点的标题、管理用户名、密码以及用于管理站点内容的电子邮件。然后单击安装 WordPress。
![](https://www.alaica.com/wp-content/uploads/linux-878.png)
14. WordPress 安装完成后,单击“登录”以访问站点的管理登录页面。
![](https://www.alaica.com/wp-content/uploads/linux-879.png)
15.现在使用您的管理凭据(上面创建的用户名和密码)登录您的新WordPress网站,并开始从仪表板自定义您的网站。
![](https://www.alaica.com/wp-content/uploads/linux-880.png)
![](https://www.alaica.com/wp-content/uploads/linux-881.png)
在本文中,我们解释了如何使用Apache作为 Web 服务器和MySQL作为为 PHP 网站提供服务的数据库系统来安装WordPress 。
接下来,关键的一步是使用 SSL 保护您的 WordPress 网站。如果您已在真实域上部署 WordPress,则可以使用免费的 Let's Encrypt证书保护该网站。如果您已在虚拟网站上本地部署 WordPress 用于测试或个人使用,我建议您改用自签名证书。