Notice: Function _load_textdomain_just_in_time was called incorrectly. Translation loading for the acf domain was triggered too early. This is usually an indicator for some code in the plugin or theme running too early. Translations should be loaded at the init action or later. Please see Debugging in WordPress for more information. (This message was added in version 6.7.0.) in /var/www/vhosts/studiogo.tech/httpdocs/upcloudold/wp-includes/functions.php on line 6131

Deprecated: Creation of dynamic property ACF::$fields is deprecated in /var/www/vhosts/studiogo.tech/httpdocs/upcloudold/wp-content/plugins/advanced-custom-fields-pro/includes/fields.php on line 138

Deprecated: Creation of dynamic property acf_loop::$loops is deprecated in /var/www/vhosts/studiogo.tech/httpdocs/upcloudold/wp-content/plugins/advanced-custom-fields-pro/includes/loop.php on line 28

Deprecated: Creation of dynamic property ACF::$loop is deprecated in /var/www/vhosts/studiogo.tech/httpdocs/upcloudold/wp-content/plugins/advanced-custom-fields-pro/includes/loop.php on line 269

Deprecated: Creation of dynamic property ACF::$revisions is deprecated in /var/www/vhosts/studiogo.tech/httpdocs/upcloudold/wp-content/plugins/advanced-custom-fields-pro/includes/revisions.php on line 397

Deprecated: Creation of dynamic property acf_validation::$errors is deprecated in /var/www/vhosts/studiogo.tech/httpdocs/upcloudold/wp-content/plugins/advanced-custom-fields-pro/includes/validation.php on line 28

Deprecated: Creation of dynamic property ACF::$validation is deprecated in /var/www/vhosts/studiogo.tech/httpdocs/upcloudold/wp-content/plugins/advanced-custom-fields-pro/includes/validation.php on line 214

Deprecated: Creation of dynamic property acf_form_customizer::$preview_values is deprecated in /var/www/vhosts/studiogo.tech/httpdocs/upcloudold/wp-content/plugins/advanced-custom-fields-pro/includes/forms/form-customizer.php on line 28

Deprecated: Creation of dynamic property acf_form_customizer::$preview_fields is deprecated in /var/www/vhosts/studiogo.tech/httpdocs/upcloudold/wp-content/plugins/advanced-custom-fields-pro/includes/forms/form-customizer.php on line 29

Deprecated: Creation of dynamic property acf_form_customizer::$preview_errors is deprecated in /var/www/vhosts/studiogo.tech/httpdocs/upcloudold/wp-content/plugins/advanced-custom-fields-pro/includes/forms/form-customizer.php on line 30

Deprecated: Creation of dynamic property ACF::$form_front is deprecated in /var/www/vhosts/studiogo.tech/httpdocs/upcloudold/wp-content/plugins/advanced-custom-fields-pro/includes/forms/form-front.php on line 598

Deprecated: Creation of dynamic property acf_form_widget::$preview_values is deprecated in /var/www/vhosts/studiogo.tech/httpdocs/upcloudold/wp-content/plugins/advanced-custom-fields-pro/includes/forms/form-widget.php on line 34

Deprecated: Creation of dynamic property acf_form_widget::$preview_reference is deprecated in /var/www/vhosts/studiogo.tech/httpdocs/upcloudold/wp-content/plugins/advanced-custom-fields-pro/includes/forms/form-widget.php on line 35

Deprecated: Creation of dynamic property acf_form_widget::$preview_errors is deprecated in /var/www/vhosts/studiogo.tech/httpdocs/upcloudold/wp-content/plugins/advanced-custom-fields-pro/includes/forms/form-widget.php on line 36

Notice: Function _load_textdomain_just_in_time was called incorrectly. Translation loading for the all-in-one-wp-migration domain was triggered too early. This is usually an indicator for some code in the plugin or theme running too early. Translations should be loaded at the init action or later. Please see Debugging in WordPress for more information. (This message was added in version 6.7.0.) in /var/www/vhosts/studiogo.tech/httpdocs/upcloudold/wp-includes/functions.php on line 6131

Deprecated: str_replace(): Passing null to parameter #3 ($subject) of type array|string is deprecated in /var/www/vhosts/studiogo.tech/httpdocs/upcloudold/wp-content/plugins/wp-super-cache/wp-cache-phase2.php on line 54

Deprecated: strtolower(): Passing null to parameter #1 ($string) of type string is deprecated in /var/www/vhosts/studiogo.tech/httpdocs/upcloudold/wp-content/plugins/wp-super-cache/wp-cache-phase2.php on line 828

Notice: Function _load_textdomain_just_in_time was called incorrectly. Translation loading for the rocket domain was triggered too early. This is usually an indicator for some code in the plugin or theme running too early. Translations should be loaded at the init action or later. Please see Debugging in WordPress for more information. (This message was added in version 6.7.0.) in /var/www/vhosts/studiogo.tech/httpdocs/upcloudold/wp-includes/functions.php on line 6131

Deprecated: Creation of dynamic property acf_field_oembed::$width is deprecated in /var/www/vhosts/studiogo.tech/httpdocs/upcloudold/wp-content/plugins/advanced-custom-fields-pro/includes/fields/class-acf-field-oembed.php on line 31

Deprecated: Creation of dynamic property acf_field_oembed::$height is deprecated in /var/www/vhosts/studiogo.tech/httpdocs/upcloudold/wp-content/plugins/advanced-custom-fields-pro/includes/fields/class-acf-field-oembed.php on line 32

Deprecated: Creation of dynamic property acf_field_google_map::$default_values is deprecated in /var/www/vhosts/studiogo.tech/httpdocs/upcloudold/wp-content/plugins/advanced-custom-fields-pro/includes/fields/class-acf-field-google-map.php on line 33

Deprecated: Creation of dynamic property acf_field__group::$have_rows is deprecated in /var/www/vhosts/studiogo.tech/httpdocs/upcloudold/wp-content/plugins/advanced-custom-fields-pro/includes/fields/class-acf-field-group.php on line 31

Deprecated: Creation of dynamic property acf_field_clone::$cloning is deprecated in /var/www/vhosts/studiogo.tech/httpdocs/upcloudold/wp-content/plugins/advanced-custom-fields-pro/pro/fields/class-acf-field-clone.php on line 34

Deprecated: Creation of dynamic property acf_field_clone::$have_rows is deprecated in /var/www/vhosts/studiogo.tech/httpdocs/upcloudold/wp-content/plugins/advanced-custom-fields-pro/pro/fields/class-acf-field-clone.php on line 35

Deprecated: Creation of dynamic property jh_acf_field_table::$settings is deprecated in /var/www/vhosts/studiogo.tech/httpdocs/upcloudold/wp-content/plugins/advanced-custom-fields-table-field/class-jh-acf-field-table.php on line 23
UpCloud

How to install LAMP stack web server on Ubuntu 20.04

benefit-4

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. These together form a reliable LAMP stack and the groundwork for building your 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.

Step 1: Preparing your Ubuntu server

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 

Step 2: Installing and testing Apache2

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

Step 3: Installing and testing PHP 7.4

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.

Step 4: Installing and securing MariaDB

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.

Conclusions

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.

Discussion Join Discussion

  1. 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?

  2. 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.

  3. 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.

  4. 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.

Leave a Reply

Your email address will not be published. Required fields are marked *

Find out what makes our Cloud servers so boring

No? Experience the UpCloud special treatment and try our next generation, high-performance and resilient Cloud servers with no drama, worries or commitment.