如何在Ubuntu 18.04 LTS上安装PhpMyAdmin

If you are not adept at managing your MySQL database on a terminal, phpMyAdmin provides a graphical interface that simplifies your database administration. phpMyAdmin is a free and open-source front-end PHP-based control panel that allows you to manage your MySQL databases & users, run complex queries, import and export database backups, review SQL activity, and adjust a myriad of other settings pertaining to your MySQL database. In this tutorial, you will learn how you can install phpMyAdmin on Ubuntu 18.04.

如果您不擅长在终端上管理MySQL数据库,则phpMyAdmin提供了一个图形界面,可以简化数据库管理。 phpMyAdmin是一个免费的开放源代码基于PHP的前端控制面板,它使您可以管理MySQL数据库和用户,运行复杂的查询,导入和导出数据库备份,查看SQL活动以及调整与以下各项有关的众多其他设置您MySQL数据库。 在本教程中,您将学习如何在Ubuntu 18.04上安装phpMyAdmin。

先决条件 (Prerequisites)

Before we proceed to install phpMyAdmin, ensure you have the following installed.

在我们继续安装phpMyAdmin之前,请确保您已安装以下组件。

  1. LAMP stack – Linux Apache MySQL PHP. You can follow steps in this tutorial to install LAMP stack on Ubuntu.

    LAMP堆栈– Linux Apache MySQL PHP。 您可以按照本教程中的步骤在Ubuntu上安装LAMP堆栈。
  2. MySQL 5.0.1 or later

    MySQL 5.0.1或更高版本
  3. PHP 5.2.0 or later

    PHP 5.2.0或更高版本

To check MySQL version, log in to the MySQL database as shown.

要检查MySQL版本,请如图所示登录MySQL数据库。

# mysql -u root -p

Provide and password, and thereafter, the details, including the version of MySQL, will be displayed

提供和密码,然后,将显示详细信息,包括MySQL版本

Output

Check Mysql Version

输出量

To check the PHP version, execute the command.

要检查PHP版本,请执行命令。

# php -v

Output

输出量

在Ubuntu 18.04上安装phpMyAdmin (Install phpMyAdmin on Ubuntu 18.04)

phpMyAdmin is available and kept up-to-date in Ubuntu’s repositories. This is therefore the recommended way of installing phpMyAdmin.

phpMyAdmin可用,并在Ubuntu的存储库中保持最新。 因此,这是安装phpMyAdmin的推荐方法。

步骤1:更新系统 (Step 1: Update the System)

Firstly, update the system repositories using the command below

首先,使用以下命令更新系统存储库

# sudo apt update -y

Output

输出量

步骤2:安装并配置phpMyAdmin (Step 2: Install and configure phpMyAdmin)

To install phpMyAdmin, run the command

要安装phpMyAdmin,请运行以下命令

# sudo apt install phpMyAdmin -y

Output

输出量

As the installation process proceeds, you will be presented with the screen below requiring you to choose the web server.

随着安装过程的进行,将显示以下屏幕,要求您选择Web服务器。

Hit on the SPACEBAR button to highlight ‘Apache‘.

点击空格键以突出显示“ Apache ”。

Hit the TAB button which moves the cursor to the OK button

点击TAB按钮,将光标移至OK按钮

Next, hit ENTER.

接下来,按Enter。

The installation will continue for a few seconds and later bring you to this screen.

安装将持续几秒钟,稍后将带您进入此屏幕。

Select ‘Yes‘ and hit ENTER

选择“ ”,然后按Enter

The system will thereafter prompt you for the phpMyAdmin password. Provide the password.

此后,系统将提示您输入phpMyAdmin密码。 提供密码。

Confirm the password in the next screen

在下一个屏幕中确认密码

After the installation is complete, you can find the phpMyAdmin configuration in the /etc/apache2/conf-enabled/phpmyadmin.conf file

安装完成后,您可以在/etc/apache2/conf-enabled/phpmyadmin.conf文件中找到phpMyAdmin配置。

Finally, restart Apache web server to effect the changes

最后,重新启动Apache Web服务器以实现更改

# systemctl restart apache2

步骤3:访问phpMyAdmin面板 (Step 3: Accessing phpMyAdmin panel)

To log in to phpMyAdmin, fire up your browser and browse your server’s URL as shown

要登录phpMyAdmin,启动浏览器并浏览服务器的URL,如下所示

https://server-ip/phpmyadmin/

https://server-ip/phpmyadmin/

Be sure to log in using the root user and corresponding password

确保使用root用户和相应的密码登录

Hit “Go” To access the phpMyAdmin dashboard

点击“开始”以访问phpMyAdmin仪表板

保护phpMyAdmin (Securing phpMyAdmin)

Before we wrap up this tutorial, we need to pay heed to some security considerations when using phpMyAdmin.

在结束本教程之前,我们需要在使用phpMyAdmin时注意一些安全注意事项。

phpMyAdmin communicates directly with MySQL database and uses the same authentication credentials that are used when accessing MySQL. For these 2 reasons, phpMyAdmin becomes a potential target for hackers. Therefore, running phpMyAdmin over plain HTTP connection is advised against. One of the ways of securing our phpMyAdmin instance is by placing a gateway in front of the platform.

