Freedom, Community & Sustainability

1 - Install LAMP (Linux, Apache, MySQL & PHP)

October 24, 2014 -- William
Last modified on December 2017
Duration: +- 1 hour

Installing the LAMP stack can be a bit time-consuming but will be the most important part of this tutorial. Linux is the operating system that you will install on your computer or virtual machine, Apache is a popular web server, MySQL and PHP are the most popular technologies for running sites like Drupal, Worpress or Joomla.

Install the Operating System (Debian GNU/Linux 7)

To install the operating system we will download Debian 7 small disk image from debian.org. Under "Small CDs" you will find links for many architectures. The most common are amd64 for the 64bit computers and i386 for the 32bit architectures. If in doubt, chose i386, they work on both cases.

Then put that disk image in a CD or pendrive. You can't just copy the disk image, you have to burn it in the CD or use a program that creates a bootable pendrive from a disk image. I'd recommend to use a pendrive since CD become outdated very fast. You can see how to do that on this link there are instructions for Windows and Mac at the very bottom. If you are already running Linux you can use the Unetbootin utility.

Once this is done, boot the computer from it. If it doesn't recognize the CD or USB you have to tell your current system to boot from either the CD or USB. When you turn on your computer you will see a short message appear on the screen telling you to press a key (usually F2, F10 or Del) to enter the configuration screen. Since every boot config is different I can't give a step by step instruction but you should find easily a place where it says something like "Boot from drive: HD or CD or USB". Choose the right one, save and reboot.

The Debian installer will start and guide you through the installation. At a certain point it will ask you if you want to install a web server, PHP or MySQL. We will not chose these options, we will install them manually to know every step of the way. Additionally, we will not install a graphical interface! It is useless to have a GUI in a server. It may take some time to download and install everything and the installer might ask some questions along the way but it's pretty self-explanatory and straight forward.

One last step after the installation is to check if you have SSH installed. SSH allows you to connect to your server remotely through the command line. Since I told not to install anything optional, chances are you don't have it. Just run the following command, if it's installed the computer will tell you.

apt-get install openssh-client openssh-server

If you have problems with this command, check that you are logged in as user "root", also called Super User. At this point, it's a good thing to log in as root because we will perform administrative tasks. After configuring everything, avoid using the root user for mundane tasks since the root user has the power to do a lot of damage to the system too.

Install the web server (Apache 2)

Installing apache is just as easy as installing SSH. Enter the following command:

apt-get install apache2

To finish up the installation of Apache we will install some programs that we will need along the way. These programs are Apache modules, scripting languages and the date updater. Although the command will appear in several lines in this web page, it should be just one long line of code in your terminal.

apt-get install perl libapache2-mod-perl2 python libapache2-mod-python libapache2-mod-rpaf curl ntp

Then activate the Apache modules! SSL is for secure connections (https://), expires is used to expire requests, headers and rewrite are for clean URLs.

a2enmod ssl expires headers rewrite

Remember to restart the server every time you change something otherwise the changes won't take effect. We don't need to do that now since we will be doing it later on but do it anyway to get into the habit.

sevice apache2 restart

Install the database (MySQL/MariaDB)

MySQL or MariaDB are basically the same thing. We will use MySQL because the name may sound more familiar to all...

apt-get install mysql-server mysql-client

During installation it will ask you for a master password to log into the database, make this password secure! Remember that we will connect this machine to the Internet later on. You won't need that password very often so write it down! (we have a tutorial about password managers if you need help with that).

Install the programming language (PHP5)

This time we will put everything into one command because we have a bunch of stuff to install. They are all related to PHP and the things we want to do with it like connecting to a database, encrypting stuff, dealing with mail, improving performance and so on.

apt-get install php5 php-pear php-apc php5-mysql php5-sqlite php5-curl php5-mcrypt php5-gmp php5-imap php5-intl php5-ming php5-ps php5-pspell php5-recode php5-tidy

That's it! we have finished the installation of the LAMP stack! Congratulations! Now let's get it going with additional services that will make our life easier.

Add new comment