Setting Up Your Own Website with Apache Web Server

we’ll walk you through the process of setting up a personal website using the Apache web server on a Linux system. Let’s get started!

Step 1: Installing Apache

First things first, we need to install the Apache web server. Open a terminal and run the following commands:

yum install epel-release -y
yum install httpd* -y
systemctl start httpd.service && systemctl enable httpd.service

This installs Apache and starts the service.

Step 2: Configuring Firewall

Ensure that your firewall allows HTTP and HTTPS traffic:

firewall-cmd --permanent --zone=public --add-service=http --add-service=https
firewall-cmd --reload
firewall-cmd --list-all

Step 3: Setting Up Virtual Hosts

Virtual hosts allow you to host multiple websites on a single server. Follow these steps to create a virtual host:

# Create directories for configuration files
mkdir /etc/httpd/sites-available
mkdir /etc/httpd/sites-enabled

# Add the following line to the end of /etc/httpd/conf/httpd.conf
vim /etc/httpd/conf/httpd.conf
IncludeOptional sites-enabled/*.conf

Step 4: Creating Directory Structure

Create directories for your website content and logs:

mkdir -p /var/www/html/priyo.example.com/
mkdir -p /var/log/httpd/priyo.example.com/

Step 5: Granting Permissions

Set the correct permissions for your website directory:

chown -R apache:apache /var/www/html/priyo.example.com
chmod -R 744 /var/www/html/priyo.example.com
chcon -Rt httpd_sys_content_t /var/www/html/priyo.example.com
chcon -R -t httpd_sys_rw_content_t /var/www/html/priyo.example.com

Step 6: Creating Virtual Host Configuration

Create a configuration file for your virtual host:

vim /etc/httpd/sites-available/priyo.example.com.conf

Use the following template for your configuration:

<VirtualHost *:80>
    ServerName priyo.example.com
    ServerAlias www.priyo.example.com
    DocumentRoot /var/www/html/priyo.example.com
    ErrorLog /var/log/httpd/priyo.example.com/error.log
    CustomLog /var/log/httpd/priyo.example.com/requests.log combined
</VirtualHost>

Step 7: Enabling the Virtual Host

Create a symbolic link to enable the virtual host:

ln -s /etc/httpd/sites-available/priyo.example.com.conf /etc/httpd/sites-enabled/priyo.example.com.conf

Step 8: Restarting the Web Server

Restart Apache to apply the changes:

systemctl restart httpd.service

Step 9: Additional Configuration (Optional)

Optimize your Apache server by adding the following configuration at the end of /etc/httpd/conf/httpd.conf:

MaxKeepAliveRequests 500
KeepAliveTimeout 5
HostnameLookups Off
KeepAlive Off

<IfModule prefork.c>
   StartServers        5
   MinSpareServers     5
   MaxSpareServers     10
   MaxClients          150
   MaxRequestsPerChild 3000
</IfModule>

Leave a Comment

Your email address will not be published. Required fields are marked *