如何在Ubuntu 20.04上使用Nginx安装phpMyAdmin
phpMyAdmin是一个免费的开源Web界面,用于管理MySQL和MariaDB服务器。 Web托管公司广泛使用它来使网站所有者能够自己创建和管理数据库。
phpMyAdmin帮助我们执行数据库活动,例如创建,删除,查询,数据库,表,列等。
在这篇文章中,我们将看到如何在Ubuntu 20.04上使用Nginx安装phpMyAdmin。
先决条件
安装MariaDB服务器
要使用phpMyAdmin管理数据库,您的系统必须具有正在运行的数据库实例和Nginx Web服务器。
独立数据库
请遵循以下教程,并为设置phpMyAdmin做好准备。
步骤1:
如何在Ubuntu 20.04上安装MariaDB
要么
步骤1:
如何在Ubuntu 20.04上安装MySQL 8.0
然后,
第2步:
如何在Ubuntu 20.04上安装LEMP Stack
如果遵循了步骤1 – MariaDB / MySQL的安装,则可以在步骤2 – LEMP堆栈教程中跳过MariaDB服务器的安装。
为phpMyAdmin安装以下PHP扩展以与数据库连接。
sudo apt install -y php-json php-mbstring
LEMP堆栈
读:
如何在Ubuntu 20.04上安装LEMP Stack
为phpMyAdmin安装以下PHP扩展以与数据库连接。
sudo apt install -y php-json php-mbstring
安装phpMyAdmin
适用于Ubuntu 20.04的Ubuntu操作系统存储库中提供的phpMyAdmin有点旧。 因此,我们将从官方网站下载最新版本的phpMyAdmin。
wget https://files.phpmyadmin.net/phpMyAdmin/5.0.2/phpMyAdmin-5.0.2-all-languages.tar.gz
使用tar命令解压缩phpMyAdmin。
tar -zxvf phpMyAdmin-5.0.2-all-languages.tar.gz
将phpMyAdmin移至所需位置。
sudo mv phpMyAdmin-5.0.2-all-languages /usr/share/phpMyAdmin
配置phpMyAdmin
复制样本配置文件。
sudo cp -pr /usr/share/phpMyAdmin/config.sample.inc.php /usr/share/phpMyAdmin/config.inc.php
编辑配置文件。
sudo nano /usr/share/phpMyAdmin/config.inc.php
生成河豚密码,并在配置文件中更新密码。
$cfg['blowfish_secret'] = 'CfX1la/aG83gx1{7rADus,iqz8RzeV8x'; /* YOU MUST FILL IN THIS FOR COOKIE AUTH! */
另外,取消注释phpMyAdmin存储设置。
使用您可以访问下一步将创建的phpMyAdmin配置数据库的用户名和密码来更改controluser和controlpass。 该用户帐户用于访问phpMyAdmin配置存储。
/** * phpMyAdmin configuration storage settings. */ /* User used to manipulate with storage */ $cfg['Servers'][$i]['controlhost'] = 'localhost'; // $cfg['Servers'][$i]['controlport'] = ''; $cfg['Servers'][$i]['controluser'] = 'pma'; $cfg['Servers'][$i]['controlpass'] = 'pmapass'; /* Storage database and tables */ $cfg['Servers'][$i]['pmadb'] = 'phpmyadmin'; $cfg['Servers'][$i]['bookmarktable'] = 'pma__bookmark'; $cfg['Servers'][$i]['relation'] = 'pma__relation'; $cfg['Servers'][$i]['table_info'] = 'pma__table_info'; $cfg['Servers'][$i]['table_coords'] = 'pma__table_coords'; $cfg['Servers'][$i]['pdf_pages'] = 'pma__pdf_pages'; $cfg['Servers'][$i]['column_info'] = 'pma__column_info'; $cfg['Servers'][$i]['history'] = 'pma__history'; $cfg['Servers'][$i]['table_uiprefs'] = 'pma__table_uiprefs'; $cfg['Servers'][$i]['tracking'] = 'pma__tracking'; $cfg['Servers'][$i]['userconfig'] = 'pma__userconfig'; $cfg['Servers'][$i]['recent'] = 'pma__recent'; $cfg['Servers'][$i]['favorite'] = 'pma__favorite'; $cfg['Servers'][$i]['users'] = 'pma__users'; $cfg['Servers'][$i]['usergroups'] = 'pma__usergroups'; $cfg['Servers'][$i]['navigationhiding'] = 'pma__navigationhiding'; $cfg['Servers'][$i]['savedsearches'] = 'pma__savedsearches'; $cfg['Servers'][$i]['central_columns'] = 'pma__central_columns'; $cfg['Servers'][$i]['designer_settings'] = 'pma__designer_settings'; $cfg['Servers'][$i]['export_templates'] = 'pma__export_templates';
信用:
技术世界
导入create_tables.sql为phpMyAdmin创建表。
sudo mysql < /usr/share/phpMyAdmin/sql/create_tables.sql -u root -p
登录到MariaDB。
sudo mysql -u root -p
添加用户并向phpMyAdmin的配置数据库授予权限。
CREATE USER 'pma'@'localhost' IDENTIFIED BY 'pmapass'; GRANT ALL ON phpmyadmin.* TO 'pma'@'localhost'; FLUSH PRIVILEGES; exit
在/etc/nginx/conf.d目录下为phpMyAdmin创建一个虚拟主机配置文件。
sudo nano /etc/nginx/conf.d/phpMyAdmin.conf
使用以下服务器块为phpMyAdmin创建虚拟主机。 根据需要更改域名(server_name)。
server { listen 80; server_name pma.itzgeek.local; root /usr/share/phpMyAdmin; location / { index index.php; } ## Images and static content is treated different location ~* ^.+.(jpg|jpeg|gif|css|png|js|ico|xml)$ { access_log off; expires 30d; } location ~ /.ht { deny all; } location ~ /(libraries|setup/frames|setup/libs) { deny all; return 404; } location ~ .php$ { include /etc/nginx/fastcgi_params; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME /usr/share/phpMyAdmin$fastcgi_script_name; } }
为phpMyAdmin创建一个tmp目录,然后更改权限。
sudo mkdir /usr/share/phpMyAdmin/tmp
sudo chmod 777 /usr/share/phpMyAdmin/tmp
设置phpMyAdmin目录的所有权。
sudo chown -R www-data:www-data /usr/share/phpMyAdmin
重新启动服务。
sudo systemctl restart nginx
sudo systemctl restart php7.4-fpm
创建数据库管理员用户
默认情况下,MariaDB根用户只能通过Unix套接字登录。 因此,我们现在将创建一个具有管理所有数据库权限的数据库管理用户。
GRANT ALL PRIVILEGES ON *.* TO 'dbadmin'@'localhost' IDENTIFIED BY 'password'; FLUSH PRIVILEGES; EXIT;
如果需要,可以为MariaDB根用户禁用Unix套接字身份验证,并启用本机密码登录。
访问phpMyAdmin
使用Web浏览器访问phpMyAdmin:
http://您的完全限定域名
使用我们在上一步中创建的数据库管理员用户登录。
登录到phpMyAdmin
您将获得可以在其中管理数据库的主页。

phpMyAdmin主页
结论
就这样。 我希望这篇文章可以帮助您在Ubuntu 20.04上使用Nginx安装phpMyAdmin。 请在评论部分分享您的反馈。