How to Install and Configure Apache Web Server on Linux
-
Update your server
- Open terminal.
- Run:
sudo apt update
.
-
Install Apache
- Run:
sudo apt install apache2
.
- Run:
-
Start Apache service
- Run:
sudo systemctl start apache2
.
- Run:
-
Enable Apache to start at boot
- Run:
sudo systemctl enable apache2
.
- Run:
-
Check Apache status
- Run:
sudo systemctl status apache2
.
- Run:
-
Open firewall for Apache
- Run:
sudo ufw allow 'Apache'
.
- Run:
-
Verify firewall settings
- Run:
sudo ufw status
.
- Run:
-
Check Apache default page
- Open browser.
- Go to:
http://your_server_ip
.
-
Configure Apache
- Edit config file:
sudo nano /etc/apache2/apache2.conf
. - Make changes.
- Save and close file.
- Edit config file:
-
Restart Apache
- Run:
sudo systemctl restart apache2
.
- Run:
-
Check config syntax
- Run:
sudo apache2ctl configtest
.
- Run:
-
Create new site config
- Run:
sudo nano /etc/apache2/sites-available/your_site.conf
.
- Run:
-
Add site config
- Example:
<VirtualHost *:80> ServerAdmin webmaster@localhost DocumentRoot /var/www/html/your_site ErrorLog ${APACHE_LOG_DIR}/error.log CustomLog ${APACHE_LOG_DIR}/access.log combined </VirtualHost>
- Save and close file.
- Example:
-
Enable new site
- Run:
sudo a2ensite your_site.conf
.
- Run:
-
Disable default site
- Run:
sudo a2dissite 000-default.conf
.
- Run:
-
Reload Apache
- Run:
sudo systemctl reload apache2
.
- Run:
-
Check your site
- Open browser.
- Go to:
http://your_server_ip
.
Conclusion
You have installed and configured Apache. Enjoy your new web server!
Sami Rahimi
Innovate relentlessly. Shape the future..
Recent Comments
MHBH
Thank you
Great