How to Install A Web Server on CentOS 7?

10 minutes read

Installing a web server on CentOS 7 involves several steps. Here's a general overview of the process:

  1. Update the system: Before installing anything, it's important to update the system software and packages to ensure you have the latest versions and bug fixes.
  2. Install the Apache web server: Apache is a popular open-source web server software. You can install it using the package manager yum by running the command: sudo yum install httpd
  3. Start and enable the web server: Once Apache is installed, start the service using the command: sudo systemctl start httpd. To ensure it starts automatically at system boot, run: sudo systemctl enable httpd
  4. Configure firewall: By default, CentOS 7 comes with a firewall called firewalld. To allow HTTP and HTTPS traffic, you need to add rules to the firewall using the following commands: sudo firewall-cmd --permanent --add-service=http sudo firewall-cmd --permanent --add-service=https sudo firewall-cmd --reload
  5. Test the web server: To check if the web server is running, open a web browser and enter your server's IP address or domain name. If Apache is working correctly, you'll see the default CentOS Apache test page.
  6. Install additional modules if required: Depending on your specific web development needs, you may need additional modules or extensions. For example, if you're using PHP, you can install it by running: sudo yum install php


This process provides a basic installation of a web server using Apache on CentOS 7. Further configuration and setup may be required based on your specific requirements or application needs.

Best Website Hosting Providers in December 2024

1
Vultr

Rating is 5 out of 5

Vultr

  • Ultra-fast Intel Core
  • Low Price and High Quality
  • High Performance and Cheap Cloud Dedicated Servers
2
Digital Ocean

Rating is 4.9 out of 5

Digital Ocean

  • Active Digital Community
  • Simple To Use
  • Starting as low as 5$ per month
3
AWS

Rating is 4.8 out of 5

AWS

4
Cloudways

Rating is 4.7 out of 5

Cloudways


How to configure Fail2Ban to protect the web server on CentOS 7?

To configure Fail2Ban to protect the web server on CentOS 7, follow these steps:

  1. Install Fail2Ban: sudo yum install epel-release sudo yum install fail2ban
  2. Copy the default configuration file: sudo cp /etc/fail2ban/jail.conf /etc/fail2ban/jail.local
  3. Edit the configuration file /etc/fail2ban/jail.local using a text editor: sudo nano /etc/fail2ban/jail.local
  4. Configure the Web server section. For example, if you are using Apache, add or modify the following lines: [apache-auth] enabled = true port = http,https filter = apache-auth logpath = /var/log/httpd/error_log maxretry = 5 bantime = 3600
  5. Find the [DEFAULT] section and update the backend value to systemd: [DEFAULT] backend = systemd
  6. Save and close the file.
  7. Create a new filter file for Apache: sudo nano /etc/fail2ban/filter.d/apache-auth.conf
  8. Add the following content to the filter file: [Definition] failregex = ^.*[:error] \[client \] (AH01797: )?(client denied by server configuration|user .*? not found|was not found on this server).*$ ignoreregex =
  9. Save and close the file.
  10. Start and enable Fail2Ban service: sudo systemctl start fail2ban sudo systemctl enable fail2ban


Fail2Ban is now configured to protect the web server on your CentOS 7 system. It will monitor the specified log files for failed login attempts and block the IP addresses that exceed the defined threshold.


How to install a web server on CentOS 7?

To install a web server on CentOS 7, you can follow these steps:

  1. Update your system: Open a terminal and run the following command:
1
sudo yum update


  1. Install Apache HTTP server: Run the following command:
1
sudo yum install httpd


  1. Start the Apache service: After the installation, start the Apache service and enable it to start on boot using the following commands:
1
2
sudo systemctl start httpd
sudo systemctl enable httpd


  1. Adjust firewall settings: If you have the firewall enabled, you need to allow incoming HTTP and HTTPS traffic. To do so, run the following commands:
1
2
3
sudo firewall-cmd --permanent --add-service=http
sudo firewall-cmd --permanent --add-service=https
sudo firewall-cmd --reload


  1. Test the web server: Open a web browser and enter your server's IP address or domain name. You should see the Apache default test page if the installation was successful.


That's it! You have successfully installed a web server (Apache) on CentOS 7.


What is SSL/TLS and how to enable it for Apache on CentOS 7?

SSL stands for Secure Sockets Layer, while TLS stands for Transport Layer Security. They are cryptographic protocols that provide secure communication over a computer network, commonly used for secure online transactions, email, and data transfer.


To enable SSL/TLS for Apache on CentOS 7, you can follow these steps:

  1. Install Apache: If you have not already installed Apache, you can do so by running the following command: sudo yum install httpd
  2. Install OpenSSL: SSL/TLS relies on OpenSSL, so you need to ensure it is installed. Run the following command to install OpenSSL: sudo yum install mod_ssl openssl
  3. Generate SSL Certificate and Key: The next step is to generate a private key and a self-signed SSL certificate. Run the following command to generate them: sudo openssl req -x509 -nodes -newkey rsa:2048 -keyout /etc/pki/tls/private/apache.key -out /etc/pki/tls/certs/apache.crt -days 365
  4. Configure Apache SSL/TLS: Open the Apache SSL/TLS configuration file using a text editor. For example: sudo vi /etc/httpd/conf.d/ssl.conf Inside the file, ensure the following configurations are set correctly: SSLCertificateFile: /etc/pki/tls/certs/apache.crt SSLCertificateKeyFile: /etc/pki/tls/private/apache.key You can also configure other SSL/TLS settings as per your requirements.
  5. Enable SSL/TLS in Apache: Use the following command to enable SSL/TLS module in Apache: sudo a2enmod ssl
  6. Restart Apache: Restart Apache to apply the changes: sudo systemctl restart httpd


