Installing LAMP (Linux, Apache, MySQL and PHP) On Linux Mint 17.3

If you’re a website designer who uses PHP, mySQL and Apache to build sites, you’ll need to install these applications on your computer in order to run your sites locally. I recently set up a Linux machine with Mint 17.3 and Mate, and found that the tutorial I followed was very helpful but missed out a few items which it took me some time to figure out.

What follows is a slightly modified tutorial which describes what worked for me.

Install Apache

Begin by installing the Apache web server.

  1. Open the Terminal, either by clicking the shortcut at the bottom left of the screen, or by clicking Menu > Applications > System Tools > Terminal.
  2. Copy/Paste or type the following line of code into Terminal and then press Enter:
sudo apt-get install apache2
  1. The Terminal will ask for your password, type it and then press Enter.

Testing Apache

  1. Open a web browser and enter the following web address:
http://localhost/

This should show you a default web page which says “It works” and gives information about Apache.

File location and permissions

Any web files you want to view in a browser should be placed in the following folder:

/var/www/html

For example if you put a file index.php into /var/www/html, you can browse to it at localhost/index.php.

The var folder is at the root of the file system and is owned by root, not by the username with which you logged in to the computer. This means that only the root user can edit files in the html folder. Don’t worry, you can change this.

You can right-click on the html folder in Explorer and choose “Open as administrator”, and then you’ll be able to edit files in the folder. However this won’t allow Fireftp or other software installed by you to edit the files, so it’s not the best solution.

Instead, make yourself the owner of the html folder. You can do this through the GUI:

  1. Open the folder as administrator.
  2. Right-click the HTML folder and choose Properties.
  3. Choose the Permissions tab.
  4. Change Owner to be your username.

This is fine if you have not yet added any files or subfolders to html. However if you have added content to the html folder, you will need to change the owner recursively and the GUI button for this “Apply permissions to Enclosed Files” doesn’t work. This seems to be a known bug and it is not clear to me why it has not been either fixed or the button removed. Fortunately the command line interface (CLI) is reasonably easy to use.

  1. In Terminal, enter the following code:
sudo chown yourusername /var/www/html -R

This will recursively make you the owner of html and all the files and folders it contains. Test this by opening html in file explorer without choosing “Open as administrator” and check that you can create a blank file.

Install PHP

The next step is to install PHP 5.

  1. Enter the following code into Terminal:
sudo apt-get install php5 libapache2-mod-php5
  1. Restart Apache by entering the following code into Terminal:
sudo /etc/init.d/apache2 restart

Test PHP

Create a test PHP file and open it in a browser.

  1. If you have the text editor ‘gedit’ installed, you can enter the following code in Terminal:
sudo gedit /var/www/html/testphp.php

However this doesn’t test whether you’ve correctly set the permissions on the html file, and you may not have gedit on your system. So instead, you can do this:

  1. Open the file explorer and browse to /var/www/html
  2. Create a new file testphp.php
  3. Open your new file in a text editor.
  4. However you created testphp.php, now enter the following text and save the file:
<?php phpinfo(); ?>
  1. In a web browser, navigate to the following web address:
http://localhost/testphp.php

This should show a page with information about your php, confirming that you’ve installed both Apache and PHP.

Install MySQL

MySQL is the last element that will allow you to test sites built with MySQL, such as WordPress sites.

  1. In Terminal enter this code:
sudo apt-get install mysql-server
  1. Optionally, configure your system so other computers on your network can view the server you have created. First open the file /etc/mysql/my.cnf. Remember to open the containing folder as administrator so you can edit the file.
  2. Find this line in the file:
bind-address = 127.0.0.1
  1. Change 127.0.0.1 to your IP address (type ifconfig in Terminal to find our your IP address).
  2. Save the file.

You may have been asked to specify a password for MySQL in the install stage, but if you did not, you can set the password by entering the following code in Terminal:

mysql -u rootmysql>
SET PASSWORD FOR 'root'@'localhost' = PASSWORD('yourpassword');

Replace ‘yourpassword’ with a password of your choice.

Install phpMyAdmin

phpMyAdmin is a web interface for editing your MySQL databases.

  1. To install phpMyAdmin, enter the following code in Terminal:
sudo apt-get install libapache2-mod-auth-mysql php5-mysql phpmyadmin
  1. To make PHP work with MySQL, first open the file /etc/php5/apache2/php.ini.
  2. Find the following line in the file (there may be spaces after the semicolon):
;extension=mysql.so
  1. Uncomment the line by removing the semicolon so it looks like this:
extension=mysql.so
  1. Now restart Apache again:
sudo /etc/init.d/apache2 restart
  1. In a browser, visit this URL:
http://localhost/phpmyadmin
  1. If you get a 404 error you need to configure Apache to work with phpMyAdmin. Open the file /etc/apache2/apache2.config.
  2. Add the following line at the bottom of the file and save it:
Include /etc/phpmyadmin/apache.conf
  1. Restart Apache again and fingers crossed, it will all work:
sudo /etc/init.d/apache2 restart

Congratulations! You’re now ready to develop websites with PHP and MySQL.