如何在 Ubuntu 22.04 上使用免费的 Let's Encrypt SSL 安装 PhpMyAdmin如何在 Ubuntu 22.04 上使用免费的 Let's Encrypt SSL 安装 PhpMyAdmin如何在 Ubuntu 22.04 上使用免费的 Let's Encrypt SSL 安装 PhpMyAdmin如何在 Ubuntu 22.04 上使用免费的 Let's Encrypt SSL 安装 PhpMyAdmin
  • 文章
  • 正则表达式
    • 工具
  • 登录
找到的结果: {phrase} (显示: {results_count} 共: {results_count_total})
显示: {results_count} 共: {results_count_total}

加载更多搜索结果...

搜索范围
模糊匹配
搜索标题
搜索内容
发表 admin at 2025年2月28日
类别
  • 未分类
标签

如何在 Ubuntu 22.04 上使用免费的 Let's Encrypt SSL 安装 PhpMyAdmin

本教程适用于这些操作系统版本

  • Ubuntu 22.04(Jammy Jellyfish)
  • Ubuntu 11.04(Natty Narwhal)

在此页

  1. 先决条件
  2. 安装 Nginx、MariaDB 和 PHP
  3. 安装 phpMyAdmin
  4. 配置 MariaDB 数据库
  5. 为 phpMyAdmin 配置 Nginx
  6. 使用 Let's Encrypt SSL 保护 phpMyAdmin
  7. 访问 phpMyAdmin
  8. 结论

phpMyAdmin 是一个免费的、开源的、基于网络的应用程序,用于通过网络浏览器管理数据库。它提供了一个简单且用户友好的 Web 界面,可帮助数据库管理员执行多项任务、管理用户帐户和权限、导入和导出数据、执行 SQL 语句等等。它是用 PHP 编写的,使初学者能够与他们的 MySQL 数据库进行交互。

在本教程中,我们将解释如何在 Ubuntu 22.04 上安装带有 Nginx 的 phpMyAdmin。

先决条件

  • 运行 Ubuntu 22.04 的服务器。
  • 您的服务器指向了一个有效的域名。
  • 在您的服务器上配置了 root 密码。

安装 Nginx、MariaDB 和 PHP

首先,您需要在服务器中安装 Nginx Web 服务器、MariaDB、PHP 和其他所需的 PHP 扩展。您可以使用以下命令安装所有这些:

apt-get install nginx mariadb-server php php-cli php-mysql php-mbstring php-zip php-gd php-json php-curl php-fpm -y

安装所有软件包后,您可以继续下一步。

安装 phpMyAdmin

默认情况下,phpMyAdmin 包在 Ubuntu 22.04 默认存储库中可用。您只需运行以下命令即可安装它:

apt-get install phpmyadmin -y

由于我们使用的是 Nginx Web 服务器,您只需按 TAB,然后按 ENTER 即可绕过此提示。您将被要求配置一个数据库供 phpMyAdmin 使用。

选择 Yes 并按 Enter 键继续。系统将要求您选择并确认 phpMyAdmin 应用程序的密码,如下所示:

提供您想要的密码,然后按 Enter 键完成安装。

配置 MariaDB 数据库

默认情况下,MariaDB 是不安全的。因此,保护 MariaDB 并使用以下命令设置 MariaDB root 密码:

mysql_secure_installation

如下图所示回答所有问题:

Enter current password for root (enter for none): 
Set root password? [Y/n] Y
New password: 
Re-enter new password: 
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 后,建议创建一个单独的用户来连接 phpMyAdmin 并管理数据库。

为此,请使用以下命令登录到 MariaDB shell:

mysql -u root -p

在出现提示时提供您的 root 密码,然后使用以下命令创建一个新用户:

MariaDB [(none)]> create user  identified by 'password';

接下来,使用以下命令将所有权限授予用户:

MariaDB [(none)]> grant all privileges on *.* to  with grant option;

接下来,使用以下命令刷新权限并退出 MariaDB shell:

MariaDB [(none)]> flush privileges;
MariaDB [(none)]> exit;

完成后,您可以继续下一步。

为 phpMyAdmin 配置 Nginx

接下来,您需要创建一个 Nginx 虚拟主机服务器块来托管 phpMyAdmin。您可以使用以下命令创建它:

nano /etc/nginx/conf.d/phpmyadmin.conf

添加以下行:

server {
  listen 80;
  listen [::]:80;
  server_name phpmyadmin.example.com;
  root /usr/share/phpmyadmin/;
  index index.php index.html index.htm index.nginx-debian.html;

  access_log /var/log/nginx/phpmyadmin_access.log;
  error_log /var/log/nginx/phpmyadmin_error.log;

  location / {
    try_files $uri $uri/ /index.php;
  }

  location ~ ^/(doc|sql|setup)/ {
    deny all;
  }

  location ~ \.php$ {
    fastcgi_pass unix:/run/php/php8.1-fpm.sock;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    include fastcgi_params;
    include snippets/fastcgi-php.conf;
  }

  location ~ /\.ht {
    deny all;
  }
}

