Support Online
Skip to main content

Installing Apache on Ubuntu (2026)

How to Install Apache Web Server on Ubuntu?

Installing an Apache web server on Ubuntu is one of the most common methods for publishing a website or hosting multiple domains. Apache is an open source, reliable and high-performance HTTP server used on millions of websites around the world.

In this guide, you will learn how to install the Apache web server on your Ubuntu server, configure firewall settings, learn service management, and publish multiple sites on a single server using VirtualHost. The guide is prepared for both beginners and system administrators who manage a production environment.

This content explains basic topics such as Apache installation, security settings, service management and site configuration step by step.


Things to Know Before Ubuntu Apache Installation

Installing Apache is quite simple because it can be installed with a single command via apt, the Ubuntu package manager. After installation, the service starts working automatically and offers a default web page.

The basic operations to be performed during Apache installation are:

  • Installing the Apache package
  • Opening HTTP and HTTPS ports via UFW firewall
  • Checking Apache service
  • Learning the server IP address
  • Publishing multiple sites with VirtualHost configuration

Installing Apache on Ubuntu Server

Before installing the Apache web server, it is necessary to update the system package list. This process ensures that your system uses the most up-to-date packages.

sudo apt update

This command refreshes the Ubuntu package list and ensures that the latest versions of newly installed packages are downloaded.

Then you can install the Apache web server.

sudo apt install apache2

This command installs the Apache web server and necessary dependencies on your system. After the installation is completed, the Apache service is automatically started.


UFW Firewall Settings (Turning on HTTP and HTTPS)

UFW (Uncomplicated Firewall) is generally used in Ubuntu systems. Some profile options for UFW are automatically added when Apache is installed.

There are three different firewall profiles for Apache:

Apache → Port 80 (HTTP) Apache Secure → Port 443 (HTTPS) Apache Full → Port 80 ve 443

To see available Apache firewall profiles, you can run this command:

sudo ufw app list

To allow HTTP traffic you can use this command:

sudo ufw allow 'Apache'

To check firewall status:

sudo ufw status

This command displays active firewall rules.


Testing That the Apache Web Server is Working

Once Apache is installed, it is important to check if the service is active.

To check Apache service status:

sudo systemctl status apache2

This command shows whether the Apache service is active, inactive or in error state.

You can use the following command to find out the local IP address of the server:

hostname -I

To find out the external IP address of the server:

curl -4 icanhazip.com

Once you know the IP address, type the following address into your web browser:

http://SUNUCU_IP_ADRESI

If you see the Apache2 Ubuntu Default Page page, Apache installation has been completed successfully.


Apache Service Management

systemctl commands are used to manage the Apache service. These commands allow starting, stopping and reloading the service.

To stop the Apache service:

sudo systemctl stop apache2

To start the Apache service:

sudo systemctl start apache2

To restart the Apache service:

sudo systemctl restart apache2

To apply Apache configuration changes without breaking connections:

sudo systemctl reload apache2

To turn off the automatic start of the Apache service at system startup:

sudo systemctl disable apache2

To enable the Apache service to start automatically at system startup:

sudo systemctl enable apache2

Publishing Multiple Sites on Ubuntu Server with VirtualHost

Thanks to the Apache VirtualHost feature, you can host multiple websites on a single server. A separate configuration file is created for each site.

First, create the site directory.

sudo mkdir -p /var/www/ornekalan.com

Set directory ownership.

sudo chown -R $USER:www-data /var/www/ornekalan.com

Set secure file permissions.

sudo chmod -R u=rwX,go=rX /var/www/ornekalan.com

Create an index file for testing purposes.

sudo nano /var/www/ornekalan.com/index.html

Sample content:

<html>
<h1>ornekalan.com yayında!</h1>
</html>

Then create the VirtualHost configuration file.

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

The file content can be like this:

<VirtualHost *:80>
ServerName ornekalan.com
ServerAlias www.ornekalan.com
DocumentRoot /var/www/ornekalan.com
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

To activate the new site:

sudo a2ensite ornekalan.com.conf

To turn off the default Apache site:

sudo a2dissite 000-default.conf

To check for Apache configuration errors:

sudo apache2ctl configtest

Finally, restart the Apache service.

sudo systemctl restart apache2

Important Arrays and Files of Apache

Knowing some important directories after Apache installation is important for system management.

RoadDescription
/var/www/htmlDefault Web Directory
/etc/apache2Apache Configuration Files
/etc/apache2/sites-availableVirtualHost Configurations
/etc/apache2/sites-enabledActive Sites
/var/log/apache2/error.logApache Error Logs
/var/log/apache2/access.logApache Access Logs

Frequently Asked Questions

Apache Ubuntu üzerinde en hızlı nasıl kurulur? The fastest method to install Apache is the sudo apt install apache2 command.

Apache çalışıyor mu nasıl kontrol edilir? sudo systemctl status apache2 command shows whether the Apache service is active or not.

Apache hangi portları kullanır? Apache uses ports 80 (HTTP) and 443 (HTTPS) by default.

VirtualHost ne işe yarar? VirtualHost feature allows you to host multiple domains on a single server.

Permission denied hatası nasıl çözülür? Usually the file ownership is set incorrectly. The following command solves the problem:

sudo chown -R $USER:www-data /var/www/site

Result

In this guide, you learned how to install the Apache web server on Ubuntu, how to make firewall settings, service management and VirtualHost configuration. Thanks to these steps, you can easily publish a website and manage multiple domains on your Linux server.

Once Apache installation is complete, you can also apply advanced configurations such as SSL installation, performance optimization and security settings.