Starting the Apache server on Linux typically uses the systemctl start httpd command for systemd distributions. If you are wondering how to start apache server in linux, you have come to the right place. This guide walks you through every step, from checking if Apache is installed to troubleshooting common issues. Whether you use Ubuntu, CentOS, or Debian, you will find clear instructions here.
Apache is one of the most popular web servers worldwide. It powers millions of websites. Knowing how to start, stop, and manage it is essential for any Linux user. Let us get started with the basics.
Prerequisites For Starting Apache
Before you start the Apache server, you need a few things in place. First, you must have root or sudo access on your Linux machine. Second, Apache should be installed. If it is not, you can install it easily.
Check if Apache is installed by running:
which apache2 or which httpd
If you see a path, Apache is installed. If not, install it using your package manager. For Ubuntu or Debian, use:
sudo apt update && sudo apt install apache2
For CentOS or RHEL, use:
sudo yum install httpd
Once installed, you are ready to start the server.
How To Start Apache Server In Linux
This is the core section of our guide. The exact command depends on your Linux distribution and init system. Most modern Linux distros use systemd. Older ones may use SysVinit.
Using Systemd (Modern Distributions)
Systemd is the default init system for Ubuntu 16.04+, CentOS 7+, Debian 8+, and Fedora. To start Apache, use the systemctl command.
- Open a terminal.
- Run:
sudo systemctl start apache2(for Debian/Ubuntu) orsudo systemctl start httpd(for CentOS/RHEL). - Check the status:
sudo systemctl status apache2orsudo systemctl status httpd.
If the status shows “active (running)”, Apache is working. You can also enable it to start on boot:
sudo systemctl enable apache2 or sudo systemctl enable httpd
Using SysVinit (Older Distributions)
For older Linux versions that use SysVinit, the command is different. Use the service command instead.
- Run:
sudo service apache2 startorsudo service httpd start. - Check status:
sudo service apache2 status.
This method still works on some systems, but systemd is now standard.
Starting Apache On Specific Distributions
Let us look at a few common distros in detail.
Ubuntu And Debian
On Ubuntu and Debian, the Apache package is called apache2. After installation, start it with:
sudo systemctl start apache2
Verify with:
sudo systemctl status apache2
You should see a green “active (running)” message. If you get an error, check the configuration file.
CentOS And RHEL
On CentOS 7 and 8, the package is httpd. Start it like this:
sudo systemctl start httpd
Then enable it:
sudo systemctl enable httpd
Check the firewall if you cannot access the server from a browser. You may need to open port 80.
sudo firewall-cmd --permanent --add-service=http
sudo firewall-cmd --reload
Fedora
Fedora uses the same commands as CentOS. Start with:
sudo systemctl start httpd
Enable boot start:
sudo systemctl enable httpd
OpenSUSE
On OpenSUSE, Apache is also called apache2. Use:
sudo systemctl start apache2
Starting Apache Without Sudo
If you do not have sudo access, you cannot start Apache normally. However, you can run a local instance as a regular user. This is useful for development.
First, create a custom configuration file. Then run:
apache2 -f /path/to/custom.conf -k start
This method is not recommended for production. Always use sudo for system-wide services.
Common Issues And Troubleshooting
Sometimes Apache does not start. Here are common problems and fixes.
Port 80 Already In Use
If another service uses port 80, Apache will fail. Check with:
sudo netstat -tulpn | grep :80
If you see a process like nginx, stop it first. Or change Apache’s port in the config file.
Configuration Syntax Errors
Apache checks its config before starting. If there is a typo, it will not start. Test the config with:
sudo apachectl configtest
Fix any errors it reports.
Permission Denied Errors
Apache needs read access to web files. If you see “Permission denied”, check file ownership. The Apache user (www-data or apache) must own or have read access.
sudo chown -R www-data:www-data /var/www/html
SELinux Blocking Apache
On CentOS and Fedora, SELinux can block Apache. Check the logs:
sudo ausearch -m avc -ts recent
If SELinux is the issue, set the correct context:
sudo chcon -R -t httpd_sys_content_t /var/www/html
Or disable SELinux temporarily (not recommended for production).
Managing Apache After Starting
Once Apache is running, you need to manage it. Here are common commands.
Stopping Apache
To stop the server:
sudo systemctl stop apache2 or sudo systemctl stop httpd
Restarting Apache
To restart after config changes:
sudo systemctl restart apache2
This stops and starts the server. For a graceful reload without dropping connections, use:
sudo systemctl reload apache2
Enabling And Disabling On Boot
To make Apache start automatically:
sudo systemctl enable apache2
To disable it:
sudo systemctl disable apache2
Testing Your Apache Installation
After starting Apache, test it. Open a web browser and go to:
http://localhost
You should see the default Apache welcome page. If you are on a remote server, use the server’s IP address instead.
You can also test from the command line:
curl http://localhost
If you see HTML output, Apache is working.
Virtual Hosts And Configuration
Apache can host multiple websites using virtual hosts. To set one up, create a config file in /etc/apache2/sites-available/ (Ubuntu) or /etc/httpd/conf.d/ (CentOS).
Example for Ubuntu:
- Create a file:
sudo nano /etc/apache2/sites-available/example.com.conf - Add basic config:
<VirtualHost *:80>
ServerAdmin webmaster@example.com
ServerName example.com
DocumentRoot /var/www/example.com
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
- Enable the site:
sudo a2ensite example.com.conf - Reload Apache:
sudo systemctl reload apache2
For CentOS, the process is similar but uses different paths.
Security Considerations
Running a web server requires security awareness. Here are quick tips.
- Keep Apache updated:
sudo apt update && sudo apt upgrade - Disable directory listing in config files.
- Use firewalls to restrict access.
- Regularly check logs: /var/log/apache2/error.log
- Use HTTPS with Let’s Encrypt for encryption.
Advanced Starting Options
Sometimes you need to start Apache with specific options.
Starting With Debug Mode
To see detailed output:
sudo apachectl -X
This runs Apache in debug mode. It stays in the foreground and shows errors.
Starting With A Different Config File
Use the -f flag:
sudo apachectl -f /etc/apache2/other.conf -k start
Starting Apache On A Different Port
Edit the Listen directive in ports.conf or httpd.conf. Change:
Listen 8080
Then restart Apache. Access it at http://localhost:8080.
Automating Apache Start With Scripts
You can create a bash script to start Apache automatically. This is useful for developers.
Example script:
#!/bin/bash
sudo systemctl start apache2
if [ $? -eq 0 ]; then
echo "Apache started successfully"
else
echo "Failed to start Apache"
fi
Make it executable: chmod +x start_apache.sh
Run it: ./start_apache.sh
Frequently Asked Questions
What Is The Command To Start Apache On Ubuntu?
The command is sudo systemctl start apache2. This works for Ubuntu 16.04 and later.
Why Does Apache Fail To Start On Linux?
Common reasons include port conflicts, syntax errors in config files, permission issues, or SELinux blocking. Check the error log at /var/log/apache2/error.log for details.
How Do I Start Apache Without Root?
You cannot start the system Apache without root. However, you can run a local instance as a regular user using a custom config file and the -f flag.
Can I Start Apache On CentOS With The Same Command As Ubuntu?
No. On CentOS, the service is called httpd, not apache2. Use sudo systemctl start httpd instead.
How Do I Know If Apache Is Running?
Use sudo systemctl status apache2 or sudo systemctl status httpd. You can also check with ps aux | grep apache or visit http://localhost in a browser.
Conclusion
Starting the Apache server on Linux is a straightforward process once you know your distribution. Use systemctl for modern systems or service for older ones. Always check the status after starting to confirm it works. With the steps in this guide, you can now start, stop, and manage Apache with confidence. Remember to test your setup and secure your server for production use. If you encounter issues, the troubleshooting section should help you resolve them quickly.
Now you know exactly how to start apache server in linux. Practice on a test machine first. Then apply these skills to your live server. Apache is a powerful tool, and mastering its startup is the first step to hosting websites effectively.