Setting Up a Web Development Server – Part 6 – Installing PhpMyAdmin
Image sourced from WebLife.
In Part Five, we installed and configured Varnish Caching and Memcached. Part Six, the last part of the series, we will be installing and configuring PhpMyAdmin. PhpMyAdmin is a web-based tool that makes it easier to manage databases – besides using the bash shell.
Before we begin installation, we need to enable the ‘rewrite’ module for Apache – to do this, run the following command: a2enmod rewrite. To inform Apache of the change, restart Apache with the following command: service apache2 restart.
To begin installing PhpMyAdmin, run the following command: apt-get install phpmyadmin. If prompted to continue, press the y key then the Enter key. You will then be taken through an installation process with several prompts…
Press the Enter key to move to the next step.
This step will ask if we want to use a utility called dbconfig-common to configure the database – select Yes and press the Enter key to proceed. You will then be prompted to enter the password for the database administrator (in our case, this is root). Enter the password (debian), then press the Enter key to proceed.
The next step will ask you to enter a password for phpmyadmin to use with the database. We will use debian as our password – type this in and press the Enter key to proceed. Enter the password and press the Enter key again to confirm the password. This should complete the initial setup; however, we need to configure some extra settings before the installation is fully complete.
To proceed with the installation, we will need to add PhpMyAdmin to Apache configuration. Open the configuration file by running the following command: vim /etc/apache2/apache2.conf. Scroll down to the bottom of this file, and add the following line: Include /etc/phpmyadmin/apache.conf. The bottom of the apache2.conf should look like this:
Save the changes and exit out of the file.
To update the new changes for Apache, run the following command: service apache2 restart.
To access our PhpMyAdmin installation, visit the following URL in your browser: localhost:8888/phpmyadmin. If the installation process went well, you should see the following in your browser:
To make sure we can login, enter the following credentials and click on the Go button:
- Username: root
- Password: debian
If all goes well, you should be logged in and shown something like the image below:
IMPORTANT: Do not make PhpMyAdmin publically accessible, and use a better password combination (than the one used here) on your server.
To finish off the PhpMyAdmin installation for this guide, we will be implementing an example security measure – using .htaccess authentication to block unauthorized access to PhpMyAdmin.
To begin implementing these measures, we will need to make a change to PhpMyAdmin’s Apache configuration. Enter the following command to open the file: vim /etc/phpmyadmin/apache.conf. You should see something like the following in the top half of the file:
Just below the line ‘DirectoryIndex index.php’, enter the following: AllowOverride All. The file should now look like the following:
Now create a directory to store the password file (needed later on) by running the following command: mkdir /var/passwords. With that directory created, create an .htaccess file in our phpmyadmin directory with the following command: vim /usr/share/phpmyadmin/.htaccess. In this new file, enter the following information:
AuthType Basic AuthName "These are restricted files, please authenticate yourself" AuthUserFile /var/passwords/.htpasswd Require valid-user
Below describes each of the lines:
- AuthType: This defines the type of authentication to be used. By using ‘Basic’, we will be using HTTP authentication.
- AuthName: This is what will be displayed with the password prompt.
- AuthUserFile: This is the path to the password file we will be using.
- Require valid user: This means only users defined in the password file can access PhpMyAdmin.
Your new .htaccess file should now look like the following:
Now it is time to create the password file mentioned in the .htaccess file. To do this, run the following command: htpasswd –c /var/passwords/.htpasswd root – where root is our username. This will open a prompt which will ask us to enter and confirm our password. You should see something like the following:
For our installation, we will use debian as our password. Once you have entered and confirmed the password, you should see something like this:
Restart Apache to finalize the changes.
To see if this works, clear your browsers history and cache, and visit localhost:8888/phpmyadmin in your browser. You should be seeing something like the image below:
Enter root as the user and debian as the password, then click on the Log In button. If the setup went well, you should now be shown the login screen for PhpMyAdmin. If you like, you can login to PhpMyAdmin to see if it still works – user is root, and debian for the password.
This concludes the PhpMyAdmin installation, and also the entire guide
Part Six and Guide Conclusion
During this whole guide, we have achieved the following tasks:
- Creating a virtual machine with VirtualBox.
- Installed Debian (version 7.7) as our virtual machine’s operating system.
- Installed Vim as our chosen text file editor (feel free to change this).
- Installed Git (useful for version control and retrieving other Git-based repositories).
- Installed SSH.
- Forwarded ports (to mitigate port-related conflicts).
- Accessed our development machine via Git Bash.
- Accessed our development machine’s file system via SFTP and FileZilla.
- Installed and configured a L.A.M.P stack – with Apache version 2.2.22, PHP version 18.104.22.168, and MySQL version 5.6.21.
- Installed and configured Memcached and its dependencies.
- Installed and configured PhpMyAdmin, with basic security implementation.
This guide is only an example of creating a web development virtual machine. You can install any available tool you require for your particular needs – e.g. Ruby on Rails, Node.js, Node Package Manager, and many more. Feel free to post your (constructive) feedback and suggestions for each part of this guide, and share it around via social media etc. Feel free to contact me if you have any queries about this particular guide.