
Apache is an open-source high-performance web server application that enables the delivery of static web applications. It's a widely used web server application that's highly extensible with modules that enable modern functionalities and integrate with dynamic web content processors such as PHP.
This article explains how to install Apache on Debian 12 and create sample virtual hosts to securely serve web applications on a server.
Before you begin:
app.example.com.Apache is available in the default package repositories on Ubuntu 24.04 with the latest package information. Follow the steps below to install Apache using the APT package manager on your server.
Update the server's package index.
Install Apache.
View the installed PHP version on your server.
Your output should be similar to the one below.
Allow the HTTP port 80 through the default firewall configuration.
Reload the firewall to apply changes.
Start the Apache web server.
Visit your server IP address using a web browser such as Chrome.
Verify that Apache delivers the default virtual host web application page in your browser.
Apache uses the apache system service to manage the application processes and runtime on your server. Follow the steps below to enable the Apache web server to automatically start at boot time, and manage the system service processes.
Enable Apache to automatically start at system boot.
Start the Apache web server.
View the Apache service status and verify that it's running.
Output:
Stop the Apache service.
Restart the Apache service.
Reload the Apache web server configuration to apply configuration changes without affecting the existing connections.
Apache virtual host profiles enable the web server to deliver web applications with specific configurations and file types. The /etc/apache2/sites-available directory contains Apache virtual host configuration files that define specific addresses or domains to serve web applications on your server. Follow the steps below to create a new Apache virtual host to serve sample web application files using the example domain app.example.com.
Disable the default Apache virtual host configuration.
Create a new Apache virtual host configuration. For example, app.example.com.conf.
Add the following contents to the file. Replace app.example.com with your actual domain.
Save and close the file.
The above configuration creates a new Apache virtual host that listens for connection requests on the HTTP port 80 using the domain app.example.com to deliver web application files from the web root directory /var/www/app.example.com.
Test the Apache configuration for errors.
Output:
Enable the Apache virtual host configuration.
Create the virtual host's web root directory /var/www/app.example.com.
Grant the Apache user www ownership privileges to the web root directory.
Change the directory permissions to 755 to grant the Apache user full privileges to all available files.
The above 755 permission mode sets the following privileges on the directory and all files:
7: Read, write and execute permissions to the www user.5: Read and execute permissions to the www user group.5: Read and execute permissions to other system users.Create a new sample HTML application file index.html in the virtual host's web root directory.
Add the following contents to the file.
Save and close the file.
The above HTML application displays a Greetings from Vultr message when accessed in a web browser.
Restart the Apache service to apply your configuration changes.
Access your domain in a web browser window and verify that Apache serves your index.html web application.
Apache listens for connection requests using your domain on the default HTTP port 80 using your virtual host configuration. HTTP connections are insecure and do not include any encryption mechanisms by default. Enable HTTPS connections using valid SSL certificates to encrypt all requests between a user's web browser and the Apache web server. Follow the steps below to generate trusted Let's Encrypt SSL certificates and secure the Apache web server.
Install the Snap package manager on your server.
Install the Certbot Let's Encrypt client tool using Snap.
Verify the installed Certbot version on your server.
Output:
Generate a new SSL certificate for your virtual host domain. Replace app.example.com with your actual domain and user@example.com with your email address.
Output:
Test the Certbot automatic SSL certificate renewal process.
Output:
Allow network connections on the HTTPS port 443 through the firewall.
Reload the firewall configuration to apply changes.
Visit your domain in a new web browser window using HTTPS and verify that your connection is secure.
Verify that a Connection is secure prompt displays in your browser's URL bar.
You have installed Apache on your Debian 12 server and enabled the web server to deliver web applications using virtual host configurations. You can integrate Apache with other applications such as PHP to enable additional functionalities and processing of specific content types on your server. For more information and configuration options, visit the official Apache documentation.
0 Comments
Be the first to comment and share your perspective with the community.