How to Install LAMP with Apache, PHP 7 and MariaDB 10 on Ubuntu 16.04 Server

Step 3: Install MariaDB 10 in Ubuntu 16.04

11. Now is time to install MariaDB database with the necessary PHP modules in order to use and access the database from Apache-PHP interface by issuing the below command on your machine console.

$ sudo apt install php7.0-mysql mariadb-server mariadb-client
Install MariaDB 10 in Ubuntu 16.04
Install MariaDB 10 in Ubuntu 16.04

12. After the installation of MariaDB is complete, run the below security script witch will secure the database (set a root password and answer with yes on all the questions in order to remove anonymous access, disable root login remotely and delete the test database).

$ sudo mysql_secure_installation
Secure MariaDB in Ubuntu 16.04
Secure MariaDB in Ubuntu 16.04

13. In order to setup or change MariaDB so that ordinary users can access the database without system sudo privileges, enter to MySQL command line interface with root privileges and issue the below commands:

$ sudo mysql 
MariaDB> use mysql;
MariaDB> update user set plugin=’‘ where User=’root’;
MariaDB> flush privileges;
MariaDB> exit
Assign User Permissions to MariaDB
Assign User Permissions to MariaDB

Then, restart MySQL service and try to login to database without root privileges by executing the below commands:

$ sudo systemctl restart mysql.service
$ mysql -u root -p

Step 4: Install PhpMyAdmin in Ubuntu 16.04

14. Optionally, if you need to manage MySQL database from a web graphical interface (which we don’t recommend on production servers) install Phpmyadmin package by running the below command.

$ sudo apt install php-gettext phpmyadmin

During the installation choose to automatically configure phpmyadmin with apache2 web server, choose No on Configure database for phpmyadmin with dbconfig-common and setup a strong password for the web interface.

Configure PhpMyAdmin with Apache
Configure PhpMyAdmin with Apache
Configure PhpMyAdmin with root Password
Configure PhpMyAdmin with root Password

15. Finally, after the installation of phpmyadmin package finishes you can access Phpmyadmin web interface by visiting the below URL:

https://your_server_IP_address/phpmyadmin/ 
PhpMyAdmin Web Interface
PhpMyAdmin Web Interface
PhpMyAdmin Dashboard
PhpMyAdmin Dashboard

That’s all! Now you have a fully LAMP stack environment installed and running on Ubuntu 16.04, which allows you to create and deploy dynamic websites on your server.

Hey TecMint readers,

Exciting news! Every month, our top blog commenters will have the chance to win fantastic rewards, like free Linux eBooks such as RHCE, RHCSA, LFCS, Learn Linux, and Awk, each worth $20!

Learn more about the contest and stand a chance to win by sharing your thoughts below!

Matei Cezar
I'am a computer addicted guy, a fan of open source and linux based system software, have about 4 years experience with Linux distributions desktop, servers and bash scripting.

Each tutorial at TecMint is created by a team of experienced Linux system administrators so that it meets our high-quality standards.

Join the TecMint Weekly Newsletter (More Than 156,129 Linux Enthusiasts Have Subscribed)
Was this article helpful? Please add a comment or buy me a coffee to show your appreciation.

8 Comments

Leave a Reply
  1. I got everything installed but phpmyadmin is in /etc instead of /var/www/html where it should have gone to I think. Also it didn’t accept my password for root. Can I reinstall phpmyadmin somehow? When I run the command for installing it, it tells me that it’s already the newest and cannot be upgreaded.
    Thank you.

    Reply
    • Use sudo dpkg-reconfigure phpmyadmin. No, by default, phpmyadmin installed from binaries does not use /var/ww/html directory for installation and uses /etc only for configuration . The source files reside in /usr/share/phpmyadmin usually.

      Reply
      • I get the following error message when running the command you advised.

        ┌────┤ Configuring 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 may 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. │
        │ * ignore – Continues the operation ignoring dbconfig-common errors. │
        │ This will usually leave this package without a functional database. │
        │ │
        │ Next step for database installation: │
        │ │
        │ abort │
        │ retry │
        │ retry (skip questions) │
        │ ignore │
        │ │
        │ │
        │ │
        │ │
        └───────────────────────────────────┘

        Reply
        • Choose retry (skip questions). If there are still issues with phpmyadmin, then completley remove the package with sudo apt remove –purge phpmyadmin and manually install phpmyadmin from sources.

          Reply
  2. Found my problem , I did not execute this script because the purpose was not clear for me. After replacing the quote ’ by ‘ , I can execute those commands. Access to phpmyadmin is OK now, but I still don’t know why ;-)
    $ sudo mysql
    MariaDB> use mysql;
    MariaDB> update user set plugin=’‘ where User=’root’;
    MariaDB> flush privileges;
    MariaDB> exit

    Reply
    • Probably because you’ve used copy-paste the commands from here directly on mysql prompt. Always enter commands manually and pay attention to syntax, especially quotes.

      Reply
  3. Hi
    For phpmyadmin, if you “choose No on Configure database for phpmyadmin with dbconfig-common ” , you cannot “setup a strong password for the web interface”. You have to say YES then you can enter password.
    By the way, nice tutorial, even if I miss some explanation. At the end, just login into phpmyadmin gave me problem, as root or my user, can’t login.
    I will have to restart and look what is the problem,
    Thanks for your work
    Philippe

    Reply

Got Something to Say? Join the Discussion...

Thank you for taking the time to share your thoughts with us. We appreciate your decision to leave a comment and value your contribution to the discussion. It's important to note that we moderate all comments in accordance with our comment policy to ensure a respectful and constructive conversation.

Rest assured that your email address will remain private and will not be published or shared with anyone. We prioritize the privacy and security of our users.