使用ubuntu 16.04上使用 LAMP 堆栈安装phpmyadmin

时间:2020-03-21 11:45:43  来源:igfitidea点击:

phpmyadmin是一个免费的,开源的基于Web的数据库管理工具,使用PHP编程语言编写。
它允许数据库管理员使用Web浏览器从本地或者远程系统管理单个或者多个数据库服务器。
使用phpmyadmin,我们可以创建,删除,重命名,编辑数据库,表,字段,以及我们可以直接执行任何SQL命令。
目前,它支持MySQL,MariaDB和Drizzle数据库服务器。
在本教程中,我们将看到如何在Ubuntu 16.04 LTS服务器中使用 LAMP 堆栈安装PHPMyAdmin。

使用Ubuntu 16.04 LTS安装PHPMYADMIN使用 LAMP 堆栈

首先,Ubuntu 16.04 LTS服务器中的设置LAMP堆栈如下所述。

  • 在Ubuntu 16.04中安装Apache,MariaDB,PHP(Lamp Stack)

PHPMyAdmin可在Ubuntu操作系统的默认存储库中使用。
一旦安装 LAMP 堆栈并准备就绪,请安装PHPMyAdmin,如下所示:

sudo apt-get install phpmyadmin

在安装过程中,我们将被要求选择应自动配置为运行PHPMyAdmin的Web服务器。
在我们的情况下,它是Apache WebServer。

选择Apache2并单击"确定"。

选择是并按ENTER键配置数据库,用于使用dbconfig-common for phpmyadmin。

输入PHPMyAdmin的密码以注册数据库服务器。
如果留空,将生成随机密码。

重新输入密码以确认:

哎呀!我们可能会遇到以下错误消息:

An error occurred while installing the database: 
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using 
password: NO) . Your options are: 
* abort - Causes the operation to fail; you will need to downgrade, 
   reinstall, reconfigure this package, or otherwise manually intervene 
   to continue using it. This will usually also impact your ability to 
   install other packages until the installation failure is resolved. 
* retry - Prompts once more with all the configuration questions 
   (including ones you Jan have missed due to the debconf priority 
   setting) and makes another attempt at performing the operation. 
* retry (skip questions) - Immediately attempts the operation again, 
   skipping all questions. This is normally useful only if you have 
   solved the underlying problem since the time the error occurred.

要修复此问题,请单击"确定"并中止PHPMyAdmin安装。

使用命令使用root用户登录MariaDB或者MySQL提示:

mysql -u root -p

为PHPMyAdmin创建一个新的数据库和数据库用户,并授予PHPMyAdmin用户的完全权限。

出于本教程的目的,我将创建一个名为"phpmyadmindb"的数据库,以及带有密码"ubuntu"的数据库用户"phpmyadminuser"。
请使用强烈的密码,这非常难以猜到生产环境。

Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 52
Server version: 10.0.25-MariaDB-0ubuntu0.16.04.1 Ubuntu 16.04
Copyright (c) 2000, 2015, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MariaDB [(none)]> CREATE DATABASE phpmyadmindb;
Query OK, 1 row affected (0.01 sec)
MariaDB [(none)]> GRANT ALL ON phpmyadmindb.* TO Hyman@theitroad IDENTIFIED BY 'ubuntu';
Query OK, 0 rows affected (0.00 sec)
MariaDB [(none)]> flush privileges;
Query OK, 0 rows affected (0.00 sec)
MariaDB [(none)]> \q
Bye

然后,编辑phpmyadmin/config-db.php文件:

sudo nano /etc/phpmyadmin/config-db.php

将数据库名称,数据库用户及其密码替换为我们之前创建的值。

[...]
$dbuser='phpmyadminuser';
$dbpass='ubuntu';
$basepath='';
$dbname='phpmyadmindb';
$dbserver='localhost';
$dbport='';
$dbtype='mysql';

保存并关闭文件。

接下来,我们必须安装以下PHP模块。
否则,我们将收到一条错误消息:

MBString扩展丢失。
请检查PHP配置。

要安装PHP模块,请运行:

sudo apt-get install php-mbstring php7.0-mbstring php-gettext

然后,编辑Apache WebServer配置文件:

sudo nano /etc/apache2/apache2.conf

最后添加以下行:

Include /etc/phpmyadmin/apache.conf

保存并关闭文件。
重新启动Apache服务以生效更改。

sudo systemctl restart apache2

访问phpmyadmin仪表板

打开Web浏览器并导航到http://ip-address/phpmyadmin。

我们应该看到以下屏幕。
输入MariaDB/MySQL'根用户名及其密码。

登录phpmyadmin仪表板。