Install phpMyAdmin, Apache2 and MySQL on Ubuntu 18.04 LTS Server

I have recently been testing Ubuntu 18.04 LTS installed on my VMware Workstation as a guest machine… In this test I learn how to install phpMyAdmin.

phpMyAdmin is a web-based tool that allows users to easily manage MySQL or MariaDB databases. If you’re not comfortable managing databases via Linux command line , you may want to use phpMyAdmin web interface to manage your databases instead.

phpMyAdmin relies on the LAMP stack to function. LAMP is a combination of open source software that enable dynamic websites and applications to function. So before getting phpMyAdmin to function, lets get LAMP installed.

This brief tutorial shows students and new users how to install phpMyAdmin with Apache2, MySQL and PHP support on Ubuntu 18.04 LTS. This post should be short and easy to follow.

To get started, continue with the steps below:

Step 1: Install MySQL Database Server

Run the commands below to install MySQL database server

sudo apt update
sudo apt install mysql-server mysql-client

During the installation, you’ll be prompted to create and confirm MySQL root password.. please do.

Step 2: Install Apache2 HTTP Server

Next, run the commands below to install Apache2 HTTP Web Server

sudo apt install apache2

Step 3: Configure Apache2

Now run the commands below to configure Apache2 basic settings. These are the basics.. and more advanced configurations can be done later.

First, confirm that your Ubuntu server configuration has Apache2 DirectoryIndex directives for php defined. To run PHP based apps, Apache2 must have index.php as a directory index in its dir.conf file.

sudo nano /etc/apache2/mods-enabled/dir.conf

Make sure index.php is defined as a DirectoryIndex in the dir.conf file…

<IfModule mod_dir.c>
DirectoryIndex index.html index.php index.xhtml index.htm
</IfModule>

Next, configure your domain or server name for your site… Open Apache2 default site config file by running the commands below.

sudo nano /etc/apache2/sites-enabled/000-default.conf

Then add the ServerName and ServerAlias to match your domain name… and save the file.

 <VirtualHost *:80>
     ServerAdmin admin@mylab.com
     DocumentRoot /var/www/html/
     ServerName example.com
     ServerAlias example.com

     ErrorLog ${APACHE_LOG_DIR}/error.log
     CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

After that restart Apache2.

sudo systemctl restart apache2.service

Step 4: Install PHP and Related Modules

Run the commands below to install PHP and related PHP modules.

sudo apt-get install php php-cgi libapache2-mod-php php-common php-pear php-mbstring

Step 5: Configure Apache2 to Use PHP

After install PHP and other related scripts, run the commands below to enable Apache2 to use PHP.

sudo a2enconf php7.2-cgi

Reload Apache2

sudo systemctl reload apache2.service

Step 6: Install phpMyAdmin

Now that Apache2 and PHP are installed the final step is to install phpMyAdmin and configure. To do that, run the commands below

sudo apt-get install phpmyadmin php-gettext

When prompted to choose the webserver, selecat apache2 and continue.

+------------------------+ Configuring phpmyadmin +-------------------------+
 | Please choose the web server that should be automatically configured to   |
 | run phpMyAdmin.                                                           |
 |                                                                           |
 | Web server to reconfigure automatically:                                  |
 |                                                                           |
 |    [*] apache2                                                            |
 |    [ ] lighttpd                                                           |
 |                                                                           |
 |                                                                           |
 |                                 <ok>                                      |
 |                                                                           |
 +---------------------------------------------------------------------------+

When prompted again to allow debconfig-common to install a database and configure select No.

 +------------------------+ Configuring phpmyadmin +-------------------------+
 |                                                                           |
 | The phpmyadmin package must have a database installed and configured      |
 | before it can be used.  This can be optionally handled with               |
 | dbconfig-common.                                                          |
 |                                                                           |
 | If you are an advanced database administrator and know that you want to   |
 | perform this configuration manually, or if your database has already      |
 | been installed and configured, you should refuse this option.  Details    |
 | on what needs to be done should most likely be provided in                |
 | /usr/share/doc/phpmyadmin.                                                |
 |                                                                           |
 | Otherwise, you should probably choose this option.                        |
 |                                                                           |
 | Configure database for phpmyadmin with dbconfig-common?                   |
 |                                                                           |
 |                  <Yes>                   <No>                             |
 |                                                                           |
 +---------------------------------------------------------------------------+

After installing, run the commands below to logon to the database server to enable phpMyAdmin root logon.

Now, open your web browser and login to the server hostname or IP address followed by phpmyadmin

ex. http://example.com/phpmyadmin

phpmyadmin logon page on ubuntu

Logon with MySQL root account you created earlier…

That’s it!

You may also like the post below:

Nginx Setup with PHP 7.1 on Ubuntu 18.04 LTS Server

14 Replies to “Install phpMyAdmin, Apache2 and MySQL on Ubuntu 18.04 LTS Server

  1. I can not access http://localhost/phpmyadmin/
    username and password: root
    mysqli_real_connect(): (HY000/1698): Access denied for user ‘root’@’localhost’

    in the installation does not request user data…. you help me?

  2. @Carlos. since mysql 5.7 this has changed. root access is not longer possible from first install. Create a new mysql user from ssh for it
    example user: phpmyadmin / example password: 12345 (change to your own usage)
    run every line below as separate command

    sudo mysql –user=root mysql
    CREATE USER ‘phpmyadmin’@’localhost’ IDENTIFIED BY ‘12345’;
    GRANT ALL PRIVILEGES ON *.* TO ‘phpmyadmin’@’localhost’ WITH GRANT OPTION;
    FLUSH PRIVILEGES;

  3. after all this great info, go to termianl and type

    sudo ln -s /usr/share/phpmyadmin /var/www/html/phpmyadmin

    them go to window and type localhost/phpmyadmin

    works for me

    1. Thanks but after i ran the command, it worked but its showing this – The mysqli extension is missing. Please check your PHP configuration. See our documentation for more information.

    2. i thank you very much. like extremely much. phpmyadmin will only open unless i connected to the internet until i run the command
      ‘sudo ln -s /usr/share/phpmyadmin /var/www/html/phpmyadmin’
      to be able to work offline.
      be blessed and stay blessed.

  4. Hahaha, You copy from other source. Not correct in Ubuntu 18.04. Not provice password when install MYSQL

  5. mysqli_real_connect(): (HY000/1045): Access denied for user ‘phpmyadmin’@’localhost’ (using password: YES)

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: