To prepare a database for use with your software, follow the instructions below. You will need to provide the database credentials (name, user, and password) when installing an application, such as a CMS (e.g., WordPress or Drupal). Best Practice: Avoid using the same database for multiple applications.
How to set up a web server (LAMP) on Debian or Ubuntu
Introduction
Whether you are hosting a dynamic WordPress blog, a custom PHP application, or simply learning the ropes of server management, the LAMP stack remains the gold standard for web hosting. LAMP stands for Linux, Apache, MariaDB and PHP a powerful suite of open-source software that powers a significant portion of the internet.
By combining the stability of Debian or Ubuntu with the robustness of the Apache web server, the data management of MySQL, and the scripting power of PHP, you create a flexible and secure environment ready to handle everything from small personal projects to enterprise-level traffic. This guide will walk you through installing, configuring, and securing your own LAMP server, giving you full control over your web presence.
Requirements
- Operating System: A running instance of Debian or Ubuntu (Desktop or Server edition).
- User Privileges: A user account with
sudo(root) privileges. - Internet Access: Required to download packages from repositories.
- Command Line Interface: Access to the Terminal (Ctrl+Alt+T).
Instructions
To ensure the most stable foundation for your web server and applications, it is highly recommended to begin with a pristine environment. If your server is not currently running a fresh instance of Debian or Ubuntu, please navigate to your Control Panel to perform a reinstallation.
While the instructions below have been specifically verified for Debian 11, the shared architecture between the two systems ensures that this tutorial is equally effective for current Ubuntu distributions.
Updating the system
sudo apt update && sudo apt upgrade -y
Installing Apache
sudo apt install -y apache2 apache2-doc
sudo systemctl status apache2
http://server_IP in a web browser. The "Apache2 Debian Default Page" should appear.
Installing the database server 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
Configuring the database server
sudo mariadb-secure-installation
Switch to unix_socket authentication [Y/n]
Change the root password? [Y/n]
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!
Setting Up Your First Database and Database User (optional)
sudo mariadb
CREATE DATABASE database_name;
database_name, user_name, and password accordingly.
GRANT ALL ON database_name.* TO 'user_name'@'localhost' IDENTIFIED BY 'password' WITH GRANT OPTION;
FLUSH PRIVILEGES;
exit;
Configuring the firewall (optional)
sudo apt install ufw
sudo ufw app list | grep WWW
WWW
WWW Cache
WWW Full
WWW Secure
sudo ufw allow 'WWW Full'
sudo ufw allow 'SSH'
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)
DNS configuration (optional)
Enabling secure connections with Let’s Encrypt (optional)
To get a secure HTTPS connection, you need a certificate from a provider like "Let’s Encrypt" and must set up Apache using a tool like "Certbot." If you don't do this, your website can only accept unencrypted http requests.
Before you start, check your DNS settings. You need to make sure your domain name actually points to your server's IP address.
This command installs an older version of Certbot (1.12.0). It still works, but if you want the absolute latest version, you need to use the "snappy" package manager instead. You can find those instructions on the Certbot website.
sudo apt install -y certbot python3-certbot-apache
sudo certbot --apache -d domainname.com -d www.domainname.com
CTCservers Recommended Tutorials
Web, Network
Step-by-Step Guide: Install AMD ROCm on Ubuntu with RX 6600 GPU
Learn how to quickly and easily set up AMD ROCm on Ubuntu for your RX 6600 GPU, enabling powerful machine learning, AI workloads, and GPU-accelerated computing right on your system.
Web, Network, Linux, Mysql, Ubuntu
LAMP Setup Guide 2026: Ubuntu & Debian | CTCservers
Install a secure LAMP stack on Debian or Ubuntu. Follow our step-by-step guide to configure Linux, Apache, MySQL, and PHP for your web server.
Web, Network, Ubuntu
Deploy Phi-3 with Ollama on Ubuntu GPU | CTCservers
Learn how to easily deploy the Phi-3 LLM on an Ubuntu 24.04 GPU server using Ollama and WebUI. Follow our step-by-step tutorial for seamless AI hosting.
Discover CTCservers Dedicated Server Locations
CTCservers servers are available around the world, providing diverse options for hosting websites. Each region offers unique advantages, making it easier to choose a location that best suits your specific hosting needs.