0 Comments // Reading Time: 6 min.
LAMP is a collection of tools needed to serve Web pages through a Web server.
LAMP is an acronym which stands for
L – Linux (in our case Ubuntu 18.04)
A – Apache (a Web server)
M – MySQL (a Database System)
P – PHP (a Programming Language Interpreter)
Sometimes the P also stands for Python and/or Perl but in our case, we use it as PHP.
With this Tech-Stack, we are able to serve websites on the Internet.
On Ubuntu, we use the APT (Advanced Packaging Tool) to install components on the system.
For this to happen we need full or temporary root rights. On most Systems you can use sudo to issue commands on behalf of the root user, if you cant use sudo and don't have access to the root account on your Server please ask your Systems Administrator to grant you the necessary permissions or login data.
For this article, we assume that you have access to the sudo command and will use it further on.
If you run into any problems while working through this article resolve them first using Google or leaving a comment below before doing any further steps.
We need access to a shell on the server which will be configured. This can be a remote shell e.g. via SSH or a local shell if you like to install LAMP on the Machine you are working on.
But before we start installing and configuring any packages or services we have to make sure our package lists and installed packages are up to date to prevent issues regarding outdated packages.
To achieve this we use the update and upgrade command of apt
sudo apt update && sudo apt upgrade
During the upgrade task, you might be asked if you want to continue installing new packages. Answer this question with Y
After upgrading all installed packages we can start installing the components needed for the LAMP stack. As this is a common task we can use predefined package lists using the tasksel tool.
First, we install tasksel with
sudo apt install tasksel
after this, we can use it to install every necessary package for the LAMP stack using
sudo tasksel install lamp-server
this will install the Apache Server, MySQL Database, and PHP Interpreter. It will also activate the needed mods for the Apache to serve PHP files and PHP modules to access MySQL Databases.
If you now point a browser to the servers IP or Domain you should be greeted with this screen.
As you can read in the part "Document Roots" of that page you can start creating your own sites under /var/www/ the only problem now is that all files in this directory are owned by root. For security reasons you should run the following commands
sudo chown -R www-data:www-data /var/www
This will set the owner and the group permissions of the folder and everything inside of it to www-data which is a user and group the Apache Server can serve files with.
As we used tasksel we don't really need to configure any PHP related files. If you wish you can take a look at
for the general PHP configuration or inside
for module specific configurations which are used by the Apache Server.
Now you can configure MySQL Databases with the help of the MySQL-Client which is simply called by using the command
if you just use this command without parameters you will most likely get an error message like
ERROR 1045 (28000): Access denied for user 'username'@'localhost' (using password: NO)
To connect to the MySQL service you first have to secure your installation. To secure a MySQL service we first need to be the root user.
Since Ubuntu 18.04 it is not possible to do this next step via sudo or specifying the root user on the command line.
Become the root user by using
this command should drop you into a root shell where you can use
Follow the instructions to secure your installation. Most of the questions can be answered with yes. When asked for the password validation strength you should use the STRONG setting.
During this step, you will also get asked for a MySQL root password twice. Make sure to choose your password wisely and save it to some safe place that only you have access to.
If you now execute
You will end up in a MySQL shell where you can send commands to the MySQL service to manage databases. It might look like this
Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 5 Server version: 5.7.23-0ubuntu0.16.04.1 (Ubuntu) Copyright (c) 2000, 2018, 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. mysql>
To create a database for example you need to enter
CREATE DATABASE name_of_the_database;
Here we choose to name our newly created database name_of_the_database. Which we now can use in e.g. Websites to store data.
If you want to remove a database you can simply use the command
DROP DATABASE name_of_the_database;
But pay attention as this command will not ask you if you are sure to delete the database. So be careful which database name you put in here.
To exit the mysql-shell you simply write
and press enter. This will drop you back into the shell you came from.
Now you are still logged in as root user. So execute another
To get back to your regular user shell.
In the lifetime of the Server you might need to start, stop or restart services like the Apache Server or the MySQL Database.
To do this you use the service command.
To stop the Apache Server you use
sudo service apache2 stop
To start it again use
sudo service apache2 start
and to do this in one step you can simply use
sudo service apache2 restart
For other services like the MySQL Database you simply change apache2 in the commands above to mysql.
And thats it. You have a full featured Webserver with a database and PHP Interpreter running.
Now you can install your favourite CMS or start serving files on your server.
In the next article I'll show you how to install TYPO3 on this setup and get everything going.
We are a digital agency specialized in the development of digital products. Our head office is in Munich/Unterföhring - but we work remotely worldwide. Our specialities are websites and portals with TYPO3, e-commerce projects with shopware and iOS and Android apps. In addition, we are also familiar with many other topics in these areas. Contact us in your preferred way: Whether by contact form, e-mail, telephone or in a Whatsapp message.