---
title: "How to set up a web server (LAMP) on Debian or Ubuntu"
description: "Setting up a web server and related software enables your cloud server to host dynamic web pages or web applications. Installing a LAMP stack is a proven approa"
url: https://docs.us.ovhcloud.com/en/bare-metal-cloud/dedicated-servers/installing-lamp-debian9-ubuntu18
lang: en
---
> For AI agents: the complete documentation index is available at https://docs.us.ovhcloud.com/en/llms.txt, the full documentation bundle is available at https://docs.us.ovhcloud.com/en/llms-full.txt.

# How to set up a web server (LAMP) on Debian or Ubuntu

Setting up a web server and related software enables your cloud server to host dynamic web pages or web applications. Installing a _LAMP stack_ is a proven approach to achieve this with open-source applications. LAMP stands for **L**inux (OS), **A**pache (web server), **M**ariaDB (database management system) and **P**HP (programming language).

 

## Requirements

- A [dedicated server](https://us.ovhcloud.com/bare-metal/), a [VPS](https://us.ovhcloud.com/vps/), or a [Public Cloud instance](https://us.ovhcloud.com/public-cloud/) in your OVHcloud account (excluding Windows systems)
- Access to the [OVHcloud Control Panel](https://manager.us.ovhcloud.com/)
- Administrative access to your service via SSH

If you need training or technical assistance to implement our solutions, contact your sales representative or click on [this link](https://us.ovhcloud.com/professional-services/) to get a quote and ask our Professional Services experts for a custom analysis of your project.

 

## Instructions

If a current Debian or Ubuntu distribution is not already installed on your server, carry out a reinstallation first in your [OVHcloud Control Panel](https://manager.us.ovhcloud.com/). This is the best way to have a clean system for your web server and the applications running on it.

Follow the respective guide to install an operating system on your OVHcloud service and connect to it via [SSH](https://docs.us.ovhcloud.com/en/bare-metal-cloud/dedicated-servers/ssh-introduction.md):

- [Dedicated server](https://docs.us.ovhcloud.com/en/bare-metal-cloud/dedicated-servers/getting-started-dedicated-server-windows-linux.md)
- [VPS](https://docs.us.ovhcloud.com/en/bare-metal-cloud/vps/starting-with-a-vps.md)
- [Public Cloud instance](https://docs.us.ovhcloud.com/en/public-cloud/compute/getting-started.md)

**Note:**

The following instructions are verified for Debian 11. Since Ubuntu is based on Debian, the tutorial should work for a current Ubuntu distribution as well.

 

### Step 1: Updating the system

After logging in to your server with SSH, ensure that all packages are up-to-date:

```
sudo apt update && sudo apt upgrade -y
```

Now you can install the current LAMP packages.

**Note:**

Since software packages are regularly updated, you might need to adjust the following instructions according to the latest versions.

 

### Step 2: Installing Apache

Install the Apache packages (including documentation):

```
sudo apt install -y apache2 apache2-doc
```

You can verify the installation with the following command:

```
sudo systemctl status apache2
```

You can also open `http://server_IP` in a web browser. The "Apache2 Debian Default Page" should appear.

 

### Step 3: Installing the database server and PHP

Install the packages of MariaDB and PHP:

```
sudo apt install -y php php-pdo php-mysql php-zip php-gd php-mbstring php-curl php-xml php-pear php-bcmath mariadb-server
```

 

### Step 4: Configuring the database server

MariaDB provides a script to assist with the initial configuration and to apply some security-related settings.

To run it, enter this command:

```
sudo mysql_secure_installation
```

Confirm the first prompt by pressing `Enter`.

Next, you can choose a method to secure access to the database server.

```
Switch to unix_socket authentication [Y/n]
```

It is recommended to use the proposed authentication method (_unix\_socket_) instead of the access via root password. Press `y` and then `Enter`. (If you decide to use root user access instead, choose `n` and then set a root password at the next prompt.)

Enter `n` at the next prompt:

```
Change the root password? [Y/n]
```

Since the subsequent prompts concern security measures, confirm them all with `y` until the script is finished.

```
Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.

Reload privilege tables now? [Y/n] y
 ... Success!

Cleaning up...

All done!  If you've completed all of the above steps, your MariaDB
installation should now be secure.

Thanks for using MariaDB!
```

If you have configured MariaDB access in the recommended way (_unix\_socket_), you now have automatic admin access (_root_) to it whenever you are logged on to the server as a user with elevated permissions (_sudo_).

\[primary]To prepare a database for use with a software, you can follow the section below. You will need to provide the database credentials (database name, user, password) during the installation of an application, such as a CMS (e.g., WordPress, Drupal). For a best practice approach, avoid using the same database for different applications.

 

#### Creating your first database and a database user (optional)

Open the MariaDB shell:

```
sudo mariadb
```

```
MariaDB [(none)]> 
```

Create a database:

```
MariaDB [(none)]> CREATE DATABASE database_name;
```

Create a "user" with a name of your choice and grant it all rights on this database. This account can then access the database and carry out all operations for the application using this database. Replace `database_name` with the name of your database, `user_name` with a name of your choice, and `password` with a strong password.

```
MariaDB [(none)]> GRANT ALL ON database_name.* TO 'user_name'@'localhost' IDENTIFIED BY 'password' WITH GRANT OPTION;
```

Ensure the changes made are applied and then exit the MariaDB shell:

```
MariaDB [(none)]> FLUSH PRIVILEGES;
```

```
MariaDB [(none)]> exit;
```

 

### Step 5: Configuring the firewall (optional)

[Configuring a firewall](https://docs.us.ovhcloud.com/en/bare-metal-cloud/dedicated-servers/firewall-linux-iptable.md) (_iptables_) will enhance the security of your server. This process can be simplified by using the frontend "Uncomplicated Firewall" (UFW) and its preset of profiles. Install UFW:

```
sudo apt install ufw
```

The relevant profiles are labelled as "WWW" in the application list:

```
sudo ufw app list | grep WWW
  WWW
  WWW Cache
  WWW Full
  WWW Secure
```

By choosing "WWW Full", both secure connections (port 443) and not-secured _http_ requests (port 80) to the web server will be allowed.

To see which ports are affected by a particular profile, enter `sudo ufw app info "profile name"`.

By entering the following command, the ports defined by the profile "WWW Full" will be opened:

```
sudo ufw allow 'WWW Full'
```

Since all ports not explicitly allowed will be **blocked** after enabling the firewall, make sure to allow SSH connections (port 22 in a default configuration) as well:

```
sudo ufw allow 'SSH'
```

Finally, activate the firewall rules and verify the configuration:

```
sudo ufw enable
```

```
sudo ufw status
```

```
Status: active
Logging: on (low)
Default: deny (incoming), allow (outgoing), disabled (routed)
New profiles: skip

To                         Action      From
--                         ------      ----
80,443/tcp (WWW Full)      ALLOW IN    Anywhere                  
22/tcp (SSH)               ALLOW IN    Anywhere                  
80,443/tcp (WWW Full (v6)) ALLOW IN    Anywhere (v6)             
22/tcp (SSH (v6))          ALLOW IN    Anywhere (v6)       
```

You can go further with UFW, for example, if you want to restrict _denial of service_ (DOS) attacks or prevent requests by certain IP address ranges. Please refer to the [official UFW documentation](https://help.ubuntu.com/community/UFW).

 

### Step 6: Enabling secure connections with Let’s Encrypt (optional)

**Note:**

To establish secure connections (`https`), the web server has to be secured via an official Certificate Authority such as "[Let’s Encrypt](https://letsencrypt.org/)" which offers free certificates. You will need to install a client tool (such as "Certbot") and configure Apache accordingly. Without this step, your website or application can only accept unencrypted `http` requests.

First, make sure that your domain name has the correct records in the DNS zone, i.e., is mapped to the IP address of your server.

**Warning:**

**NOTE:** The following command will install a functioning but outdated version of Certbot (_certbot 1.12.0_). To install the latest version, the additional package manager _snappy_ must be used. You can find installation instructions on the [Certbot website](https://certbot.eff.org/instructions?ws=apache\&os=debianbuster).

Install the required packages for the Certbot client:

```
sudo apt install -y certbot python3-certbot-apache
```

Obtain the certificate for your domain name and the "www" subdomain:

```
sudo certbot --apache -d domainname.com -d www.domainname.com
```

You will need to enter a valid email address and accept the terms of service.

Certbot will automatically renew the certificates. There are no further steps needed. However, you can look into the available options to learn more about the capabilities of Certbot.

 

## Go further

[How to upload and retrieve data on a server via SFTP](https://docs.us.ovhcloud.com/en/bare-metal-cloud/dedicated-servers/transfer-data-via-sftp.md)

[UFW documentation](https://help.ubuntu.com/community/UFW)

[Apache documentation](https://httpd.apache.org/docs/)

[MariaDB documentation](https://mariadb.com/kb/en/documentation/)

[Let’s Encrypt documentation](https://httpd.apache.org/docs/)

[Certbot documentation](https://eff-certbot.readthedocs.io/en/stable/)

[NGINX documentation](https://nginx.org/en/docs/) (Apache alternative)

Browse all the [Dedicated Servers guides](https://docs.us.ovhcloud.com/en/bare-metal-cloud/dedicated-servers/landing-page-dedicated-servers.md).

Browse the rest of the [OVHcloud US documentation](https://docs.us.ovhcloud.com/en/index.md) for guides on our other products and services.

Learn more about [Dedicated Servers](https://us.ovhcloud.com/bare-metal/) on the OVHcloud US website.
