如何在 Ubuntu 22.04 LTS 上安装 WordPress
admin
2023-08-02 05:05:00
0

WordPress 是最受欢迎的网站建设工具之一。它是开源 CMS,几乎可以与任何网络托管服务配合使用,使其成为构建任何类型网站的最容易安装和使用的服务之一。WordPress-logoWordPress-logo

在 Ubuntu 22.04 LTS Jammy Jellyfish 上安装 WordPress

apt步骤 1. 首先,通过在终端中运行以下命令,确保所有系统包都是最新的。

sudo apt update
sudo apt upgrade

步骤 2. 在 Ubuntu 22.04 上安装 LAMP 堆栈。

在开始本教程之前,必须在您的服务器上安装 LAMP 服务器。如果您没有安装 LAMP Stack,您可以在此处按照我们的指南进行操作。

步骤 3. 在 Ubuntu 22.04 上安装 WordPress。

默认情况下,Ubuntu 22.04 基础存储库中不提供 WordPress。现在运行以下命令,将最新的稳定版 WordPress 下载到您的 Ubuntu 系统:

wget -O /tmp/wordpress.tar.gz https://wordpress.org/latest.tar.gz

接下来,使用以下命令将 WordPress 压缩包解压缩到 webroot 目录:

tar -xzvf /tmp/wordpress.tar.gz -C /var/www/html

我们将需要更改一些文件夹权限:

chown -R www-data.www-data /var/www/html/wordpress

步骤 4. 为 WordPress 配置 MariaDB。

默认情况下,MariaDB 未加固。mysql_secure_installation您可以使用脚本保护 MariaDB 。您应该仔细阅读下面的每个步骤,这些步骤将设置 root 密码、删除匿名用户、禁止远程 root 登录、删除测试数据库和访问安全 MariaDB:

mysql_secure_installation

像这样配置它:

- Set root password? [Y/n] y
- Remove anonymous users? [Y/n] y
- Disallow root login remotely? [Y/n] y
- Remove test database and access to it? [Y/n] y
- Reload privilege tables now? [Y/n] y

接下来,我们需要登录 MariaDB 控制台并为 WordPress 创建一个数据库。运行以下命令:

mysql -u root -p

这将提示您输入密码,因此请输入您的 MariaDB 根密码并按 Enter。登录到数据库服务器后,您需要为 WordPress 安装创建一个数据库:

MariaDB [(none)]> CREATE DATABASE wordpress_db;
MariaDB [(none)]> CREATE USER \'wordpress_user\'@\'localhost\' IDENTIFIED BY \'your-strong-password\';
MariaDB [(none)]> GRANT ALL ON wordpress_db.* TO \'wordpress_user\'@\'localhost\';
MariaDB [(none)]> FLUSH PRIVILEGES;
MariaDB [(none)]> EXIT;

步骤 5. 配置 WordPress。

现在导航到 WordPress 目录并重命名示例配置文件:

cd /var/www/html/wordpress
sudo mv wp-config-sample.php wp-config.php

接下来,编辑 WordPress 配置文件:

nano /var/www/html/wordpress/wp-config.php

添加以下文件配置:

