Your Search Bar For Shrewd Tips

How To Install Httpd In Ubuntu


How To Install Httpd In Ubuntu

If you're looking to set up a web server on your Ubuntu system, installing the Apache HTTP Server, commonly known as httpd, is a reliable and popular choice. Apache provides a robust platform for hosting websites, developing web applications, and managing server-side content. This comprehensive guide will walk you through the step-by-step process of installing and configuring httpd on Ubuntu, ensuring you can get your web server up and running smoothly.

Prerequisites for Installing Httpd on Ubuntu

  • Ubuntu Operating System: Ensure you are running a supported Ubuntu version (e.g., Ubuntu 20.04 LTS, 22.04 LTS).
  • Root or Sudo Privileges: You need administrative access to install packages and make system changes.
  • Stable Internet Connection: To download the necessary packages and dependencies.
  • Updated System: Before starting, it's recommended to update your system to ensure all repositories and packages are current.

Step 1: Update Your System

Before installing new software, always update your system's package list to ensure you have the latest information on available packages. Open your terminal and run the following commands:

sudo apt update
sudo apt upgrade -y

This process updates your package list and upgrades existing packages to their latest versions, reducing potential conflicts during installation.

Step 2: Install Apache HTTP Server (Httpd) on Ubuntu

In Ubuntu, the Apache HTTP Server is provided through the apache2 package. To install it, execute the following command:

sudo apt install apache2 -y

Once installed, the apache2 service will automatically start. You can verify its status with:

sudo systemctl status apache2

If the service is active and running, you're ready to proceed to configuration and testing.

Step 3: Configure Firewall to Allow HTTP and HTTPS Traffic

To make your web server accessible externally, you need to allow HTTP (port 80) and HTTPS (port 443) traffic through your firewall. Ubuntu uses ufw (Uncomplicated Firewall) for firewall management. Run these commands:

sudo ufw allow 'Apache Full'
sudo ufw enable

Check the status of your firewall rules to confirm:

sudo ufw status

Ensure that rules for Apache are active, allowing traffic on the necessary ports.

Step 4: Verify Your Apache Installation

Open a web browser and navigate to your server's IP address or domain name. If Apache installed correctly and is running, you should see the default Apache Ubuntu welcome page, which says:

It works!

If you see this page, your Apache server is successfully installed and accessible.

You can find your server's IP address by running:

ip a

or

hostname -I

Step 5: Manage the Apache Service

Apache service management commands include starting, stopping, restarting, and enabling the service to launch on boot. Use the following commands:

  • Start Apache: sudo systemctl start apache2
  • Stop Apache: sudo systemctl stop apache2
  • Restart Apache: sudo systemctl restart apache2
  • Enable Apache on boot: sudo systemctl enable apache2
  • Disable Apache from starting on boot: sudo systemctl disable apache2

Step 6: Configure Virtual Hosts (Optional but Recommended)

Virtual hosts allow you to host multiple websites on a single server. To set up a new virtual host, follow these steps:

  • Create a directory for your website:
sudo mkdir -p /var/www/yourdomain.com/public_html
  • Set permissions:
sudo chown -R $USER:$USER /var/www/yourdomain.com/public_html
  • Create a new virtual host file:
sudo nano /etc/apache2/sites-available/yourdomain.com.conf

Add the following configuration, replacing yourdomain.com with your actual domain:

<VirtualHost *:80>
    ServerAdmin admin@yourdomain.com
    ServerName yourdomain.com
    ServerAlias www.yourdomain.com
    DocumentRoot /var/www/yourdomain.com/public_html
    ErrorLog ${APACHE_LOG_DIR}/yourdomain.com_error.log
    CustomLog ${APACHE_LOG_DIR}/yourdomain.com_access.log combined
</VirtualHost>
  • Enable the virtual host and rewrite module:
sudo a2ensite yourdomain.com.conf
sudo a2enmod rewrite
  • Test the configuration for syntax errors:
sudo apache2ctl configtest
  • Reload Apache to apply changes:
sudo systemctl reload apache2

This setup allows you to serve multiple websites efficiently and securely.

Step 7: Secure Your Web Server with SSL (Optional)

For secure HTTPS connections, it’s recommended to install SSL certificates. The easiest way is to use Certbot with Let's Encrypt:

sudo apt install certbot python3-certbot-apache -y
sudo certbot --apache -d yourdomain.com -d www.yourdomain.com

Follow the prompts to obtain and install your SSL certificate. Certbot automatically configures your virtual host to redirect HTTP to HTTPS, ensuring secure data transmission.

Conclusion

Installing httpd (Apache) on Ubuntu is a straightforward process that involves updating your system, installing the Apache package, configuring your firewall, and optionally setting up virtual hosts and SSL certificates. With Apache installed, you can host websites, develop web applications, and manage server-side content efficiently. Remember to keep your server updated and secure to ensure optimal performance and safety. Whether you're a beginner or an experienced developer, this guide provides the essential steps to get your web server up and running on Ubuntu.


Disclaimer: Articles are written by Humans, AI or Both. Verify Important information.

Shrewdnia

Shrewdnia

Shrewdnia is a destination for curious minds seeking clarity, knowledge, and informed perspectives. Through insightful articles and practical guides our passionate team explores a wide range of topics designed to help readers understand the world around them, make smarter decisions, and stay informed in an ever-changing landscape.


πŸ’‘ Every question sparks discovery, and every perspective enriches the conversation. Share your thoughts and insights in the comments πŸ‘‡

Back to blog

Leave a comment

JOIN THE SHREWDNIA COMMUNITY FORUM

What do you think?

Have an opinion, experience, or question about this topic? Join the Shrewdnia Forum and share your thoughts with other readers.

Join the Forum β†’