Skip to main content

How to Install Apache HTTP Server on Linux Mint

The Apache HTTP Server is a widely used and powerful web server software that allows you to serve web content over the internet. It is known for its stability, security, and flexibility. In this tutorial, we will guide you through the step-by-step process of installing Apache HTTP Server on Linux Mint.

Prerequisites

Before we begin, make sure you have the following:

  • A Linux Mint operating system installed on your machine.
  • A terminal with administrative privileges.

Step 1: Update Package Repository

The first step is to update the package repository to ensure you have the latest software available. Open a terminal and execute the following command:

sudo apt update

This command will fetch the latest information about available packages from the repositories.

Step 2: Install Apache HTTP Server

Once the package repository is updated, you can install Apache HTTP Server using the following command:

sudo apt install apache2

This command will install the Apache HTTP Server along with its dependencies.

Step 3: Start and Enable Apache

After the installation is complete, you can start the Apache service using the following command:

sudo systemctl start apache2

To ensure that Apache starts automatically on system boot, enable it with the command:

sudo systemctl enable apache2

Step 4: Verify Apache Installation

To confirm that Apache HTTP Server is installed and running correctly, open a web browser and enter the following URL:

http://localhost/

If Apache is running properly, you should see the default Apache2 Ubuntu Default Page.

Step 5: Firewall Configuration

By default, Apache listens on port 80. If you have a firewall enabled on your Linux Mint system, you need to allow incoming connections to the Apache server. You can use the ufw command line tool to configure the firewall.

To allow incoming HTTP traffic, execute the following command:

sudo ufw allow 'Apache'

Now, your firewall will allow connections to your Apache server.

Step 6: Apache Configuration Files

Apache HTTP Server has several configuration files that control its behavior. The main configuration file is located at /etc/apache2/apache2.conf. You can open this file using a text editor to modify the server settings.

For example, to change the default document root directory, open the configuration file using your preferred text editor:

sudo nano /etc/apache2/apache2.conf

Find the line that starts with DocumentRoot and update it to your desired directory path. Save the file and exit the editor.

Step 7: Virtual Hosts

Apache supports virtual hosts, which allow you to host multiple websites on a single server. To create a virtual host, you need to create a new configuration file in the /etc/apache2/sites-available/ directory.

For example, let's create a virtual host for a website named example.com. Open a terminal and execute the following command:

sudo nano /etc/apache2/sites-available/example.com.conf

Add the following configuration to the file:

<VirtualHost *:80>
ServerName example.com
ServerAlias www.example.com
DocumentRoot /var/www/html/example.com
ErrorLog ${APACHE_LOG_DIR}/example.com_error.log
CustomLog ${APACHE_LOG_DIR}/example.com_access.log combined
</VirtualHost>

Save the file and exit the editor.

Step 8: Enable Virtual Host

To enable the virtual host, create a symbolic link in the /etc/apache2/sites-enabled/ directory using the following command:

sudo ln -s /etc/apache2/sites-available/example.com.conf /etc/apache2/sites-enabled/

Step 9: Restart Apache

After making any changes to the Apache configuration, you need to restart Apache for the changes to take effect. Execute the following command to restart Apache:

sudo systemctl restart apache2

Step 10: Testing Virtual Host

To test the newly created virtual host, you can add an entry to your /etc/hosts file. Open the file using a text editor with administrative privileges:

sudo nano /etc/hosts

Add the following line at the end of the file:

127.0.0.1   example.com

Save the file and exit the editor.

Now, you can access your website by entering http://example.com in your web browser.

Conclusion

Congratulations! You have successfully installed Apache HTTP Server on your Linux Mint system. You have also learned how to start and enable Apache, configure firewall settings, create virtual hosts, and modify Apache's configuration files. Apache HTTP Server is now ready to serve your websites and applications. Enjoy exploring its numerous features and possibilities!