• Office Hours:

    10:00 AM to 5:00 PM IST

  • Call:

    +919986158351

  • Mail Us
assembling boxes graphic design

Install PhpMyAdmin, Apache2 and MySQL on Ubuntu 16.04 LTS Server

I have seen many people struggling while installing the proper server setup to use either PHP or WordPress on Linux. Even though Linux is a better choice for developers, it’s a grinding process for the beginners to set up the environment and dependencies. In this post, I will provide a step-by-step guide to setting up the basic server configuration where we can run PHP and WordPress.

To get started, continue with the steps below:

Step 1: Install MySQL Database Server

Run the following commands on terminal 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 Web Server

sudo apt install apache2

Step 3: Configure Apache2

Run the command below to check and set up the basic configurations.

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. Access the file using any text editor, either “nano” or “gedit”, whichever is available. Here I am using “gedit” as it is easy for me to use.

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

Make sure “index.php” is included as a DirectoryIndex in “dir.conf” file.

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

Now, this part of the step is optional, configure your domain or server name for your local machine site.  Open Apache2 default site config file by running the commands below:

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

Then add server name and server alias 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 command 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 installing PHP and other related scripts, run the command below to enable Apache2 to use PHP

sudo a2enconf php7-cgi

Reload Apache2

sudo service apache2 restart

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 install phpmyadmin php-gettext

When prompted to choose the web server, select apache2 and continue

When prompted again to allow “debconfig-common” to install a database and configure, select “No

After installing, now we need to add phpMyAdmin to the Apache2 server. To do this, open apache2.conf configuration file by typing the below code:

sudo gedit /etc/apache2/apahce2.conf

Then add the following line anywhere inside the file (make sure there is no ‘#’ at the beginning of the line):

Include /etc/phpmyadmin/apache.conf

Now open your web browser and login to phpMyAdmin by typing server hostname followed by phpmyadmin.

Logon with MySQL root account you created earlier.

That’s it folks! Did it work?

If you face any issues, leave a comment and I will try to resolve it for you.

Leave a comment

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