How To Install Web Server On Debian


Debian is a popular operating system used by many web developers and administrators. One of the key tasks in setting up a website or web application is installing a web server. In this article, we will guide you through the steps of installing a web server on Debian, specifically focusing on the Apache web server.

1. Update and Upgrade Your System

Before installing any software, it is always a good practice to update and upgrade your system to ensure you have the latest security patches and bug fixes. Open the terminal and run the following commands:

sudo apt update sudo apt upgrade

2. Install Apache

Apache is a widely used web server that powers a large percentage of websites on the internet. To install Apache, run the following command:

sudo apt install apache2

3. Start and Enable Apache

Once the installation is complete, start the Apache service and enable it to start on boot:

sudo systemctl start apache2 sudo systemctl enable apache2

4. Configure Firewall

By default, Apache listens on port 80. To allow incoming web traffic, you need to open this port on your firewall. Run the following command to enable HTTP traffic:

sudo ufw allow 'Apache'

5. Test Apache

To check if Apache is running correctly, open your web browser and enter your server’s IP address or domain name. If you see the Apache default page, it means Apache is installed and working properly.

6. Install MySQL

MySQL is a popular relational database management system often used in web applications. To install MySQL, run the following command:

sudo apt install mysql-server

7. Start and Enable MySQL

After the installation, start the MySQL service and enable it to start on boot:

sudo systemctl start mysql sudo systemctl enable mysql

8. Secure MySQL Installation

MySQL comes with a security script that allows you to secure the installation. Run the script by executing:

sudo mysql_secure_installation

9. Install PHP

PHP is a popular server-side scripting language used to create dynamic web pages. To install PHP, run the following command:

sudo apt install php libapache2-mod-php php-mysql

10. Test PHP

To test if PHP is working correctly with Apache, create a PHP info file. Create a new file called info.php in the Apache web root directory:

sudo nano /var/www/html/info.php

Add the following line to the file:

Save and close the file. Open your web browser and enter your server’s IP address or domain name, followed by /info.php. If you see the PHP information page, it means PHP is installed and working correctly.

11. Install phpMyAdmin (Optional)

phpMyAdmin is a web-based tool used for managing MySQL databases. To install phpMyAdmin, run the following command:

sudo apt install phpmyadmin

During the installation, you will be prompted to choose a web server. Select Apache by pressing the spacebar, then press Enter to continue. Follow the on-screen instructions to complete the installation.

12. Configure Apache for phpMyAdmin

To configure Apache to work with phpMyAdmin, you need to edit the Apache configuration file. Open the file by executing:

sudo nano /etc/apache2/conf-available/phpmyadmin.conf

Find the line that says Require ip and add your IP address below it, allowing remote access to phpMyAdmin. Save and close the file.

13. Enable phpMyAdmin

Enable the phpMyAdmin configuration by executing:

sudo ln -s /etc/apache2/conf-available/phpmyadmin.conf /etc/apache2/conf-enabled/

Restart Apache for the changes to take effect:

sudo systemctl restart apache2

14. Set Up Virtual Hosts (Optional)

If you plan to host multiple websites on your Debian server, you can set up virtual hosts. Virtual hosts allow you to host multiple domains on a single server. To create a virtual host, follow these steps:

  1. Create a new directory to store the website files:
  2. sudo mkdir /var/www/
  3. Assign ownership of the directory to the Apache user:
  4. sudo chown -R www-data:www-data /var/www/
  5. Create a new configuration file for the virtual host:
  6. sudo nano /etc/apache2/sites-available/
  7. Add the following content to the file:
  8.  ServerName ServerAlias DocumentRoot /var/www/  AllowOverride All Require all granted 
  9. Enable the virtual host:
  10. sudo a2ensite
  11. Restart Apache:
  12. sudo systemctl restart apache2

15. Secure Your Web Server

Securing your web server is crucial to protect your website and data from potential threats. Here are a few tips to enhance the security of your Debian web server:

  • Keep your system up to date by regularly applying security patches.
  • Use strong and unique passwords for all user accounts.
  • Disable the root login and use a non-root user with sudo privileges.
  • Configure a firewall to only allow necessary incoming and outgoing connections.
  • Regularly backup your website files and databases.


By following the steps outlined in this article, you should now have a fully functional web server running on Debian. You can now start hosting your websites or web applications and take advantage of the powerful features offered by Apache, MySQL, and PHP.

Remember to regularly maintain and update your server to ensure optimal performance and security.