保存并关闭文件。然后,使用以下命令检查 Nginx 是否有任何语法错误:

nginx -t

您应该得到以下输出:

nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful

最后,重新启动 Nginx 服务以应用更改:

systemctl restart nginx

您还可以使用以下命令检查 Nginx 状态:

systemctl status nginx

您应该看到以下输出:

? nginx.service - A high performance web server and a reverse proxy server
     Loaded: loaded (/lib/systemd/system/nginx.service; enabled; vendor preset: enabled)
     Active: active (running) since Sun 2022-06-12 04:37:05 UTC; 6s ago
       Docs: man:nginx(8)
    Process: 20020 ExecStartPre=/usr/sbin/nginx -t -q -g daemon on; master_process on; (code=exited, status=0/SUCCESS)
    Process: 20021 ExecStart=/usr/sbin/nginx -g daemon on; master_process on; (code=exited, status=0/SUCCESS)
   Main PID: 20022 (nginx)
      Tasks: 2 (limit: 2292)
     Memory: 2.6M
        CPU: 33ms
     CGroup: /system.slice/nginx.service
             ??20022 "nginx: master process /usr/sbin/nginx -g daemon on; master_process on;"
             ??20023 "nginx: worker process" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" ""

Jun 12 04:37:05 ubuntu systemd[1]: Starting A high performance web server and a reverse proxy server...
Jun 12 04:37:05 ubuntu systemd[1]: Started A high performance web server and a reverse proxy server.

接下来,更改 phpMyAdmin 目录的所有权和权限:

chown -R www-data:www-data /usr/share/phpmyadmin/
chmod -R 755

使用 Let's Encrypt SSL 保护 phpMyAdmin

在开始之前,您需要安装 Certbot 客户端以下载并安装 Let's Encrypt SSL。

首先,使用以下命令添加 Certbot 存储库:

add-apt-repository ppa:ahasenack/certbot-tlssni01-1875471

接下来,使用以下命令更新存储库并安装 Certbot 客户端:

apt-get update -y
apt-get install certbot python3-certbot-nginx -y

安装 Certbot 后,运行以下命令为您的域下载并安装 Let's Encrypt SSL:

certbot --nginx -d phpmyadmin.example.com

您将被要求提供您的电子邮件并接受服务条款,如下所示:

Saving debug log to /var/log/letsencrypt/letsencrypt.log
Plugins selected: Authenticator nginx, Installer nginx
Enter email address (used for urgent renewal and security notices) (Enter 'c' to
cancel): 

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
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 at
https://acme-v02.api.letsencrypt.org/directory
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
(A)gree/(C)ancel: A

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Would you be willing 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: Y

Obtaining a new certificate
Performing the following challenges:
http-01 challenge for phpmyadmin.example.com
Waiting for verification...
Cleaning up challenges
Deploying Certificate to VirtualHost /etc/nginx/sites-enabled/phpmyadmin

接下来,选择是否将 HTTP 流量重定向到 HTTPS:

Please choose whether or not to redirect HTTP traffic to HTTPS, removing HTTP access.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
1: No redirect - Make no further changes to the webserver configuration.
2: Redirect - Make all requests redirect to secure HTTPS access. Choose this for
new sites, or if you're confident your site works on HTTPS. You can undo this
change by editing your web server's configuration.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Select the appropriate number [1-2] then [enter] (press 'c' to cancel): 2

键入 2 并按 Enter 键以完成安装。

Redirecting all traffic on port 80 to ssl in /etc/nginx/sites-enabled/phpmyadmin

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Congratulations! You have successfully enabled https://phpmyadmin.example.com

You should test your configuration at:
https://www.ssllabs.com/ssltest/analyze.html?d=phpmyadmin.example.com
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

IMPORTANT NOTES:
 - Congratulations! Your certificate and chain have been saved at:
   /etc/letsencrypt/live/phpmyadmin.example.com/fullchain.pem
   Your key file has been saved at:
   /etc/letsencrypt/live/phpmyadmin.example.com/privkey.pem
   Your cert will expire on 2022-09-12. To obtain a new or tweaked
   version of this certificate in the future, simply run certbot again
   with the "certonly" option. To non-interactively renew *all* of
   your certificates, run "certbot renew"
 - 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

访问 phpMyAdmin

现在,打开您的 Web 浏览器并输入 URL https://phpmyadmin.eample.com。您将被重定向到 phpMyAdmin 登录页面:

提供您的管理员用户名、密码,然后单击“开始”按钮。您应该在以下页面上看到 phpMyAdmin 默认仪表板:

结论

恭喜!您已经在 Ubuntu 22.04 上成功安装了 phpMyAdmin 并使用 Let's Encrypt SSL 对其进行了保护。您现在可以连接到 phpMyAdmin,管理您的数据库并通过 Web 浏览器执行多项任务。

©2015-2025 艾丽卡 support@alaica.com