
Apache is an open-source web server that delivers static and dynamic web applications. It’s highly customizable, supports modular extensions, and can also function as a reverse proxy or load balancer for backend services.
In this article, you are to install Apache web server on Ubuntu 22.04 and deliver web applications securely on your server.
Before you begin:
Have an Ubuntu 22.04 server.
Set up a new A record for your domain that points to the server IP address.
Access the server using SSH as a non-root user with sudo privileges.
The Apache web server is available in the default repositories for Ubuntu 22.04. Follow the steps below to install the latest version using APT and enable the server to start automatically at boot.
Update the server's package index.
Install the Apache web server package.
View the installed Apache web server version.
Output:
Allow connections on the HTTP port 80.
Access your public server IP using a web browser such as Chrome and verify that the default Apache web page displays.
Apache is managed by the apache system service, which handles the web server’s runtime processes. Follow the steps below to enable Apache to start at boot and verify its service status.
Enable the Apache service to automatically start at boot time.
Output:
Start the Apache web server.
View the service status and verify that it's active on your server.
Output:
Stop the Apache web server.
Restart the Apache web server.
Follow the steps below to disable the default virtual host and create a new virtual host to listen for connection requests using your domain on the default HTTP port 80.
Create a new Apache virtual host configuration file in the /etc/apache2/sites-available/ directory using a text editor such as nano. For example, website.conf.
Add the following contents to the file. Replace app.example.com with your domain and webmaster@example.com with your web administrator email.
Save and close the file.
The above Apache configuration creates a new virtual host that delivers web application files from the /var/www/html/website directory using your domain app.example.com. Within the configuration:
<VirtualHost *:80>: Configures the virtual host to listen on HTTP port 80.ServerAdmin webmaster@example.com: Sets the administrator email for error notifications.ServerName example.com: Defines the domain for serving the web application. DocumentRoot /var/www/html/website: Specifies the web root directory containing the application files.DirectoryIndex index.html: Sets the default file to serve when the domain is accessed.ErrorLog ${APACHE_LOG_DIR}/error.log: Specifies the error log file location.CustomLog ${APACHE_LOG_DIR}/access.log combined: Defines the access log file using the combined log format.<Directory /var/www/html/example>: Applies configurations for requests to the web root directory.Options Indexes FollowSymLinks: Enables directory listing and symbolic link following.AllowOverride All: Permits .htaccess files to override settings.Require all granted: Grants access to all users for the web root directory.Disable the default Apache virtual host configuration.
Enable the new Apache virtual host configuration.
Create the web root directory /var/www/html/website referenced in your virtual host configuration.
Test the Apache configuration for errors.
Output:
Create a new sample HTML application index.html file in the web root directory.
Add the following contents to the file.
Save and close the file.
Grant the web server user and group www-data ownership privileges to the /var/www/html/website web root directory.
Restart the Apache web server to apply your configuration changes.
Follow the steps below to secure the Apache web server with Let's Encrypt SSL certificates, encrypt network connections, and redirect all HTTP traffic to HTTPS.
Install the Certbot Let's Encrypt client package using the Snap package manager.
Request a new Let's Encrypt SSL certificate on your server using your virtual host domain. Replace app.example.com with your actual domain and hello@example.com with your email address.
Test the Certbot SSL certificate renewal process.
Output:
Restart the Apache web server to apply your SSL configuration changes.
Follow the steps below to configure the UFW utility and allow network connections using the Apache web server firewall profile.
List all available UFW application profiles.
Verify that the default Apache profile apache is available similar to the following output:
Allow the Apache Full profile to enable both HTTP port 80 and HTTPS port 443 connections through the firewall.
Reload UFW to apply the firewall changes.
View the firewall status and verify that the new rules are available.
Output:
Access your virtual host domain app.example.com in a new web browser window and verify that Apache serves your HTML application with a Greetings from Vultr message.
You’ve installed Apache on your Ubuntu 22.04 server. Apache lets you host static websites and integrate with dynamic processors like PHP to serve applications such as WordPress. You can also configure Apache as a reverse proxy using the mod_proxy module to securely deliver backend services .For more information and configuration options, visit the Apache documentation.
0 Comments
Be the first to comment and share your perspective with the community.