If you plan to host a website or web application, one of the most crucial steps is setting up a reliable web server. Among all the available options, Apache HTTP Server remains the most popular choice for Linux servers. It is open-source, highly flexible, secure, and trusted by millions of websites worldwide. Learning how to create Apache on Linux server is a foundational skill for system administrators, developers, and even small business owners looking to manage their hosting environment.

In this guide, we will cover everything from prerequisites and installation to configuration, security, and troubleshooting so that you can set up Apache smoothly on your Linux machine.
Prerequisites
Before you begin, make sure you have:
- A Linux-based server (Ubuntu, Debian, CentOS, or RHEL are the most common).
- Root or sudo access to the server.
- A stable internet connection for downloading packages and updates.
- Basic familiarity with Linux commands, though we will explain each step clearly.
Step-by-Step Guide to Install Apache on Linux Server
Apache is one of the most popular and reliable web servers used worldwide. Installing Apache on a Linux server is simple and ensures a stable environment for hosting websites and applications. Follow the steps below to set it up quickly and efficiently.
- Update Your Linux System
Updating your system ensures that all packages are current and compatible with Apache. Use the following commands:
sudo apt update && sudo apt upgrade -y # For Ubuntu/Debian
sudo yum update -y # For CentOS/RHEL
This step prevents compatibility issues and strengthens server security.
- Install Apache Using Package Manager
Each Linux distribution uses its package manager. Run the appropriate command for your system:
sudo apt install apache2 -y # For Ubuntu/Debian
sudo yum install httpd -y # For CentOS/RHEL
After installation, Apache is added to your server, but you still need to start and enable it.
- Start and Enable Apache Service
To make Apache run immediately and on every server reboot, use:
sudo systemctl start apache2 # For Ubuntu/Debian
sudo systemctl enable apache2
sudo systemctl start httpd # For CentOS/RHEL
sudo systemctl enable httpd
- Verify Apache Installation
Check whether Apache is running by typing your server’s IP address in a browser. If the setup was successful, you will see Apache’s default welcome page, confirming that your web server is live.
Configuring Apache Web Server
Once Apache is installed, proper configuration is essential to ensure optimal performance, security, and smooth handling of web requests. The configuration process allows you to customize how the server responds to clients and manages hosted websites.
- Apache Configuration Files
Apache’s power lies in its flexibility. The main configuration files are:
- Ubuntu/Debian:
/etc/apache2/apache2.conf
- CentOS/RHEL:
/etc/httpd/conf/httpd.conf
You can use these files to define server settings, security rules, and performance tweaks.
- Setting Up a Basic HTML Test Page
To confirm your server is ready to serve web pages, create a simple HTML file:
echo "<h1>Apache is Successfully Installed!</h1>" | sudo tee /var/www/html/index.html
Now, visit your server’s IP address again. You should see your custom test page.
- Managing Virtual Hosts
If you plan to host multiple websites on a single server, virtual hosts make this possible.
- On Ubuntu/Debian: configure sites in
/etc/apache2/sites-available/
- On CentOS/RHEL: configure in
/etc/httpd/conf.d/
By creating separate virtual host files, you can assign unique domain names, document roots, and settings to each site.
Securing Apache on Linux
Securing Apache is crucial to protecting your Linux server from unauthorized access, vulnerabilities, and potential attacks. By applying the right security practices, you can ensure a safer and more reliable web hosting environment.
- Configure Firewall Rules
A firewall is essential to allow only safe traffic. Use:
sudo ufw allow 'Apache Full' # For Ubuntu
sudo firewall-cmd --permanent --add-service=http # For CentOS/RHEL
sudo firewall-cmd --permanent --add-service=https
sudo firewall-cmd --reload
- Enable HTTPS with SSL/TLS
Security is non-negotiable. Use Let’s Encrypt to enable SSL for free:
sudo apt install certbot python3-certbot-apache -y
sudo certbot --apache
This will secure your site with HTTPS, protecting data transfers.
Managing Apache Services on Linux
Once Apache is installed, you’ll frequently need to manage it. Common commands include:
- Start Apache:
sudo systemctl start apache2
- Stop Apache:
sudo systemctl stop apache2
- Restart Apache:
sudo systemctl restart apache2
- Check Status:
sudo systemctl status apache2
Logs are located in /var/log/apache2/
(Ubuntu) or /var/log/httpd/
(CentOS). Monitoring these logs helps identify performance issues and security threats.
Common Issues and Fixes
Even with a proper setup, errors may occur. Some common problems include:
- Apache fails to start: Usually caused by port conflicts (port 80 or 443 already in use). Stop other services or change the port in the config file.
- Permission denied errors: Ensure that web files are owned by the correct user (
www-data
on Ubuntu orapache
on CentOS). - Firewall blocking access: Check your firewall rules to allow web traffic.
- Configuration errors: Run
apachectl configtest
to validate Apache’s configuration.
If you encounter errors, search for solutions to fix Apache issues in Linux, which often involves log analysis and configuration adjustments.
FAQs to Create Apache on Linux Server
How do I restart Apache in Linux?
You can restart Apache using the systemctl
command. On Ubuntu/Debian, run:
sudo systemctl restart apache2
On CentOS/RHEL, run:
sudo systemctl restart httpd
This ensures Apache reloads all configurations without shutting down your server.
How do I check if Apache is running on my Linux server?
Use the following command:
sudo systemctl status apache2 # For Ubuntu/Debian
sudo systemctl status httpd # For CentOS/RHEL
Alternatively, open your server’s IP address in a web browser. If you see the Apache welcome page or your hosted site, Apache is running successfully.
How do I enable SSL in Apache on Linux?
The easiest way is to install Certbot and get a free SSL certificate from Let’s Encrypt. On Ubuntu, use:
sudo apt install certbot python3-certbot-apache -y
sudo certbot --apache
For CentOS, install certbot
with yum
and run the same command. This enables HTTPS for your websites hosted on Apache.
Conclusion
Apache remains the backbone of web hosting on Linux. In this guide, you learned how to create Apache on a Linux server from scratch — including installation, configuration, security, and troubleshooting. With proper setup and regular maintenance, Apache can serve websites reliably for years to come. Whether you are a beginner experimenting with your first server or an experienced administrator managing production environments, Apache’s stability and flexibility make it the perfect choice for Linux hosting. For more, visit, Apache official documentation.