What is LAMP stack?
LAMP stands for Linux - Apache - MySql - PHP. This is basically everything you need to have a fully working testing server on your machine. Some parts of LAMP may already be installed on your system. If so uninstall them. I will assume, that nothing is installed, and we will install all parts of LAMP. The following steps should be same and compatible with all Debian based systems (Ubuntu is one of them). We will use Advanced Packing Tool (APT) to install these tools, rather than compiling them from code sources.
We already have Linux, so now we will install:
- Apache 2.4, the web server which will serve the requests and responses
- PHP 7.3, the engine which will process the request and return dynamic responses
- MySQL 5.7, the database to store and read data from.
Installing Apache 2.4
We will add Personal Package Archive (PPA) as the standard APT repository has some ancient version of Apache. I think they do this on purpose as having old but stable versions of tools in repository offers backwards some compatibility with other older tools. However, we as web developers understand that older versions have a lot of bugs and are also slower, therefore we will try to use the newest tech. Type in terminal following three lines:
sudo add-apt-repository ppa:ondrej/apache2 sudo apt-get update sudo apt-get install apache2
The above code added repository from
ondrej/apache2 into our local APT repository index. Ondrej repo contains usually
the latest versions of apache2 and I use it personally for few years also in productions environments. After adding
this PPA to the list of repositories, we have to run
update, so that the system will pull down the latest list of
software from each archive it knows about, including the PPA you just added. Finally, we can
install apache2 from
the repository. To check the version of installed Apache server, run in terminal:
At the time when I updated this document (6th Feb 2019) the apache2 version in this repository is
2.4.37, see bellow:
Server version: Apache/2.4.37 (Ubuntu) Server built: 2018-10-28T15:27:08
Installing PHP 7.3
Installing the PHP is very similar to Apache. Again we will add the PPA from
ondrej, who maintains these packages
regularly and compiles the source, so that we don’t have to compile. Currently, there are different packages we could
use. Just forget any version of PHP below 7, they are too old. Even the version 7.0 is too old and has received last
security fixes on 1st of January 2019. I mention them just in case somebody will need to work on some older project.
Ideally use PHP 7.3 version which is currently in stable version and will be supported until end of 2022.
Check PHP Supported version for more details.
|PHP Version||Personal Package Archive|
|PHP 5.6, 7.0, 7.1, 7.2, 7.3||ppa:ondrej/php|
Today we will use the PHP in version 7.3, so type in terminal:
sudo add-apt-repository ppa:ondrej/php sudo apt update sudo apt install php7.3
The above code will
add the repository
ppa:ondrej/php to our system, then we
update the system with list of
packages in repositories and finally
install php7.3 package. We are done with PHP and we can check the version of
installed PHP with
Mine installed version is 7.3.1
PHP 7.3.1-3+ubuntu18.04.1+deb.sury.org+2 (cli) (built: Feb 5 2019 12:10:30) ( NTS ) Copyright (c) 1997-2018 The PHP Group Zend Engine v3.3.1, Copyright (c) 1998-2018 Zend Technologies with Zend OPcache v7.3.1-3+ubuntu18.04.1+deb.sury.org+2, Copyright (c) 1999-2018, by Zend Technologies
In case you want to play with different versions and for example install version 7.2, you will need to:
- remove the php7.3 package
- install the php 7.2
The above steps would be:
sudo apt remove php7.3 sudo apt install php7.2
PHP can be extended with modules, like xdebug. If you want to check what modules are installed,
and some install examples are:
sudo apt install php7.3-xdebug # or sudo apt install php7.3-soap php7.3-curl php7.3-mbstring php7.3-dom php7.3-bcmath php7.3-mysql
Installing MySQL 5.7
LAMP stack uses the MySQL server as the database. The database servers usually runs on different server as the apache webserver, because of the performance requirements, but for our development environment, we can have mySQL on same system.
This time we don’t need to add repository as the mysql 5.7 is the default version. We just
update the list of software
in repository and then
install mysql-server. I will now install mySQL 5.7:
sudo apt-get update sudo apt-get install mysql-server
After this, the mysql server is installed, but you will need to make initial set up.
You will be asked to provide password for the
root user during installation. I usually set something simple
toor), as this database will be only on your local machine. To check the installed version type in
sudo mysql -u root -p
That will login you into mysql console and the welcome screen will show you the version. Mine mysql showed version 5.7.25:
stefan@ubuntu:~/$ sudo mysql -u root -p Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 7 Server version: 5.7.25-0ubuntu0.18.04.2 (Ubuntu) Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
exit to exit the mysql console and go back to terminal.
The development environment
The development environment is now ready and you have LAMP stack ready to be used. If you visit http://localhost in your favourite browser now, you will see the Apache2 Default Page.