UpCloud
Effortless global cloud infrastructure for SMBs
Introducing
If you’re interested in what we have to offer, contact sales or fill out a contact form.
Our support live chat is available for our customers 24/7. You can also email our support team.
Send us an email to give feedback or to say hello.
Start a new journey
Why Partner with UpCloud?
I’ve been passionate about the hosting industry since 2001. Before founding UpCloud, my first company grew to become one of Finland’s largest shared web hosting providers, serving over 30,000 customers. Along the way, I faced the same challenges many of you know well—24/7 on-call responsibilities, solving technical issues, and managing customer inquiries.
At UpCloud, we’ve designed a platform that solves these challenges, offering reliability, scalability, and unparalleled support. We understand the pressures you face because we’ve been there too. Partner with us, and let’s help you focus on growing your business while we handle the rest.
Sincerely, Joel Pihlajamaa CTO, Founder
Login
Sign up
Updated on 7.2.2025
LAMP stack is a simple yet popular suite of widely supported web server software. It commonly refers to the combination of Linux, Apache, MySQL and PHP. LAMP stack makes a great starting point for users who want to get a web server running quickly and easily on their new cloud server.
In this guide, we’ll walk you through the steps required to install a basic web server using Ubuntu 20.04, Apache2, MariaDB and PHP. Together, these form a reliable LAMP stack and the groundwork for building websites! The steps in this guide are written for use with a newly deployed Ubuntu 20.04 UpCloud Cloud Server. The steps and installed software may vary on other platforms.
To begin with, you need a cloud server to run the LAMP stack software. If you are new to UpCloud, have a look at our quick-started guide for deploying your first cloud server and how to connect to it.
Once you have your cloud server up and running and connect to it using SSH, you can get started!
First of all, ensure everything is up to date on your server:
sudo apt update sudo apt upgrade
Now open ports 22 (for SSH), 80 and 443 and enable Ubuntu Firewall (ufw):
sudo ufw allow ssh sudo ufw allow 80 sudo ufw allow 443 sudo ufw enable
Install Apache using apt:
sudo apt install apache2
Confirm that Apache is now running with the following command:
sudo systemctl status apache2
You should then get an output showing that the apache2.service is running and enabled.
● apache2.service - The Apache HTTP Server Loaded: loaded (/lib/systemd/system/apache2.service; enabled; vendor preset: enabled) Active: active (running) since Tue 2020-11-03 10:32:26 UTC; 1min 6s ago Docs: https://httpd.apache.org/docs/2.4/ Main PID: 52943 (apache2) Tasks: 7 (limit: 2282) Memory: 11.9M CGroup: /system.slice/apache2.service ├─52943 /usr/sbin/apache2 -k start ├─52944 /usr/sbin/apache2 -k start ├─52945 /usr/sbin/apache2 -k start ├─52946 /usr/sbin/apache2 -k start ├─52947 /usr/sbin/apache2 -k start ├─52948 /usr/sbin/apache2 -k start └─52953 /usr/sbin/apache2 -k start
Once installed, test by accessing your server’s IP in your browser:
http://YOURSERVERIPADDRESS/
You should see a page with an “Apache2 Ubuntu Default” header showing that Apache2 has been installed successfully. If you do not see this, please ensure that the previous commands in this section have been completed without error
PHP 7.4 is the latest available right now so let’s install that along with some regularly used modules:
sudo apt install php7.4 php7.4-mysql php-common php7.4-cli php7.4-json php7.4-common php7.4-opcache libapache2-mod-php7.4
Check the installation and version:
php --version
Restart Apache for the changes to take effect:
sudo systemctl restart apache2
Create a phpinfo.php test page:
echo '<?php phpinfo(); ?>' | sudo tee -a /var/www/html/phpinfo.php > /dev/null
Test everything is working by accessing the following in your browser:
http://YOURSERVERIPADDRESS/phpinfo.php
You should see a PHP Version 7.4.3 page listing all of your PHP options. If you don’t or it tries to download a file, double-check that all of the above steps have been completed without error.
Once you’ve confirmed that PHP is working correctly, delete the test file.
sudo rm /var/www/html/phpinfo.php
The information displayed in the PHP info could be used to find an attack vector against your web server so best not to leave it publicly accessible.
MariaDB is a fork of MySQL from some of the original MySQL team and is a drop-in replacement. We’ll be using this over MySQL itself in this guide!
Install the required packages:
sudo apt install mariadb-server mariadb-client
Once installed, check it’s running correctly:
sudo systemctl status mariadb
You should see an output similar to the example below.
● mariadb.service - MariaDB 10.3.25 database server Loaded: loaded (/lib/systemd/system/mariadb.service; enabled; vendor preset: enabled) Active: active (running) since Tue 2020-11-03 10:33:12 UTC; 4s ago Docs: man:mysqld(8) https://mariadb.com/kb/en/library/systemd/ Main PID: 53554 (mysqld) Status: "Taking your SQL requests now..." Tasks: 31 (limit: 2282) Memory: 65.9M CGroup: /system.slice/mariadb.service └─53554 /usr/sbin/mysqld
Secure your newly installed MariaDB service:
sudo mysql_secure_installation
As you have no root password set for MariaDB you should simply press Enter when prompted, pressing Y on the next question to then set a root password (keep this safe and secure!) With that set, you can press Enter for the remaining questions as the defaults for each of these will help to secure your new installation.
Congratulation! You should then have a functioning LAMP stack web server with Linux, Apache, MariaDB and PHP set up and running! You are now ready to start building your website.
Join discussion
20.3.2021 at 23.44
Nice Tutorial! Clear and focus on the task. Thank you!
8.4.2021 at 21.17
Excellent tutorial, very clean, lean and to the point. Well done.
9.4.2021 at 17.21
Thanks for your supereasy to follow tutorial help me alot
18.4.2021 at 07.56
The best Installation procedures I have ever used for LAMP. Thanks
21.4.2021 at 07.26
Very good tutorial
1.5.2021 at 21.24
Very good tutorial but, why not use tasksel? It is a lot easier and automatic… for example, look here:
https://vitux.com/install-and-configure-lamp-server-on-ubuntu/
4.5.2021 at 13.33
Hi Gonzalo, thanks for the comment. Tasksel is a great option for installing predefined configurations. However, the main point of tutorials for installing a LAMP stack manually is in learning how each component works and interacts.
25.9.2021 at 17.06
Very good, nice and clear but I need some help configuring the permissions for PHP file uploads. I determined Apache and PHP both run as ‘me’ and I own the destination Uploads directory but the script fails move_uploaded_file(): Unable to move ‘/tmp/phpSeyVgA’ to ‘uploads/notes.csv’ in /var/www/html/catalogue/index.php on line 428. Any thoughts?
27.9.2021 at 17.45
Hi Philip, thanks for the question. Commonly, a LAMP stack like in this tutorial is run under the user and group www-data. You may need to change the ownership of your uploads/ directory to allow the webserver to copy the uploaded files over.
26.11.2021 at 15.04
Nice tutorial. Maybe should have included phpMyAdmin.
29.3.2022 at 11.51
I am not able to install php7.4 Please suggest me how it works and way to solve this problem.
13.4.2022 at 16.27
Hi there, thanks for the question. If your choice of OS doesn’t have PHP available via package manager, you can always just download the version you prefer from PHP’s website.
Your email address will not be published. Required fields are marked *
Comment *
Name *
Email *
Website
Save my name, email, and website in this browser for the next time I comment.
Δ
See all tutorials