Integrated Tech Solutions

Setup Apache Server – A Complete guide for Beginners

By - Admin, Updated on August 17, 2024

Introduction:

Setting up a web server is an essential skill for anyone venturing into the world of web development or server administration. Apache, one of the most widely used web servers, is a reliable choice for hosting websites. In this guide, we will walk you through the step-by-step process of setting up an Apache server on an Ubuntu operating system.

Step 1: Update and Upgrade Ubuntu: Before installing any software, it’s a good practice to ensure that your system is up to date. Open a terminal and run the following commands:

sudo apt update
sudo apt upgrade

Step 2: Install Apache: To install Apache on Ubuntu, use the following command:

sudo apt install apache2

During the installation, Ubuntu will prompt you to confirm whether you want to proceed. Type ‘Y’ and press Enter.

Step 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

You can check the status of Apache to ensure that it’s running without any issues:

sudo systemctl status apache2

Step 4: Configure Firewall: If you have a firewall enabled on your system, you’ll need to allow traffic on the default HTTP port (port 80). Use the following command:

sudo ufw allow 80

Step 5: Test Apache: Open a web browser and enter your server’s IP address in the address bar. You should see the default Apache landing page, indicating that your server is up and running.

Step 6: Create Virtual Hosts (Optional): Virtual Hosts allow you to host multiple websites on a single server. To set up a virtual host, create a new configuration file for your site. Replace ‘your_domain’ with your domain name or desired site name.

sudo nano /etc/apache2/sites-available/your_domain.conf

Add the following basic configuration, modifying the paths and settings accordingly:

<VirtualHost *:80> 
ServerAdmin webmaster@your_domain 
ServerName your_domain 
DocumentRoot /var/www/your_domain/public_html 
ErrorLog ${APACHE_LOG_DIR}/error.log 
CustomLog ${APACHE_LOG_DIR}/access.log combined 
</VirtualHost>

Save the file and enable the virtual host:

sudo a2ensite your_domain.conf

Restart Apache for the changes to take effect:

sudo systemctl restart apache2

Enable additional modules in apache

sudo a2enmod module_name
sudo a2dismod module_name

For example to enable mod_headers,

sudo a2enmod headers
sudo a2ensite sitename
sudo a2dissite sitename

Locate Server Logs in Apache2

By Default, server logs of apache are stored in /var/log/apache2 directory

Keep Reading

👋 Hi, Find this Helpful? There is More

You Asked,
We made it!

fix japanese keyword hack

Step by Step Video Tutorials on trending topics in software development

Yes I am Curious »

AR in Websites – Top 3 Platforms for Bringing Augmented Reality to Your Web Experience

As technology advances, augmented reality (AR) is no longer limited to gaming or social media apps. Integrating AR into websites...

Know More »

Webhook Explained for Beginners: Everything You Need to Know

In the world of APIs, automation, and modern web applications, the term “webhook” often comes up. But what exactly is...

Know More »