Apache is a widely used and popular open-source web server software. In this blog post, we will go through the process of how to install Apache on Oracle Linux, which is a free and open-source Linux distribution provided by Oracle. This step-by-step guide will help you get your Apache web server up and running in no time. So, let’s get started!
Table of Contents
- Prerequisites
- Installing Apache
- Configuring Apache
- Setting Up a Virtual Host
- Securing Apache with SSL/TLS
- Testing Your Apache Web Server
- Conclusion
How to Install Apache on Oracle Linux
Prerequisites
Before you can install Apache on Oracle Linux, you’ll need to have the following:
- Oracle Linux – Make sure you have Oracle Linux 7 or 8 installed on your server or virtual machine.
- SSH access – Have SSH access to your server with root privileges. If you need help changing the SSH port, check out our guide on how to change SSH port, as the process is similar to Oracle Linux.
- Updated system – Ensure your Oracle Linux system is up-to-date by running:
sudo yum update -y
Installing Apache on Oracle Linux
First, we need to install the Apache web server package. Follow these steps to install Apache on Oracle Linux:
- Install the Apache package – Run the following command to install Apache:
sudo yum install httpd -y
Start Apache – After installing Apache, start the web server with this command:
sudo systemctl start httpd
Enable Apache – To ensure Apache starts automatically upon boot, enable it with this command:
sudo systemctl enable httpd
Congratulations! You’ve successfully installed Apache on Oracle Linux.
Configuring Apache
After installing Apache, you’ll want to configure it to suit your needs. Here are some basic configuration steps:
- Edit the main configuration file – Open the Apache configuration file by running:
sudo nano /etc/httpd/conf/httpd.conf
Replace nano
with your preferred text editor, like vim
or emacs
. If you need help installing a text editor, you can refer to our guides on how to install Vim on Rocky Linux or how to install Nano on CentOS 8, as the process is similar for Oracle Linux.
Modify the configuration file – In the configuration file, you can change various settings such as the Listen
directive to change the default port Apache listens on, ServerName
to set the server’s fully qualified domain name (FQDN), and ServerAdmin
to set the email address of the server administrator.
Save and exit – Save the changes and exit the text editor.
Restart Apache – Restart the Apache web server to apply the changes:
sudo systemctl restart httpd
Setting Up a Virtual Host on Linux
Virtual hosts allow you to host multiple websites on a single Apache web server. To set up a virtual host, follow these steps:
- Create a directory for your website – Create a directory to store your website’s files:bash
sudo mkdir -p /var/www/example.com/public_html
Replace example.com
with your domain name.
Set the directory permissions – Adjust the directory permissions to allow the Apache user access:
sudo chown -R apache:apache /var/www/example.com/public_html
sudo chmod -R 755 /var/www
Create a virtual host configuration file – Create a new configuration file for your virtual host:
sudo nano /etc/httpd/conf.d/example.com.conf
Replace example.com
with your domain name.
Configure the virtual host – Add the following configuration to the file, replacing example.com
with your domain name and [email protected]
with your email address:
<VirtualHost *:80>
ServerAdmin [email protected]
DocumentRoot /var/www/example.com/public_html
ServerName example.com
ServerAlias www.example.com
ErrorLog /var/log/httpd/example.com-error.log
CustomLog /var/log/httpd/example.com-access.log combined
</VirtualHost>
Save and exit – Save the changes and exit the text editor.
Restart Apache – Restart the Apache web server to apply the changes:
sudo systemctl restart httpd
Securing Apache with SSL/TLS
Securing your Apache web server with SSL/TLS is crucial for protecting user data and ensuring secure connections. You can obtain an SSL certificate from a certificate authority (CA) like Let’s Encrypt. To secure your Apache web server, follow these steps:
- Install Certbot – Install the Certbot tool, which will help you obtain an SSL certificate from Let’s Encrypt:
sudo yum install certbot python3-certbot-apache -y
Request an SSL certificate – Run the following command to request an SSL certificate for your domain, replacing example.com
with your domain name:
sudo certbot --apache -d example.com -d www.example.com
Follow the prompts – Certbot will ask for your email address and agreement to the terms of service. After providing the required information, Certbot will automatically configure SSL/TLS for your virtual host.
Restart Apache – Restart the Apache web server to apply the changes:
sudo systemctl restart httpd
Testing Your Apache Web Server
After configuring your Apache web server and setting up a virtual host, you can test it by visiting your domain name in a web browser. If you see the Apache test page or your website’s content, your Apache web server is working correctly.
You can also verify that SSL/TLS is working by checking if your website is accessible via HTTPS.
Conclusion
You have now successfully installed and configured Apache on Oracle Linux. This guide has covered the installation process, basic configuration, setting up a virtual host, and securing your web server with SSL/TLS.
To further enhance your server setup, you may want to explore installing additional components, such as how to install MySQL on Rocky Linux, how to install PHP on Rocky Linux, or how to install phpMyAdmin on Rocky Linux, as the process is similar for Oracle Linux. These additional components can help you set up a complete LAMP stack (Linux, Apache, MySQL, and PHP) for your web applications.
If you need a control panel for your web hosting environment, you can refer to our guide on the best control panel for web hosting to make an informed decision. You can also explore guides on installing control panels like Plesk, CWP, or cPanel on Oracle Linux or other Linux distributions.
With your Apache web server now installed and configured, you are ready to host and manage your websites on Oracle Linux. Good luck, and enjoy the flexibility and power that Apache on Oracle Linux provides!