Learn how to set up a LAMP web server on your OVHcloud service.
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 Linux (OS), Apache (web server), MariaDB (database management system) and PHP (programming language).
Requirements
- A dedicated server, a VPS, or a Public Cloud instance in your OVHcloud account (excluding Windows systems)
- Access to the OVHcloud Control Panel
- 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 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. 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:
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:
Now you can install the current LAMP packages.
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):
You can verify the installation with the following command:
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:
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:
Confirm the first prompt by pressing Enter.
Next, you can choose a method to secure access to the database server.
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:
Since the subsequent prompts concern security measures, confirm them all with y until the script is finished.
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:
Create a database:
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.
Ensure the changes made are applied and then exit the MariaDB shell:
Step 5: Configuring the firewall (optional)
Configuring a firewall (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:
The relevant profiles are labelled as "WWW" in the application list:
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:
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:
Finally, activate the firewall rules and verify the configuration:
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.
Step 6: Enabling secure connections with Let’s Encrypt (optional)
To establish secure connections (https), the web server has to be secured via an official Certificate Authority such as "Let’s Encrypt" 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.
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.
Install the required packages for the Certbot client:
Obtain the certificate for your domain name and the "www" subdomain:
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
NGINX documentation (Apache alternative)
For more information and tutorials, please see our other Dedicated Servers support guides or explore the guides for other OVHcloud products and services.