How to Install and Configure Apache Web Server on Linux

How to Install and Configure Apache Web Server on Linux

  1. Update your server

    • Open terminal.
    • Run: sudo apt update.
  2. Install Apache

    • Run: sudo apt install apache2.
  3. Start Apache service

    • Run: sudo systemctl start apache2.
  4. Enable Apache to start at boot

    • Run: sudo systemctl enable apache2.
  5. Check Apache status

    • Run: sudo systemctl status apache2.
  6. Open firewall for Apache

    • Run: sudo ufw allow 'Apache'.
  7. Verify firewall settings

    • Run: sudo ufw status.
  8. Check Apache default page

    • Open browser.
    • Go to: http://your_server_ip.
  9. Configure Apache

    • Edit config file: sudo nano /etc/apache2/apache2.conf.
    • Make changes.
    • Save and close file.
  10. Restart Apache

    • Run: sudo systemctl restart apache2.
  11. Check config syntax

    • Run: sudo apache2ctl configtest.
  12. Create new site config

    • Run: sudo nano /etc/apache2/sites-available/your_site.conf.
  13. 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.
  14. Enable new site

    • Run: sudo a2ensite your_site.conf.
  15. Disable default site

    • Run: sudo a2dissite 000-default.conf.
  16. Reload Apache

    • Run: sudo systemctl reload apache2.
  17. Check your site

    • Open browser.
    • Go to: http://your_server_ip.

Conclusion

You have installed and configured Apache. Enjoy your new web server!

Vibe Plus 1

Sami Rahimi

Innovate relentlessly. Shape the future..

Recent Comments

Vibe Plus 1
MHBH

Great

Vibe Plus 1
MHBH

Thank you

Post your Comments (first log in)