phpMyAdmin直接与MySQL数据库通信,并使用与访问MySQL相同的身份验证凭据。 由于这两个原因,phpMyAdmin成为了潜在的黑客目标。 因此,建议不要通过纯HTTP连接运行phpMyAdmin。 保护我们的phpMyAdmin实例的方法之一是通过在平台前面放置一个网关。

We will use Apache’s .htaccess for authorization and authentication.

我们将使用Apache的.htaccess进行授权和认证。

配置Apache以允许.htaccess覆盖 ( Configure Apache to allow .htaccess overrides)

To begin with, we are going to enable the .htaccess file overrides function by editing the Apache configuration file in /etc/apache2/conf-available/phpmyadmin.conf.

首先,我们将通过编辑/etc/apache2/conf-available/phpmyadmin.conf的Apache配置文件来启用.htaccess文件覆盖功能。

We will add the AllowOverride All directive in the section of the Apache configuration file as shown

我们将在Apache配置文件的部分中添加AllowOverride All指令,如下所示

Options FollowSymLinks
    DirectoryIndex index.php
    AllowOverride All
    . . .

Save and exit the text editor.

保存并退出文本编辑器。

To effect the changes, restart the Apache web server

要进行更改,请重新启动Apache Web服务器

# systemctl restart apache2

创建一个.htaccess文件 ( Create a .htaccess file)

Having enabled the .htaccess use for our phpMyAdmin application, let’s create the .htaccess file for security implementation.

为我们的phpMyAdmin应用程序启用了.htaccess使用后,让我们创建.htaccess文件以实现安全性。

For it to be a success, we are going to create the file within phpMyAdmin directory

为获得成功,我们将在phpMyAdmin目录中创建文件

sudo vim /usr/share/phpmyadmin/.htaccess

Add the following information to the file

将以下信息添加到文件中

/usr/share/phpmyadmin/.htaccess
AuthType Basic
AuthName "Restricted Files"
AuthUserFile /etc/phpmyadmin/.htpasswd
Require valid-user

Let’s have a look at some of the terminologies in the file

让我们看一下文件中的一些术语

AuthType Basic: The attribute specifies the type of authentication to be implemented. This implements a password authentication using a password file.

AuthType Basic :该属性指定要实现的身份验证类型。 这使用密码文件实现密码验证。

AuthName: This attribute sets the message for the authentication dialog box.

AuthName :此属性设置身份验证对话框的消息。

AuthUserFile: This defines the location of the password file to be used for the authentication.

AuthUserFile :这定义了用于身份验证的密码文件的位置。

Require valid-user: This attribute specifies that only authenticated users are allowed to access phpMyAdmin application. This keeps any unauthorized users from logging in.

Require valid-user :此属性指定仅允许经过身份验证的用户访问phpMyAdmin应用程序。 这样可以防止任何未经授权的用户登录。

创建一个.htpasswd文件进行身份验证 ( Create a .htpasswd file for authentication)

The final stage will be to create a .htpasswd file for authentication. We are going to create it within the /etc/phpmyadmin/.htpasswd file like we specified earlier in the /usr/share/phpmyadmin/.htaccess file.

最后.htpasswd是创建一个.htpasswd文件进行身份验证。 我们将在/etc/phpmyadmin/.htpasswd文件中创建它,就像我们先前在/usr/share/phpmyadmin/.htaccess文件中指定的一样。

sudo htpasswd -c  /usr/share/phpmyadmin/.htpasswd username

Thereafter, you will be prompted to create a password and later confirm for the user that you are creating.

此后,系统将提示您创建密码,并稍后为您要创建的用户确认。

In the output below, we have created user ‘spikey

在下面的输出中,我们创建了用户' Spiky '

You can add an additional user without the -c flag as shown

您可以添加不带-c标志的其他用户,如图所示

# sudo htpasswd /etc/phpmyadmin/.htpasswd additionaluser

Now, let’s access phpMyAdmin via the browser. Notice the pop-up authentication dialog box.

现在,让我们通过浏览器访问phpMyAdmin。 注意弹出式身份验证对话框。

Use the credentials you defined using the htpasswd command and click on ‘Sign In’.

使用您使用htpasswd命令定义的凭据,然后单击“登录”。

https://server-ip/phpmyadmin/

https://server-ip/phpmyadmin/

After logging in, you will be directed to the phpMyAdmin dashboard as before.

登录后,您将像以前一样被定向到phpMyAdmin仪表板。

结语 (Wrapping up)

This concludes our tutorial on how you can install phpMyAdmin on Ubuntu 18.04 with additional security. phpMyAdmin provides a seamless and efficient way of managing your databases, users and other aspects of your databases and tables.

这样就结束了我们的教程,该教程介绍了如何在Ubuntu 18.04上以更高的安全性安装phpMyAdmin。 phpMyAdmin提供了一种无缝高效的方法来管理数据库,用户以及数据库和表的其他方面。

翻译自: https://www.journaldev.com/29122/install-phpmyadmin-ubuntu

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值