define( \'DB_NAME\', \'wordpress_db\' );

/** Database username */
define( \'DB_USER\', \'wordpress_user\' );

/** Database password */
define( \'DB_PASSWORD\', \'your-strong-password\' );

/** Database hostname */
define( \'DB_HOST\', \'localhost\' );

步骤 6. 配置 Apache 虚拟主机。

现在为 WordPress 创建虚拟主机配置文件:

sudo nano /etc/apache2/sites-available/www.domain.com.conf

添加以下文件:



   ServerName domain.com
   ServerAlias www.domain.com
   ServerAdmin admin@domain.com
   DocumentRoot /var/www/html/wordpress

   ErrorLog ${APACHE_LOG_DIR}/www.domain.com_error.log
   CustomLog ${APACHE_LOG_DIR}/www.domain.com_access.log combined

   
      Options FollowSymlinks
      AllowOverride All
      Require all granted
   

保存并关闭文件,然后重新启动 Apache 网络服务器以进行更改:

sudo a2ensite www.domain.com.conf
sudo a2enmod ssl rewrite
sudo systemctl restart apache2

第 7 步。使用 Let\’s Encrypt 保护 WordPress。

首先,您需要安装 Certbot 以使用 Let\’s Encrypt 获取 SSL 证书:

sudo apt install certbot python3-certbot-apache

接下来,按照以下步骤使用 Let\’s Encrypt 获取您的 SSL 证书:

sudo certbot --apache

您将需要按照交互式提示安装证书。由于我有两个域,我将为这两个域安装 SSL 证书:

Saving debug log to /var/log/letsencrypt/letsencrypt.log
Enter email address (used for urgent renewal and security notices)
 (Enter \'c\' to cancel): admin@domain.com

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Please read the Terms of Service at
https://letsencrypt.org/documents/LE-SA-v1.2-November-15-2017.pdf. You must
agree in order to register with the ACME server. Do you agree?
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
(Y)es/(N)o: Y
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Would you be willing, once your first certificate is successfully issued, to
share your email address with the Electronic Frontier Foundation, a founding
partner of the Let\'s Encrypt project and the non-profit organization that
develops Certbot? We\'d like to send you email about our work encrypting the web,
EFF news, campaigns, and ways to support digital freedom.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
(Y)es/(N)o: N
Account registered.

Which names would you like to activate HTTPS for?
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
1: domain.com
2: www.domain.com
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Select the appropriate numbers separated by commas and/or spaces, or leave input
blank to select all options shown (Enter \'c\' to cancel): 1,2
Requesting a certificate for domain.com and www.domain.com
Successfully received certificate.
Certificate is saved at: /etc/letsencrypt/live/domain.com/fullchain.pem
Key is saved at:         /etc/letsencrypt/live/domain.com/privkey.pem
This certificate expires on 2022-12-10.
These files will be updated when the certificate renews.
Certbot has set up a scheduled task to automatically renew this certificate in the background.

Deploying certificate
Successfully deployed certificate for domain.com to /etc/apache2/sites-available/www.domain.com-le-ssl.conf
Successfully deployed certificate for www.domain.com to /etc/apache2/sites-available/www.domain.com-le-ssl.conf
Congratulations! You have successfully enabled HTTPS on https://domain.com and https://www.domain.com

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
If you like Certbot, please consider supporting our work by:
 * Donating to ISRG / Let\'s Encrypt:   https://letsencrypt.org/donate
 * Donating to EFF:                    https://eff.org/donate-le
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

步骤 8. 设置自动续订 SSL。

Let\’s Encrypt 证书的有效期为 90 天,强烈建议在证书到期前更新证书。您可以通过运行以下命令来测试证书的自动续订:

sudo certbot renew --dry-run

输出:

Saving debug log to /var/log/letsencrypt/letsencrypt.log

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Processing /etc/letsencrypt/renewal/domain.com.conf
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Account registered.
Simulating renewal of an existing certificate for domain.com and www.domain.com

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Congratulations, all simulated renewals succeeded: 
  /etc/letsencrypt/live/domain.com/fullchain.pem (success)
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

步骤 9. 配置防火墙。

现在,我们使用 Apache 设置了一个简单防火墙 (UFW),以允许对 HTTP 和 HTTPS 的默认 Web 端口进行公共访问:

sudo ufw allow OpenSSH
sudo ufw allow \'Apache Full\'
sudo ufw enable

第 10 步。访问 WordPress Web 界面。

成功安装后,打开 Web 浏览器并使用 URL 访问 WordPress 安装向导。您将被重定向到以下页面:https://domain.com

wordpress-wp-admin-installwordpress-wp-admin-install

感谢您使用本教程在 Ubuntu 22.04 LTS Jammy Jellyfish 系统上安装带有 LAMP 的 WordPress。如需其他帮助或有用信息,我们建议您查看WordPress 网站。

相关内容

热门资讯

Windows 11 和 10... Windows 11/10 文件夹属性中缺少共享选项卡 – 已修复 1.检查共享选项卡是否可用 右键...
Radmin VPN Wind... Radmin VPN 是一款免费且用户友好的软件,旨在牢固地连接计算机以创建一个有凝聚力的虚拟专用网...
如何修复 Steam 内容文件... Steam 内容文件锁定是当您的 Steam 文件无法自行更新时出现的错误。解决此问题的最有效方法之...
在 Windows 11 中打... 什么是链路状态电源管理? 您可以在系统控制面板的电源选项中看到链接状态电源管理。它是 PCI Exp...
事件 ID 7034:如何通过... 点击进入:ChatGPT工具插件导航大全 服务控制管理器 (SCM) 负责管理系统上运行的服务的活动...
Hive OS LOLMine... 目前不清退的交易所推荐: 1、全球第二大交易所OKX欧意 国区邀请链接: https://www.m...
在 iCloud 上关闭“查找... 如果您是 Apple 的长期用户,您肯定会遇到过 Find My 应用程序,它本机安装在 iPhon...
iPhone 屏幕上有亮绿色斑... iPhone 是市场上最稳定的智能手机之一,这主要归功于专为它们设计的 iOS 操作系统。然而,他们...
balenaEtcher烧录后... balenaEtcher烧录后u盘或者内存卡无法识别不能使用的解决方法想要恢复原来的方法,使用win...
farols1.1.501.0... faro ls 1.1.501.0(64bit)可以卸载,是一款无需连接外部PC机或笔记本计算机即可...