Apache HTTP Server, often referred to as just Apache, is one of the most popular and widely used web server software. It is open-source, reliable, and highly customizable. In this tutorial, we will guide you through the process of how to install Apache on Scientific Linux step by step.
Prerequisites
Before you begin, make sure that you have the following:
- A system running Scientific Linux
- A user account with sudo privileges
How to Install Apache on Scientific Linux
Update the System
First and foremost, you need to ensure that your system is up to date. You can do this by running the following command:
sudo yum update -y
This command will update all installed packages on your system.
Install Apache on Scientific Linux
Now that your system is up to date, you can proceed with installing Apache. Run the following command to install the latest version of Apache:
sudo yum install httpd -y
This command will install Apache and all its dependencies.
Start and Enable Apache on Scientific Linux
Once the installation is complete, start the Apache service by running the following command:
sudo systemctl start httpd
To ensure that Apache starts automatically whenever the system boots, enable it using this command:
sudo systemctl enable httpd
Configure Firewall on Scientific Linux
In order to allow incoming HTTP and HTTPS traffic, you will need to open the necessary ports on your firewall. Run the following commands to achieve this:
sudo firewall-cmd --add-service=http --permanent
sudo firewall-cmd --add-service=https --permanent
sudo firewall-cmd --reload
These commands will open ports 80 and 443 and reload the firewall configuration.
Test Apache Installation on Scientific Linux
To verify that Apache is running correctly, open your web browser and navigate to the following address:
http://your_server_IP_address
Replace your_server_IP_address
with the actual IP address of your Scientific Linux server. You should see the default Apache welcome page, which confirms that the installation was successful.
Configure Apache on Scientific Linux (Optional)
By default, Apache stores its main configuration file at /etc/httpd/conf/httpd.conf
. You can edit this file using any text editor, such as nano or vim.
For example, to change the default listening port for Apache, open the configuration file and search for the following line:
Listen 80
Change the port number to your desired value and save the file. Restart Apache for the changes to take effect:
sudo systemctl restart httpd
Create a Virtual Host on Apache Server (Optional)
Apache supports virtual hosting, allowing you to host multiple websites on a single server. To create a new virtual host, follow these steps:
- Create a new directory for your website:
sudo mkdir -p /var/www/your_domain/public_html
Replace your_domain
with your actual domain name.
Set the appropriate ownership and permissions for the newly created directory:
sudo chown -R apache:apache /var/www/your_domain/public_html
sudo chmod -R 755 /var/www/your_domain
Create a new virtual host configuration file:
sudo nano /etc/httpd/conf.d/your_domain.conf
Add the following configuration to the newly created file:
<VirtualHost *:80>
ServerAdmin [email protected]
DocumentRoot "/var/www/html"
ServerName example.com
ServerAlias www.example.com
ErrorLog "/var/log/httpd/error.log"
CustomLog "/var/log/httpd/access.log" combined
</VirtualHost>
<VirtualHost *:443>
ServerAdmin [email protected]
DocumentRoot "/var/www/html"
ServerName example.com
ServerAlias www.example.com
ErrorLog "/var/log/httpd/error.log"
CustomLog "/var/log/httpd/access.log" combined
SSLEngine on
SSLCertificateFile "/etc/pki/tls/certs/server.crt"
SSLCertificateKeyFile "/etc/pki/tls/private/server.key"
</VirtualHost>
With this configuration, Apache will listen on both ports 80 (HTTP) and 443 (HTTPS) and serve the same document root for both. Replace example.com
and [email protected]
with your actual domain and email address. The SSL configuration points to the locations of the SSL certificate and key files.
Now, save and close the configuration file. Next, you need to enable SSL support and adjust the firewall settings.
Step 5: Enable SSL Support and Configure the Firewall
First, install the mod_ssl
package:
sudo yum install mod_ssl
Next, restart Apache to apply the changes:
sudo systemctl restart httpd
Adjust the firewall settings to allow incoming traffic on ports 80 and 443:
sudo firewall-cmd --add-service=http --permanent
sudo firewall-cmd --add-service=https --permanent
sudo firewall-cmd --reload
Test the Apache Installation
Open your web browser and visit your server’s IP address or domain name. You should see the default Apache test page. If you have configured a domain name, you can test the SSL configuration by visiting https://yourdomain.com
. You should see a padlock icon in your browser’s address bar, indicating a secure connection.
Congratulations! You have successfully installed Apache on Scientific Linux with SSL support. Now you can start building your website or web application.
For further customization and optimization, you may want to explore additional Apache modules and features. Be sure to check out our other tutorials on Linux server administration, such as how to install nano on Scientific Linux, how to install Vim on Scientific Linux, and how to set up a bridged network for KVM.