{"id":2107,"date":"2020-11-04T10:50:19","date_gmt":"2020-11-04T08:50:19","guid":{"rendered":"https:\/\/upcloud.com\/global\/us\/resources\/tutorials\/installing-lamp-stack-ubuntu\/"},"modified":"2026-04-23T14:25:30","modified_gmt":"2026-04-23T13:25:30","slug":"installing-lamp-stack-ubuntu","status":"publish","type":"tutorial","link":"https:\/\/upcloud.com\/global\/resources\/tutorials\/installing-lamp-stack-ubuntu\/","title":{"rendered":"How to install LAMP stack web server on Ubuntu 20.04"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">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.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">In this guide, we\u2019ll 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!&nbsp;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.<\/p>\n\n\n\n\n\n<h2 class=\"wp-block-heading\">Step 1: Preparing your Ubuntu server<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">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 <a href=\"https:\/\/upcloud.com\/global\/docs\/guides\/deploy-server\/\" target=\"_blank\" rel=\"noreferrer noopener\">deploying your first cloud server<\/a> and <a href=\"https:\/\/upcloud.com\/global\/docs\/guides\/connecting-to-your-server\/\" target=\"_blank\" rel=\"noreferrer noopener\">how to connect to it<\/a>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Once you have your cloud server up and running and connect to it using SSH, you can get started!<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">First of all, ensure everything is up to date on your server:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">sudo apt update\nsudo apt upgrade\n<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Now open ports 22 (for SSH), 80 and 443 and enable Ubuntu Firewall (ufw):<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">sudo ufw allow ssh\nsudo ufw allow 80\nsudo ufw allow 443\nsudo ufw enable\n<\/pre>\n\n\n\n<div class=\"wp-block-buttons is-layout-flex wp-block-buttons-is-layout-flex\">\n<div class=\"wp-block-button\"><a class=\"wp-block-button__link wp-element-button\" href=\"https:\/\/signup.upcloud.com\/\">Try UpCloud for free!<\/a><\/div>\n<\/div>\n\n\n\n<h2 class=\"wp-block-heading\">Step 2: Installing and testing Apache2<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Install Apache using apt:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">sudo apt install apache2<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Confirm that Apache is now running with the following command:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">sudo systemctl status apache2<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">You should then get an output showing that the apache2.service is running and enabled.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">\u25cf apache2.service - The Apache HTTP Server\n     Loaded: loaded (\/lib\/systemd\/system\/apache2.service; enabled; vendor preset: enabled)\n     Active: active (running) since Tue 2020-11-03 10:32:26 UTC; 1min 6s ago\n       Docs: https:\/\/httpd.apache.org\/docs\/2.4\/\n   Main PID: 52943 (apache2)\n      Tasks: 7 (limit: 2282)\n     Memory: 11.9M\n     CGroup: \/system.slice\/apache2.service\n             \u251c\u250052943 \/usr\/sbin\/apache2 -k start\n             \u251c\u250052944 \/usr\/sbin\/apache2 -k start\n             \u251c\u250052945 \/usr\/sbin\/apache2 -k start\n             \u251c\u250052946 \/usr\/sbin\/apache2 -k start\n             \u251c\u250052947 \/usr\/sbin\/apache2 -k start\n             \u251c\u250052948 \/usr\/sbin\/apache2 -k start\n             \u2514\u250052953 \/usr\/sbin\/apache2 -k start\n<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Once installed, test by accessing your server\u2019s IP in your browser:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">http:\/\/YOURSERVERIPADDRESS\/<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">You should see a page with an \u201cApache2 Ubuntu Default\u201d 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<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Step 3: Installing and testing PHP 7.4<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">PHP 7.4 is the latest available right now so let\u2019s install that along with some regularly used modules:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">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<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Check the installation and version:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">php --version<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Restart Apache for the changes to take effect:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">sudo systemctl restart apache2<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Create a phpinfo.php test page:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">echo '&lt;?php phpinfo(); ?&gt;' | sudo tee -a \/var\/www\/html\/phpinfo.php &gt; \/dev\/null<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Test everything is working by accessing the following in your browser:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">http:\/\/YOURSERVERIPADDRESS\/phpinfo.php<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">You should see a PHP Version 7.4.3 page listing all of your PHP options. If you don\u2019t or it tries to download a file, double-check that all of the above steps have been completed without error.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Once you\u2019ve confirmed that PHP is working correctly, delete the test file.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">sudo rm \/var\/www\/html\/phpinfo.php<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">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.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Step 4: Installing and securing MariaDB<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">MariaDB is a fork of MySQL from some of the original MySQL team and is a drop-in replacement. We\u2019ll be using this over MySQL itself in this guide!<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Install the required packages:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">sudo apt install mariadb-server mariadb-client<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Once installed,&nbsp;check it\u2019s running correctly:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">sudo systemctl status mariadb<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">You should see an output similar to the example below.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">\u25cf mariadb.service - MariaDB 10.3.25 database server\n     Loaded: loaded (\/lib\/systemd\/system\/mariadb.service; enabled; vendor preset: enabled)\n     Active: active (running) since Tue 2020-11-03 10:33:12 UTC; 4s ago\n       Docs: man:mysqld(8)\n             https:\/\/mariadb.com\/kb\/en\/library\/systemd\/\n   Main PID: 53554 (mysqld)\n     Status: \"Taking your SQL requests now...\"\n      Tasks: 31 (limit: 2282)\n     Memory: 65.9M\n     CGroup: \/system.slice\/mariadb.service\n             \u2514\u250053554 \/usr\/sbin\/mysqld\n<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Secure your newly installed MariaDB service:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">sudo mysql_secure_installation<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">As you have no root password set for MariaDB you should simply press <tt>Enter<\/tt> when prompted, pressing <tt>Y<\/tt> on the next question to then set a root password (keep this safe and secure!) With that set, you can press <tt>Enter<\/tt> for the remaining questions as the defaults for each of these will help to secure your new installation.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Conclusions<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">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.<\/p>\n","protected":false},"author":49,"featured_media":28480,"comment_status":"open","ping_status":"closed","template":"","community-category":[250],"class_list":["post-2107","tutorial","type-tutorial","status-publish","has-post-thumbnail","hentry"],"acf":[],"_links":{"self":[{"href":"https:\/\/upcloud.com\/global\/wp-json\/wp\/v2\/tutorial\/2107","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/upcloud.com\/global\/wp-json\/wp\/v2\/tutorial"}],"about":[{"href":"https:\/\/upcloud.com\/global\/wp-json\/wp\/v2\/types\/tutorial"}],"author":[{"embeddable":true,"href":"https:\/\/upcloud.com\/global\/wp-json\/wp\/v2\/users\/49"}],"replies":[{"embeddable":true,"href":"https:\/\/upcloud.com\/global\/wp-json\/wp\/v2\/comments?post=2107"}],"version-history":[{"count":1,"href":"https:\/\/upcloud.com\/global\/wp-json\/wp\/v2\/tutorial\/2107\/revisions"}],"predecessor-version":[{"id":6459,"href":"https:\/\/upcloud.com\/global\/wp-json\/wp\/v2\/tutorial\/2107\/revisions\/6459"}],"wp:attachment":[{"href":"https:\/\/upcloud.com\/global\/wp-json\/wp\/v2\/media?parent=2107"}],"wp:term":[{"taxonomy":"community-category","embeddable":true,"href":"https:\/\/upcloud.com\/global\/wp-json\/wp\/v2\/community-category?post=2107"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}