- Update your system
Before installing any new packages, it is always a good idea to update your system. Open a terminal window and run the following command:
sudo apt-get update && sudo apt-get upgrade
This will ensure that your system is up-to-date and all security patches are installed.
- Install Apache
Once your system is updated, you can install Apache using the following command:
sudo apt-get install apache2
This will install Apache and all its dependencies.
- Configure Apache
After installing Apache, you can configure it to meet your needs. The main configuration file for Apache is located at /etc/apache2/apache2.conf. You can open this file using a text editor such as nano or vim:
sudo nano /etc/apache2/apache2.conf
Here, you can configure various settings such as the server name, port, and document root. Once you have made any changes, save the file and exit.
- Test Apache
After configuring Apache, you can test it by opening a web browser and navigating to your server’s IP address. You should see the Apache2 Ubuntu Default Page, indicating that Apache is running properly.
- Configure Firewall
By default, Debian comes with a firewall called ufw. You can allow incoming HTTP and HTTPS traffic using the following commands:
sudo ufw allow http sudo ufw allow https
- Install PHP
If you plan to run dynamic websites, you will need to install PHP. You can install PHP using the following command:
sudo apt-get install php libapache2-mod-php php-mysql
This will install PHP and the necessary modules.
- Test PHP
Once PHP is installed, you can test it by creating a test PHP file in the document root directory:
sudo nano /var/www/html/info.php
Add the following code to the file:
<?php phpinfo(); ?>
Save the file and exit. Then, navigate to http://your-server-ip/info.php in your web browser. You should see a PHP info page, indicating that PHP is installed and working.
That’s it! You now have a working web server on Debian using Apache.