At this point, SSL/TLS should be enabled for Apache on CentOS 7. You can verify by accessing your website using HTTPS (e.g., https://yourdomain.com) and checking if the SSL certificate is correctly recognized by your browser.


How to generate a self-signed SSL certificate on CentOS 7?

To generate a self-signed SSL certificate on CentOS 7, you can follow these steps:

  1. Install OpenSSL if it is not already installed. You can do this by running the following command: sudo yum install openssl
  2. Generate a private key by running the following command: openssl genrsa -out key.pem 2048
  3. Generate a CSR (Certificate Signing Request) using the private key by running the following command: openssl req -new -key key.pem -out csr.pem During this step, you will be prompted to enter details such as the common name (CN) and organizational details. Make sure to enter the correct information.
  4. Generate a self-signed certificate using the private key and CSR by running the following command: openssl x509 -req -days 365 -in csr.pem -signkey key.pem -out cert.pem Adjust the number of days according to your requirements.
  5. Move the key and certificate files to their appropriate locations: sudo mv key.pem /etc/pki/tls/private/ sudo mv cert.pem /etc/pki/tls/certs/ sudo chmod 600 /etc/pki/tls/private/key.pem sudo chmod 644 /etc/pki/tls/certs/cert.pem
  6. Update the Apache configuration file to enable SSL and specify the paths to the key and certificate files. Open the Apache configuration file in a text editor: sudo nano /etc/httpd/conf.d/ssl.conf Inside the file, look for the following lines: SSLCertificateFile /etc/pki/tls/certs/localhost.crt SSLCertificateKeyFile /etc/pki/tls/private/localhost.key Replace the paths with the paths of the self-signed certificate and key: SSLCertificateFile /etc/pki/tls/certs/cert.pem SSLCertificateKeyFile /etc/pki/tls/private/key.pem Save the file and exit the editor.
  7. Restart the Apache service to apply the changes: sudo systemctl restart httpd


You have now generated a self-signed SSL certificate on CentOS 7. Note that self-signed certificates are not trusted by default by web browsers, so you might see a security warning when accessing your website.


How to prepare for CentOS 7 installation?

  1. Verify System Requirements: Ensure that your hardware meets the minimum system requirements for CentOS 7, such as sufficient disk space, memory, and a compatible processor.
  2. Obtain the CentOS 7 ISO: Download the CentOS 7 ISO file from the official CentOS website or a trusted mirror site. Choose the appropriate ISO file according to your system architecture (32-bit or 64-bit).
  3. Create Bootable Media: Burn the CentOS 7 ISO file to a DVD or create a bootable USB drive using tools like Rufus or UNetbootin.
  4. Back Up Data: Before proceeding with the installation, take a backup of your data to ensure that you don't lose any important files during the installation process.
  5. Configure BIOS Settings: If the installation is being done on a physical machine, ensure that the boot order is set to start from the DVD or USB drive. Also, disable any unnecessary settings like secure boot or fast boot.
  6. Start Installation: Insert the CentOS 7 installation media and restart your computer. Follow the on-screen instructions to start the CentOS 7 installation process.
  7. Language and Localization: Select your preferred language and localization options during the installation. This includes selecting the keyboard layout and time zone.
  8. Disk Partitioning: Choose the disk partitioning mode that best suits your requirement. CentOS 7 offers three options: automatic partitioning, manual partitioning, or configuring the disk manually.
  9. Network Configuration: Configure network settings like hostname, IP address, DNS, and proxy (if required).
  10. Software Selection: Select the software packages that you want to install with CentOS 7. You can choose from predefined selections like Minimal Install, Infrastructure Server, or customize the package selection based on your needs.
  11. Set Root Password: Assign a strong password for the root user, as it is the superuser account that has administrative privileges.
  12. User Account Creation: Create a regular user account with a strong password for day-to-day usage. This helps improve security by reducing the risk of using the root account for regular tasks.
  13. Installation Complete: Once the installation is completed, remove the installation media and restart the system.
  14. Post-Installation Configuration: After rebooting, perform any necessary post-installation configurations such as updating the system, installing additional software packages, configuring firewall rules, etc.


By following these steps, you will be well-prepared for the CentOS 7 installation process.

Facebook Twitter LinkedIn Whatsapp Pocket

Related Posts:

To install WordPress on CentOS 7, you can follow these steps:Log in to your CentOS 7 server using SSH or any other terminal client.Update the server packages by running the command: sudo yum update.Install the required packages for running WordPress by running...
To install Laravel on RackSpace, follow the steps outlined below:Set up a RackSpace cloud server: Start by creating a RackSpace account and launching a new cloud server instance. Make sure to choose an operating system compatible with Laravel, such as Ubuntu o...
Setting up a web hosting server on Windows involves several steps. Here is a brief overview of the process:Select a suitable Windows server operating system: Choose a version of Windows Server that meets your requirements and is compatible with the software yo...
New account creation in cPanel is fairly problem free. However, issues go for a toss when the wrong web site web page exhibits up. Often, the unsuitable web page exhibits up on account of unsuitable area configuration in cPanel. And, the web site homeowners us...
To run HumHub on Vultr, you can follow the steps below:Create a Vultr account: Go to the Vultr website and sign up for an account if you don't have one already. Deploy a new server: Once you are logged in, click on the "+" button in the top right c...
To install a web server on Linux, you need to follow these steps:Choose a web server software: Popular web server software for Linux includes Apache, Nginx, and Lighttpd. Select the one that suits your needs. Update your system: Before installing any software,...