Apache is a very popular and commonly used open-source web server that can run on both Linux and Windows operating systems. In this blog, we will build a very basic static Apache website and later branch this out to a dynamic webpage using LEMP stack.
Lab Server Setup:
Hostname: lnx03.ash.local
Operating System: Redhat 9.2
Packages and Config files required for the Apache server
- httpd – Package installs the Apache web server.
- mod_ssl -Additional package required to create secure websites ie: SSL
- links – Optional package for text-based web browser
Default ports: 80 and 443 (SSL)
These are the main folders storing Apache config files
Purpose | Location |
Default Parent Directory | /var/www/html |
Main Apache root configuration directory. | /etc/httpd |
Additional Apache configuration files are provided by third-party software. | /etc/httpd/conf.d |
Main Configuration file | /etc/httpd/conf/httpd.conf |
Configuration files for additional modules.( SymLink to /etc/httpd/modules) | /var/lib/httpd/modules |
Configuration files which load modules | /etc/httpd/conf.modules.d/ directory (e.g. PHP) |
Contains log files ( SymLink to /etc/httpd/logs) | /etc/log/httpd |
Main web document root directory | /var/www |
Access Logs | /var/log/httpd/example.com.access.log |
Error Logs | /var/log/httpd/example.com.error.log |
Step 1 – Set up the host file
1 2 3 4 5 6 7 8 9 |
<span class="line"><span style="color: #A6ACCD">[</span><span style="color: #E4F0FB">root</span><span style="color: #A6ACCD">@</span><span style="color: #E4F0FB">lnx03</span><span style="color: #A6ACCD"> </span><span style="color: #91B4D5">~</span><span style="color: #A6ACCD">]# </span><span style="color: #E4F0FB">cat</span><span style="color: #A6ACCD"> </span><span style="color: #91B4D5">/</span><span style="color: #E4F0FB">etc</span><span style="color: #91B4D5">/</span><span style="color: #E4F0FB">hostname</span><span style="color: #A6ACCD"> </span></span> <span class="line"><span style="color: #E4F0FB">lnx03</span></span> <span class="line"><span style="color: #A6ACCD">[</span><span style="color: #E4F0FB">root</span><span style="color: #A6ACCD">@</span><span style="color: #E4F0FB">lnx03</span><span style="color: #A6ACCD"> </span><span style="color: #91B4D5">~</span><span style="color: #A6ACCD">]# </span><span style="color: #E4F0FB">cat</span><span style="color: #A6ACCD"> </span><span style="color: #91B4D5">/</span><span style="color: #E4F0FB">etc</span><span style="color: #91B4D5">/</span><span style="color: #E4F0FB">hosts</span><span style="color: #A6ACCD"> </span></span> <span class="line"><span style="color: #5DE4C7">127.0</span><span style="color: #A6ACCD">.</span><span style="color: #5DE4C7">0.1</span><span style="color: #A6ACCD"> </span><span style="color: #E4F0FB">localhost</span><span style="color: #A6ACCD"> </span><span style="color: #E4F0FB">localhost</span><span style="color: #A6ACCD">.</span><span style="color: #E4F0FB">localdomain</span><span style="color: #A6ACCD"> </span><span style="color: #E4F0FB">localhost4</span><span style="color: #A6ACCD"> </span><span style="color: #E4F0FB">localhost4</span><span style="color: #A6ACCD">.</span><span style="color: #E4F0FB">localdomain4</span></span> <span class="line"><span style="color: #A6ACCD">::</span><span style="color: #5DE4C7">1</span><span style="color: #A6ACCD"> </span><span style="color: #E4F0FB">localhost</span><span style="color: #A6ACCD"> </span><span style="color: #E4F0FB">localhost</span><span style="color: #A6ACCD">.</span><span style="color: #E4F0FB">localdomain</span><span style="color: #A6ACCD"> </span><span style="color: #E4F0FB">localhost6</span><span style="color: #A6ACCD"> </span><span style="color: #E4F0FB">localhost6</span><span style="color: #A6ACCD">.</span><span style="color: #E4F0FB">localdomain6</span></span> <span class="line"><span style="color: #5DE4C7">192.168</span><span style="color: #A6ACCD">.</span><span style="color: #5DE4C7">0.21</span><span style="color: #A6ACCD"> </span><span style="color: #E4F0FB">lnx03</span><span style="color: #A6ACCD"> </span><span style="color: #E4F0FB">lnx03</span><span style="color: #A6ACCD">.</span><span style="color: #E4F0FB">ash</span><span style="color: #A6ACCD">.</span><span style="color: #E4F0FB">local</span></span> <span class="line"><span style="color: #A6ACCD">[</span><span style="color: #E4F0FB">root</span><span style="color: #A6ACCD">@</span><span style="color: #E4F0FB">lnx03</span><span style="color: #A6ACCD"> </span><span style="color: #91B4D5">~</span><span style="color: #A6ACCD">]# </span><span style="color: #E4F0FB">ç</span></span> <span class="line"></span> <span class="line"></span> |
Step 2 – Install the Apache server and the mod ssl package using the following command
1 |
<span class="line"><span style="color: #A6ACCD"> </span><span style="color: #E4F0FB">dnf</span><span style="color: #A6ACCD"> </span><span style="color: #E4F0FB">install</span><span style="color: #A6ACCD"> </span><span style="color: #91B4D5">--</span><span style="color: #E4F0FB">assumeyes</span><span style="color: #A6ACCD"> </span><span style="color: #E4F0FB">httpd</span><span style="color: #A6ACCD"> </span><span style="color: #E4F0FB">mod_ssl</span></span> |
Step 3 – Check Apache daemon(httpd) install
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
<span class="line"><span style="color: #A6ACCD">[</span><span style="color: #E4F0FB">root</span><span style="color: #A6ACCD">@</span><span style="color: #E4F0FB">lnx03</span><span style="color: #A6ACCD"> </span><span style="color: #91B4D5">/</span><span style="color: #A6ACCD">]# </span></span> <span class="line"><span style="color: #A6ACCD">[</span><span style="color: #E4F0FB">root</span><span style="color: #A6ACCD">@</span><span style="color: #E4F0FB">lnx03</span><span style="color: #A6ACCD"> </span><span style="color: #91B4D5">/</span><span style="color: #A6ACCD">]# </span><span style="color: #E4F0FB">dnf</span><span style="color: #A6ACCD"> </span><span style="color: #E4F0FB">list</span><span style="color: #A6ACCD"> </span><span style="color: #E4F0FB">httpd</span><span style="color: #A6ACCD"> </span></span> <span class="line"><span style="color: #E4F0FB">Updating</span><span style="color: #A6ACCD"> </span><span style="color: #E4F0FB">Subscription</span><span style="color: #A6ACCD"> </span><span style="color: #E4F0FB">Management</span><span style="color: #A6ACCD"> </span><span style="color: #E4F0FB">repositories</span><span style="color: #A6ACCD">.</span></span> <span class="line"><span style="color: #E4F0FB">Last</span><span style="color: #A6ACCD"> </span><span style="color: #E4F0FB">metadata</span><span style="color: #A6ACCD"> </span><span style="color: #E4F0FB">expiration</span><span style="color: #A6ACCD"> </span><span style="color: #91B4D5">check</span><span style="color: #A6ACCD">: </span><span style="color: #5DE4C7">0</span><span style="color: #A6ACCD">:</span><span style="color: #5DE4C7">02</span><span style="color: #A6ACCD">:</span><span style="color: #5DE4C7">48</span><span style="color: #A6ACCD"> </span><span style="color: #E4F0FB">ago</span><span style="color: #A6ACCD"> </span><span style="color: #E4F0FB">on</span><span style="color: #A6ACCD"> </span><span style="color: #E4F0FB">Mon</span><span style="color: #A6ACCD"> </span><span style="color: #5DE4C7">30</span><span style="color: #A6ACCD"> </span><span style="color: #E4F0FB">Oct</span><span style="color: #A6ACCD"> </span><span style="color: #5DE4C7">2023</span><span style="color: #A6ACCD"> </span><span style="color: #5DE4C7">06</span><span style="color: #A6ACCD">:</span><span style="color: #5DE4C7">24</span><span style="color: #A6ACCD">:</span><span style="color: #5DE4C7">38</span><span style="color: #A6ACCD"> </span><span style="color: #E4F0FB">GMT</span><span style="color: #A6ACCD">.</span></span> <span class="line"><span style="color: #E4F0FB">Installed</span><span style="color: #A6ACCD"> </span><span style="color: #E4F0FB">Packages</span></span> <span class="line"><span style="color: #E4F0FB">httpd</span><span style="color: #A6ACCD">.</span><span style="color: #E4F0FB">x86_64</span><span style="color: #A6ACCD"> </span><span style="color: #5DE4C7">2.4</span><span style="color: #A6ACCD">.</span><span style="color: #5DE4C7">53</span><span style="color: #91B4D5">-</span><span style="color: #A6ACCD">11.</span><span style="color: #E4F0FB">el9_2</span><span style="color: #A6ACCD">.</span><span style="color: #5DE4C7">5</span><span style="color: #A6ACCD"> @</span><span style="color: #E4F0FB">rhel</span><span style="color: #91B4D5">-</span><span style="color: #5DE4C7">9</span><span style="color: #91B4D5">-</span><span style="color: #E4F0FB">for</span><span style="color: #91B4D5">-</span><span style="color: #E4F0FB">x86_64</span><span style="color: #91B4D5">-</span><span style="color: #E4F0FB">appstream</span><span style="color: #91B4D5">-</span><span style="color: #E4F0FB">rpms</span></span> <span class="line"></span> <span class="line"></span> <span class="line"><span style="color: #A6ACCD">[</span><span style="color: #E4F0FB">root</span><span style="color: #A6ACCD">@</span><span style="color: #E4F0FB">lnx03</span><span style="color: #A6ACCD"> </span><span style="color: #91B4D5">/</span><span style="color: #A6ACCD">]# </span><span style="color: #E4F0FB">yum</span><span style="color: #A6ACCD"> </span><span style="color: #E4F0FB">list</span><span style="color: #A6ACCD"> </span><span style="color: #E4F0FB">httpd</span></span> <span class="line"><span style="color: #E4F0FB">Updating</span><span style="color: #A6ACCD"> </span><span style="color: #E4F0FB">Subscription</span><span style="color: #A6ACCD"> </span><span style="color: #E4F0FB">Management</span><span style="color: #A6ACCD"> </span><span style="color: #E4F0FB">repositories</span><span style="color: #A6ACCD">.</span></span> <span class="line"><span style="color: #E4F0FB">Last</span><span style="color: #A6ACCD"> </span><span style="color: #E4F0FB">metadata</span><span style="color: #A6ACCD"> </span><span style="color: #E4F0FB">expiration</span><span style="color: #A6ACCD"> </span><span style="color: #91B4D5">check</span><span style="color: #A6ACCD">: </span><span style="color: #5DE4C7">0</span><span style="color: #A6ACCD">:</span><span style="color: #5DE4C7">03</span><span style="color: #A6ACCD">:</span><span style="color: #5DE4C7">15</span><span style="color: #A6ACCD"> </span><span style="color: #E4F0FB">ago</span><span style="color: #A6ACCD"> </span><span style="color: #E4F0FB">on</span><span style="color: #A6ACCD"> </span><span style="color: #E4F0FB">Mon</span><span style="color: #A6ACCD"> </span><span style="color: #5DE4C7">30</span><span style="color: #A6ACCD"> </span><span style="color: #E4F0FB">Oct</span><span style="color: #A6ACCD"> </span><span style="color: #5DE4C7">2023</span><span style="color: #A6ACCD"> </span><span style="color: #5DE4C7">06</span><span style="color: #A6ACCD">:</span><span style="color: #5DE4C7">24</span><span style="color: #A6ACCD">:</span><span style="color: #5DE4C7">38</span><span style="color: #A6ACCD"> </span><span style="color: #E4F0FB">GMT</span><span style="color: #A6ACCD">.</span></span> <span class="line"><span style="color: #E4F0FB">Installed</span><span style="color: #A6ACCD"> </span><span style="color: #E4F0FB">Packages</span></span> <span class="line"><span style="color: #E4F0FB">httpd</span><span style="color: #A6ACCD">.</span><span style="color: #E4F0FB">x86_64</span><span style="color: #A6ACCD"> </span><span style="color: #5DE4C7">2.4</span><span style="color: #A6ACCD">.</span><span style="color: #5DE4C7">53</span><span style="color: #91B4D5">-</span><span style="color: #A6ACCD">11.</span><span style="color: #E4F0FB">el9_2</span><span style="color: #A6ACCD">.</span><span style="color: #5DE4C7">5</span><span style="color: #A6ACCD"> @</span><span style="color: #E4F0FB">rhel</span><span style="color: #91B4D5">-</span><span style="color: #5DE4C7">9</span><span style="color: #91B4D5">-</span><span style="color: #E4F0FB">for</span><span style="color: #91B4D5">-</span><span style="color: #E4F0FB">x86_64</span><span style="color: #91B4D5">-</span><span style="color: #E4F0FB">appstream</span><span style="color: #91B4D5">-</span><span style="color: #E4F0FB">rpms</span></span> <span class="line"><span style="color: #A6ACCD">[</span><span style="color: #E4F0FB">root</span><span style="color: #A6ACCD">@</span><span style="color: #E4F0FB">lnx03</span><span style="color: #A6ACCD"> </span><span style="color: #91B4D5">/</span><span style="color: #A6ACCD">]# </span></span> <span class="line"></span> |
Step 4 – Enable the Apache service with either httpd.service or apache2.service using the below command
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
<span class="line"><span style="color: #F8F8F2"># To Manage httpd deamon</span></span> <span class="line"><span style="color: #F8F8F2"># systemctl start</span><span style="color: #F92672">|</span><span style="color: #F8F8F2">stop</span><span style="color: #F92672">|</span><span style="color: #F8F8F2">status httpd.service</span></span> <span class="line"></span> <span class="line"><span style="color: #F8F8F2"># To Stop and Disable Service</span></span> <span class="line"><span style="color: #F8F8F2">systemctl enable </span><span style="color: #F92672">|</span><span style="color: #F8F8F2">disable httpd.service </span></span> <span class="line"></span> <span class="line"><span style="color: #F8F8F2"># To Ensure service stays peristant during reboots</span></span> <span class="line"><span style="color: #F8F8F2">chkconfig httpd on</span></span> <span class="line"></span> <span class="line"><span style="color: #F8F8F2"># To Show status </span><span style="color: #F92672">of</span><span style="color: #F8F8F2"> httpd</span></span> <span class="line"><span style="color: #F8F8F2">systemctl list</span><span style="color: #F92672">-</span><span style="color: #F8F8F2">unitfiles </span><span style="color: #F92672">|</span><span style="color: #F8F8F2"> grep httpd</span></span> <span class="line"></span> <span class="line"><span style="color: #F8F8F2">Optionally, services can be restarted </span><span style="color: #F92672">as</span><span style="color: #F8F8F2"> </span></span> <span class="line"><span style="color: #F92672">/</span><span style="color: #F8F8F2">etc</span><span style="color: #F92672">/</span><span style="color: #F8F8F2">init.d</span><span style="color: #F92672">/</span><span style="color: #F8F8F2">httpd </span><span style="color: #F92672">|</span><span style="color: #F8F8F2"> stop </span><span style="color: #F92672">|</span><span style="color: #F8F8F2"> start</span></span> <span class="line"></span> |
1 2 3 4 5 6 7 8 9 10 11 |
<span class="line"><span style="color: #F6F6F4">[root@lnx03 </span><span style="color: #F286C4">/</span><span style="color: #F6F6F4">]# </span></span> <span class="line"><span style="color: #F6F6F4">[root@lnx03 </span><span style="color: #F286C4">/</span><span style="color: #F6F6F4">]# systemctl enable httpd</span></span> <span class="line"><span style="color: #F6F6F4">Created symlink </span><span style="color: #F286C4">/</span><span style="color: #F6F6F4">etc</span><span style="color: #F286C4">/</span><span style="color: #F6F6F4">systemd</span><span style="color: #F286C4">/</span><span style="color: #F6F6F4">system</span><span style="color: #F286C4">/</span><span style="color: #F6F6F4">multi</span><span style="color: #F286C4">-</span><span style="color: #F6F6F4">user.target.wants</span><span style="color: #F286C4">/</span><span style="color: #F6F6F4">httpd.service → </span><span style="color: #F286C4">/</span><span style="color: #F6F6F4">usr</span><span style="color: #F286C4">/</span><span style="color: #F6F6F4">lib</span><span style="color: #F286C4">/</span><span style="color: #F6F6F4">systemd</span><span style="color: #F286C4">/</span><span style="color: #F6F6F4">system</span><span style="color: #F286C4">/</span><span style="color: #F6F6F4">httpd.service.</span></span> <span class="line"><span style="color: #F6F6F4">[root@lnx03 </span><span style="color: #F286C4">/</span><span style="color: #F6F6F4">]# systemctl start httpd </span></span> <span class="line"><span style="color: #F6F6F4">[root@lnx03 </span><span style="color: #F286C4">/</span><span style="color: #F6F6F4">]# </span></span> <span class="line"><span style="color: #F6F6F4">[root@lnx03 </span><span style="color: #F286C4">/</span><span style="color: #F6F6F4">]# </span></span> <span class="line"><span style="color: #F6F6F4">[root@lnx03 </span><span style="color: #F286C4">/</span><span style="color: #F6F6F4">]# systemctl status httpd </span></span> <span class="line"><span style="color: #F6F6F4">● httpd.service </span><span style="color: #F286C4">-</span><span style="color: #F6F6F4"> The Apache HTTP Server</span></span> <span class="line"><span style="color: #F6F6F4"> Loaded: </span><span style="color: #62E884">loaded</span><span style="color: #F6F6F4"> (</span><span style="color: #F286C4">/</span><span style="color: #F6F6F4">usr</span><span style="color: #F286C4">/</span><span style="color: #F6F6F4">lib</span><span style="color: #F286C4">/</span><span style="color: #F6F6F4">systemd</span><span style="color: #F286C4">/</span><span style="color: #F6F6F4">system</span><span style="color: #F286C4">/</span><span style="color: #F6F6F4">httpd.service; enabled; preset: disabled)</span></span> <span class="line"><span style="color: #F6F6F4"> Active: </span><span style="color: #62E884">active</span><span style="color: #F6F6F4"> (running) since Mon </span><span style="color: #BF9EEE">2023</span><span style="color: #F286C4">-</span><span style="color: #BF9EEE">10</span><span style="color: #F286C4">-</span><span style="color: #BF9EEE">30</span><span style="color: #F6F6F4"> </span><span style="color: #BF9EEE">06</span><span style="color: #F6F6F4">:</span><span style="color: #BF9EEE">30</span><span style="color: #F6F6F4">:</span><span style="color: #BF9EEE">19</span><span style="color: #F6F6F4"> GMT; 21s ago</span></span> <span class="line"></span> |
Step 5 – Check the version of Apache installed.
1 2 3 4 5 |
<span class="line"><span style="color: #E4F0FB">root</span><span style="color: #A6ACCD">@</span><span style="color: #E4F0FB">lnx03</span><span style="color: #A6ACCD"> </span><span style="color: #91B4D5">/</span><span style="color: #A6ACCD">]# </span><span style="color: #E4F0FB">httpd</span><span style="color: #A6ACCD"> </span><span style="color: #91B4D5">-</span><span style="color: #E4F0FB">v</span></span> <span class="line"><span style="color: #E4F0FB">Server</span><span style="color: #A6ACCD"> </span><span style="color: #91B4D5">version</span><span style="color: #A6ACCD">: </span><span style="color: #E4F0FB">Apache</span><span style="color: #91B4D5">/</span><span style="color: #5DE4C7">2.4</span><span style="color: #A6ACCD">.</span><span style="color: #5DE4C7">53</span><span style="color: #A6ACCD"> (</span><span style="color: #E4F0FB">Red</span><span style="color: #A6ACCD"> </span><span style="color: #E4F0FB">Hat</span><span style="color: #A6ACCD"> </span><span style="color: #E4F0FB">Enterprise</span><span style="color: #A6ACCD"> </span><span style="color: #E4F0FB">Linux</span><span style="color: #A6ACCD">)</span></span> <span class="line"><span style="color: #E4F0FB">Server</span><span style="color: #A6ACCD"> </span><span style="color: #91B4D5">built</span><span style="color: #A6ACCD">: </span><span style="color: #E4F0FB">Apr</span><span style="color: #A6ACCD"> </span><span style="color: #5DE4C7">28</span><span style="color: #A6ACCD"> </span><span style="color: #5DE4C7">2023</span><span style="color: #A6ACCD"> </span><span style="color: #5DE4C7">00</span><span style="color: #A6ACCD">:</span><span style="color: #5DE4C7">00</span><span style="color: #A6ACCD">:</span><span style="color: #5DE4C7">00</span></span> <span class="line"><span style="color: #A6ACCD">[</span><span style="color: #E4F0FB">root</span><span style="color: #A6ACCD">@</span><span style="color: #E4F0FB">lnx03</span><span style="color: #A6ACCD"> </span><span style="color: #91B4D5">/</span><span style="color: #A6ACCD">]# </span></span> <span class="line"></span> |
Step 6 –Verify that port 80 is open
1 2 3 4 |
<span class="line"><span style="color: #A6ACCD">[</span><span style="color: #E4F0FB">root</span><span style="color: #A6ACCD">@</span><span style="color: #E4F0FB">lnx03</span><span style="color: #A6ACCD"> </span><span style="color: #91B4D5">/</span><span style="color: #A6ACCD">]# </span><span style="color: #E4F0FB">netstat</span><span style="color: #A6ACCD"> </span><span style="color: #91B4D5">-</span><span style="color: #E4F0FB">tulpn</span><span style="color: #A6ACCD"> </span><span style="color: #91B4D5">|</span><span style="color: #A6ACCD"> </span><span style="color: #91B4D5">grep</span><span style="color: #A6ACCD"> :</span><span style="color: #5DE4C7">80</span></span> <span class="line"><span style="color: #E4F0FB">tcp6</span><span style="color: #A6ACCD"> </span><span style="color: #5DE4C7">0</span><span style="color: #A6ACCD"> </span><span style="color: #5DE4C7">0</span><span style="color: #A6ACCD"> :::</span><span style="color: #5DE4C7">80</span><span style="color: #A6ACCD"> :::</span><span style="color: #91B4D5">*</span><span style="color: #A6ACCD"> </span><span style="color: #E4F0FB">LISTEN</span><span style="color: #A6ACCD"> </span><span style="color: #5DE4C7">2318</span><span style="color: #91B4D5">/</span><span style="color: #E4F0FB">httpd</span><span style="color: #A6ACCD"> </span></span> <span class="line"><span style="color: #A6ACCD">[</span><span style="color: #E4F0FB">root</span><span style="color: #A6ACCD">@</span><span style="color: #E4F0FB">lnx03</span><span style="color: #A6ACCD"> </span><span style="color: #91B4D5">/</span><span style="color: #A6ACCD">]# </span></span> <span class="line"></span> |
Step 7 –Allow HTTP and HTTPS traffic in our firewall if enabled.
1 2 3 4 5 6 7 8 9 10 11 12 13 |
<span class="line"><span style="color: #E4F0FB">$</span><span style="color: #A6ACCD"> </span><span style="color: #E4F0FB">firewall</span><span style="color: #91B4D5">-</span><span style="color: #E4F0FB">cmd</span><span style="color: #A6ACCD"> </span><span style="color: #91B4D5">--</span><span style="color: #E4F0FB">permanent</span><span style="color: #A6ACCD"> </span><span style="color: #91B4D5">--</span><span style="color: #E4F0FB">add</span><span style="color: #91B4D5">-</span><span style="color: #E4F0FB">service</span><span style="color: #91B4D5">=</span><span style="color: #E4F0FB">http</span><span style="color: #A6ACCD"> </span><span style="color: #91B4D5">--</span><span style="color: #E4F0FB">add</span><span style="color: #91B4D5">-</span><span style="color: #E4F0FB">service</span><span style="color: #91B4D5">=</span><span style="color: #E4F0FB">https</span></span> <span class="line"><span style="color: #A6ACCD"># </span><span style="color: #E4F0FB">firewall</span><span style="color: #91B4D5">-</span><span style="color: #E4F0FB">cmd</span><span style="color: #A6ACCD"> </span><span style="color: #91B4D5">--</span><span style="color: #E4F0FB">reload</span></span> <span class="line"></span> <span class="line"><span style="color: #E4F0FB">On</span><span style="color: #A6ACCD"> </span><span style="color: #E4F0FB">the</span><span style="color: #A6ACCD"> </span><span style="color: #E4F0FB">old</span><span style="color: #A6ACCD"> </span><span style="color: #E4F0FB">RHEL</span><span style="color: #A6ACCD">, </span><span style="color: #E4F0FB">we</span><span style="color: #A6ACCD"> </span><span style="color: #E4F0FB">would</span><span style="color: #A6ACCD"> </span><span style="color: #E4F0FB">use</span><span style="color: #A6ACCD"> </span><span style="color: #E4F0FB">iptables</span><span style="color: #A6ACCD"> </span><span style="color: #E4F0FB">to</span><span style="color: #A6ACCD"> </span><span style="color: #E4F0FB">set</span><span style="color: #A6ACCD"> </span><span style="color: #E4F0FB">the</span><span style="color: #A6ACCD"> </span><span style="color: #E4F0FB">config</span><span style="color: #A6ACCD"> </span><span style="color: #A6ACCDC0">as</span><span style="color: #A6ACCD"> </span><span style="color: #A6ACCDC0">shown</span></span> <span class="line"></span> <span class="line"></span> <span class="line"><span style="color: #A6ACCD"># </span><span style="color: #E4F0FB">Allow</span><span style="color: #A6ACCD"> </span><span style="color: #E4F0FB">a</span><span style="color: #A6ACCD"> </span><span style="color: #E4F0FB">subnet</span><span style="color: #A6ACCD"> </span><span style="color: #E4F0FB">to</span><span style="color: #A6ACCD"> </span><span style="color: #E4F0FB">pass</span><span style="color: #A6ACCD"> </span><span style="color: #E4F0FB">port</span><span style="color: #A6ACCD"> </span><span style="color: #5DE4C7">80</span><span style="color: #A6ACCD"> </span></span> <span class="line"><span style="color: #A6ACCD"> </span><span style="color: #E4F0FB">iptables</span><span style="color: #91B4D5">-</span><span style="color: #E4F0FB">A</span><span style="color: #A6ACCD"> </span><span style="color: #E4F0FB">INPUT</span><span style="color: #A6ACCD"> </span><span style="color: #91B4D5">-</span><span style="color: #E4F0FB">m</span><span style="color: #A6ACCD"> </span><span style="color: #E4F0FB">state</span><span style="color: #A6ACCD"> </span><span style="color: #91B4D5">--</span><span style="color: #E4F0FB">state</span><span style="color: #A6ACCD"> </span><span style="color: #E4F0FB">NEW</span><span style="color: #A6ACCD"> </span><span style="color: #91B4D5">-</span><span style="color: #E4F0FB">m</span><span style="color: #A6ACCD"> </span><span style="color: #E4F0FB">tcp</span><span style="color: #A6ACCD"> </span><span style="color: #91B4D5">-</span><span style="color: #E4F0FB">p</span><span style="color: #A6ACCD"> </span><span style="color: #E4F0FB">tcp</span><span style="color: #A6ACCD"> </span><span style="color: #91B4D5">-</span><span style="color: #E4F0FB">s</span><span style="color: #A6ACCD"> </span><span style="color: #5DE4C7">192.168</span><span style="color: #A6ACCD">.</span><span style="color: #5DE4C7">1.0</span><span style="color: #91B4D5">/</span><span style="color: #5DE4C7">24</span><span style="color: #A6ACCD"> </span><span style="color: #91B4D5">--</span><span style="color: #E4F0FB">dport</span><span style="color: #A6ACCD"> </span><span style="color: #5DE4C7">80</span><span style="color: #A6ACCD"> </span><span style="color: #91B4D5">-</span><span style="color: #E4F0FB">j</span><span style="color: #A6ACCD"> </span><span style="color: #E4F0FB">ACCEPT</span></span> <span class="line"><span style="color: #A6ACCD"> </span><span style="color: #E4F0FB">iptables</span><span style="color: #A6ACCD"> </span><span style="color: #91B4D5">-</span><span style="color: #E4F0FB">A</span><span style="color: #A6ACCD"> </span><span style="color: #E4F0FB">INPUT</span><span style="color: #A6ACCD"> </span><span style="color: #91B4D5">-</span><span style="color: #E4F0FB">m</span><span style="color: #A6ACCD"> </span><span style="color: #E4F0FB">state</span><span style="color: #A6ACCD"> </span><span style="color: #91B4D5">--</span><span style="color: #E4F0FB">state</span><span style="color: #A6ACCD"> </span><span style="color: #E4F0FB">NEW</span><span style="color: #A6ACCD"> </span><span style="color: #91B4D5">-</span><span style="color: #E4F0FB">m</span><span style="color: #A6ACCD"> </span><span style="color: #E4F0FB">tcp</span><span style="color: #A6ACCD"> </span><span style="color: #91B4D5">-</span><span style="color: #E4F0FB">p</span><span style="color: #A6ACCD"> </span><span style="color: #E4F0FB">tcp</span><span style="color: #A6ACCD"> </span><span style="color: #91B4D5">--</span><span style="color: #E4F0FB">dport</span><span style="color: #A6ACCD"> </span><span style="color: #5DE4C7">80</span><span style="color: #A6ACCD"> </span><span style="color: #91B4D5">-</span><span style="color: #E4F0FB">j</span><span style="color: #A6ACCD"> </span><span style="color: #E4F0FB">ACCEPT</span></span> <span class="line"><span style="color: #A6ACCD"> </span><span style="color: #E4F0FB">iptables</span><span style="color: #A6ACCD"> </span><span style="color: #91B4D5">-</span><span style="color: #E4F0FB">A</span><span style="color: #A6ACCD"> </span><span style="color: #E4F0FB">INPUT</span><span style="color: #A6ACCD"> </span><span style="color: #91B4D5">-</span><span style="color: #E4F0FB">m</span><span style="color: #A6ACCD"> </span><span style="color: #E4F0FB">state</span><span style="color: #A6ACCD"> </span><span style="color: #91B4D5">--</span><span style="color: #E4F0FB">state</span><span style="color: #A6ACCD"> </span><span style="color: #E4F0FB">NEW</span><span style="color: #A6ACCD"> </span><span style="color: #91B4D5">-</span><span style="color: #E4F0FB">m</span><span style="color: #A6ACCD"> </span><span style="color: #E4F0FB">tcp</span><span style="color: #A6ACCD"> </span><span style="color: #91B4D5">-</span><span style="color: #E4F0FB">p</span><span style="color: #A6ACCD"> </span><span style="color: #E4F0FB">tcp</span><span style="color: #A6ACCD"> </span><span style="color: #91B4D5">--</span><span style="color: #E4F0FB">dport</span><span style="color: #A6ACCD"> </span><span style="color: #5DE4C7">443</span><span style="color: #A6ACCD"> </span><span style="color: #91B4D5">-</span><span style="color: #E4F0FB">j</span><span style="color: #A6ACCD"> </span><span style="color: #E4F0FB">ACCEPT</span></span> <span class="line"><span style="color: #A6ACCD"> </span><span style="color: #E4F0FB">service</span><span style="color: #A6ACCD"> </span><span style="color: #E4F0FB">iptables</span><span style="color: #A6ACCD"> </span><span style="color: #E4F0FB">save</span></span> <span class="line"><span style="color: #A6ACCD"> </span><span style="color: #E4F0FB">service</span><span style="color: #A6ACCD"> </span><span style="color: #E4F0FB">iptables</span><span style="color: #A6ACCD"> </span><span style="color: #E4F0FB">restart</span></span> <span class="line"></span> |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
<span class="line"><span style="color: #ADBAC7">[root@lnx03 </span><span style="color: #F47067">/</span><span style="color: #ADBAC7">]# </span></span> <span class="line"><span style="color: #ADBAC7">[root@lnx03 </span><span style="color: #F47067">/</span><span style="color: #ADBAC7">]# systemctl status firewalld</span></span> <span class="line"><span style="color: #ADBAC7">○ firewalld.service </span><span style="color: #F47067">-</span><span style="color: #ADBAC7"> firewalld </span><span style="color: #F47067">-</span><span style="color: #ADBAC7"> dynamic firewall daemon</span></span> <span class="line"><span style="color: #ADBAC7"> </span><span style="color: #F69D50">Loaded</span><span style="color: #ADBAC7">: </span><span style="color: #DCBDFB">loaded</span><span style="color: #ADBAC7"> (</span><span style="color: #F47067">/</span><span style="color: #ADBAC7">usr</span><span style="color: #F47067">/</span><span style="color: #ADBAC7">lib</span><span style="color: #F47067">/</span><span style="color: #ADBAC7">systemd</span><span style="color: #F47067">/</span><span style="color: #ADBAC7">system</span><span style="color: #F47067">/</span><span style="color: #ADBAC7">firewalld.service; disabled; preset: enabled)</span></span> <span class="line"><span style="color: #ADBAC7"> </span><span style="color: #F69D50">Active</span><span style="color: #ADBAC7">: </span><span style="color: #DCBDFB">inactive</span><span style="color: #ADBAC7"> (dead)</span></span> <span class="line"><span style="color: #ADBAC7"> </span><span style="color: #F69D50">Docs</span><span style="color: #ADBAC7">: </span><span style="color: #F69D50">man</span><span style="color: #ADBAC7">:</span><span style="color: #DCBDFB">firewalld</span><span style="color: #ADBAC7">(</span><span style="color: #6CB6FF">1</span><span style="color: #ADBAC7">)</span></span> <span class="line"><span style="color: #ADBAC7">[root@lnx03 </span><span style="color: #F47067">/</span><span style="color: #ADBAC7">]# </span></span> <span class="line"><span style="color: #ADBAC7">[root@lnx03 </span><span style="color: #F47067">/</span><span style="color: #ADBAC7">]# systemctl start firewalld</span></span> <span class="line"><span style="color: #ADBAC7">[root@lnx03 </span><span style="color: #F47067">/</span><span style="color: #ADBAC7">]# systemctl status firewalld</span></span> <span class="line"><span style="color: #ADBAC7">● firewalld.service </span><span style="color: #F47067">-</span><span style="color: #ADBAC7"> firewalld </span><span style="color: #F47067">-</span><span style="color: #ADBAC7"> dynamic firewall daemon</span></span> <span class="line"><span style="color: #ADBAC7"> </span><span style="color: #F69D50">Loaded</span><span style="color: #ADBAC7">: </span><span style="color: #DCBDFB">loaded</span><span style="color: #ADBAC7"> (</span><span style="color: #F47067">/</span><span style="color: #ADBAC7">usr</span><span style="color: #F47067">/</span><span style="color: #ADBAC7">lib</span><span style="color: #F47067">/</span><span style="color: #ADBAC7">systemd</span><span style="color: #F47067">/</span><span style="color: #ADBAC7">system</span><span style="color: #F47067">/</span><span style="color: #ADBAC7">firewalld.service; disabled; preset: enabled)</span></span> <span class="line"><span style="color: #ADBAC7"> </span><span style="color: #F69D50">Active</span><span style="color: #ADBAC7">: </span><span style="color: #DCBDFB">active</span><span style="color: #ADBAC7"> (running) since Mon </span><span style="color: #6CB6FF">2023</span><span style="color: #F47067">-</span><span style="color: #6CB6FF">10</span><span style="color: #F47067">-</span><span style="color: #6CB6FF">30</span><span style="color: #ADBAC7"> </span><span style="color: #6CB6FF">06</span><span style="color: #ADBAC7">:</span><span style="color: #6CB6FF">33</span><span style="color: #ADBAC7">:</span><span style="color: #6CB6FF">03</span><span style="color: #ADBAC7"> </span><span style="color: #6CB6FF">GMT</span><span style="color: #ADBAC7">; 1s ago</span></span> <span class="line"><span style="color: #ADBAC7"> </span><span style="color: #F69D50">Docs</span><span style="color: #ADBAC7">: </span><span style="color: #F69D50">man</span><span style="color: #ADBAC7">:</span><span style="color: #DCBDFB">firewalld</span><span style="color: #ADBAC7">(</span><span style="color: #6CB6FF">1</span><span style="color: #ADBAC7">)</span></span> <span class="line"><span style="color: #ADBAC7"> Main </span><span style="color: #F69D50">PID</span><span style="color: #ADBAC7">: </span><span style="color: #6CB6FF">2546</span><span style="color: #ADBAC7"> (firewalld)</span></span> <span class="line"><span style="color: #ADBAC7"> </span><span style="color: #F69D50">Tasks</span><span style="color: #ADBAC7">: </span><span style="color: #6CB6FF">2</span><span style="color: #ADBAC7"> (</span><span style="color: #F69D50">limit</span><span style="color: #F47067">:</span><span style="color: #ADBAC7"> </span><span style="color: #6CB6FF">10930</span><span style="color: #ADBAC7">)</span></span> <span class="line"><span style="color: #ADBAC7"> Memory: 27.0M</span></span> <span class="line"><span style="color: #ADBAC7"> CPU: 847ms</span></span> <span class="line"><span style="color: #ADBAC7"> CGroup: /system.slice/firewalld.service</span></span> <span class="line"><span style="color: #ADBAC7"> └─2546 /usr/bin/python3 -s /usr/sbin/firewalld --nofork --nopid</span></span> <span class="line"></span> <span class="line"><span style="color: #ADBAC7">Oct 30 06:33:03 lnx03 systemd[1]: Starting firewalld - dynamic firewall daemon...</span></span> <span class="line"><span style="color: #ADBAC7">Oct 30 06:33:03 lnx03 systemd[1]: Started firewalld - dynamic firewall daemon.</span></span> <span class="line"><span style="color: #ADBAC7">[root@lnx03 /]# </span></span> <span class="line"></span> <span class="line"><span style="color: #ADBAC7">[root@lnx03 /]# firewall-cmd --permanent --add-service=http --add-service=https</span></span> <span class="line"><span style="color: #ADBAC7">success</span></span> <span class="line"><span style="color: #ADBAC7">[root@lnx03 /]# firewall-cmd --reload</span></span> <span class="line"><span style="color: #ADBAC7">success</span></span> <span class="line"></span> <span class="line"></span> <span class="line"><span style="color: #ADBAC7">[root@lnx03 /]# firewall-cmd --list-all</span></span> <span class="line"><span style="color: #ADBAC7">public (</span><span style="color: #F69D50">active</span><span style="color: #ADBAC7">)</span></span> <span class="line"><span style="color: #ADBAC7"> target: default</span></span> <span class="line"><span style="color: #ADBAC7"> icmp-block-inversion: no</span></span> <span class="line"><span style="color: #ADBAC7"> interfaces: ens160</span></span> <span class="line"><span style="color: #ADBAC7"> sources: </span></span> <span class="line"><span style="color: #ADBAC7"> services: cockpit dhcpv6-client http https ssh</span></span> <span class="line"><span style="color: #ADBAC7"> ports: </span></span> <span class="line"><span style="color: #ADBAC7"> protocols: </span></span> <span class="line"><span style="color: #ADBAC7"> forward: yes</span></span> <span class="line"><span style="color: #ADBAC7"> masquerade: no</span></span> <span class="line"><span style="color: #ADBAC7"> forward-ports: </span></span> <span class="line"><span style="color: #ADBAC7"> source-ports: </span></span> <span class="line"><span style="color: #ADBAC7"> icmp-blocks: </span></span> <span class="line"><span style="color: #ADBAC7"> rich rules: </span></span> <span class="line"><span style="color: #ADBAC7">[root@lnx03 /]# </span></span> <span class="line"></span> <span class="line"></span> |
Step 8 – Create web content under /var/www/html folder for RHEL.
1 2 3 |
<span class="line"><span style="color: #A6ACCD">[</span><span style="color: #E4F0FB">root</span><span style="color: #A6ACCD">@</span><span style="color: #E4F0FB">lnx03</span><span style="color: #A6ACCD"> </span><span style="color: #91B4D5">/</span><span style="color: #A6ACCD">]# </span><span style="color: #E4F0FB">echo</span><span style="color: #A6ACCD"> </span><span style="color: #E4F0FB">This</span><span style="color: #A6ACCD"> </span><span style="color: #E4F0FB">is</span><span style="color: #A6ACCD"> </span><span style="color: #E4F0FB">my</span><span style="color: #A6ACCD"> </span><span style="color: #E4F0FB">webserver</span><span style="color: #A6ACCD"> </span><span style="color: #E4F0FB">$HOSTNAME</span><span style="color: #A6ACCD"> </span><span style="color: #91B4D5">></span><span style="color: #A6ACCD"> </span><span style="color: #91B4D5">/var</span><span style="color: #A6ACCD">/</span><span style="color: #E4F0FB">www</span><span style="color: #A6ACCD">/html/index.html</span></span> <span class="line"><span style="color: #A6ACCD">[</span><span style="color: #E4F0FB">root</span><span style="color: #A6ACCD">@</span><span style="color: #E4F0FB">lnx03</span><span style="color: #A6ACCD"> </span><span style="color: #91B4D5">/</span><span style="color: #A6ACCD">]# </span><span style="color: #E4F0FB">cat</span><span style="color: #A6ACCD"> </span><span style="color: #91B4D5">/var</span><span style="color: #A6ACCD">/</span><span style="color: #E4F0FB">www</span><span style="color: #A6ACCD">/html/index.html </span></span> <span class="line"><span style="color: #E4F0FB">This</span><span style="color: #A6ACCD"> </span><span style="color: #E4F0FB">is</span><span style="color: #A6ACCD"> </span><span style="color: #E4F0FB">my</span><span style="color: #A6ACCD"> </span><span style="color: #E4F0FB">webserver</span><span style="color: #A6ACCD"> </span><span style="color: #E4F0FB">lnx03</span></span> |
Step 9 – Test the config file
1 2 |
<span class="line"><span style="color: #A6ACCD">[</span><span style="color: #E4F0FB">root</span><span style="color: #A6ACCD">@</span><span style="color: #E4F0FB">lnx03</span><span style="color: #A6ACCD"> </span><span style="color: #E4F0FB">conf</span><span style="color: #A6ACCD">]# </span><span style="color: #E4F0FB">apachectl</span><span style="color: #A6ACCD"> </span><span style="color: #E4F0FB">configtest</span></span> <span class="line"><span style="color: #E4F0FB">Syntax</span><span style="color: #A6ACCD"> </span><span style="color: #E4F0FB">OK</span></span> |
Step 10 – Verify the webpage
1 2 3 4 5 |
<span class="line"><span style="color: #A6ACCD">[</span><span style="color: #E4F0FB">root</span><span style="color: #A6ACCD">@</span><span style="color: #E4F0FB">lnx03</span><span style="color: #A6ACCD"> </span><span style="color: #E4F0FB">conf</span><span style="color: #A6ACCD">]# </span><span style="color: #E4F0FB">curl</span><span style="color: #A6ACCD"> </span><span style="color: #5DE4C7">127.0</span><span style="color: #A6ACCD">.</span><span style="color: #5DE4C7">0.1</span></span> <span class="line"><span style="color: #E4F0FB">This</span><span style="color: #A6ACCD"> </span><span style="color: #E4F0FB">is</span><span style="color: #A6ACCD"> </span><span style="color: #E4F0FB">my</span><span style="color: #A6ACCD"> </span><span style="color: #E4F0FB">webserver</span><span style="color: #A6ACCD"> </span><span style="color: #E4F0FB">lnx03</span></span> <span class="line"><span style="color: #A6ACCD">[</span><span style="color: #E4F0FB">root</span><span style="color: #A6ACCD">@</span><span style="color: #E4F0FB">lnx03</span><span style="color: #A6ACCD"> </span><span style="color: #E4F0FB">conf</span><span style="color: #A6ACCD">]# </span><span style="color: #E4F0FB">curl</span><span style="color: #A6ACCD"> </span><span style="color: #E4F0FB">lnx03</span><span style="color: #A6ACCD">.</span><span style="color: #E4F0FB">ash</span><span style="color: #A6ACCD">.</span><span style="color: #E4F0FB">local</span></span> <span class="line"><span style="color: #E4F0FB">This</span><span style="color: #A6ACCD"> </span><span style="color: #E4F0FB">is</span><span style="color: #A6ACCD"> </span><span style="color: #E4F0FB">my</span><span style="color: #A6ACCD"> </span><span style="color: #E4F0FB">webserver</span><span style="color: #A6ACCD"> </span><span style="color: #E4F0FB">lnx03</span></span> <span class="line"><span style="color: #A6ACCD">[</span><span style="color: #E4F0FB">root</span><span style="color: #A6ACCD">@</span><span style="color: #E4F0FB">lnx03</span><span style="color: #A6ACCD"> </span><span style="color: #E4F0FB">conf</span><span style="color: #A6ACCD">]# </span></span> |
Apache Virtual Host Configuration to run multiple websites – Shared Website Hosting.
Most of the WordPress sites we use run with the virtual host configuration. The objective of a virtual host entry in Apache config is to handle multiple websites from a single IP address on our Apache VM so that a single massive VM can serve a ton of websites from it which is the principle of Shared Website Hoisting.
We will aim to set up our two hotel websites running from a single web server as shown below – www.east.ash.local and www.west.ash.local from our single server which has a single IP address of 192.168.0.17, so we must have DNS names resolving to this machine IP address or make an entry in /etc/hosts file. Each hotel branch will have its own URL as shown.
Set up the host file
1 2 3 4 5 |
<span class="line"><span style="color: #E4F0FB">root</span><span style="color: #A6ACCD">@</span><span style="color: #E4F0FB">lnx03</span><span style="color: #A6ACCD"> </span><span style="color: #91B4D5">~</span><span style="color: #A6ACCD">]# </span><span style="color: #E4F0FB">cat</span><span style="color: #A6ACCD"> </span><span style="color: #91B4D5">/</span><span style="color: #E4F0FB">etc</span><span style="color: #91B4D5">/</span><span style="color: #E4F0FB">hosts</span><span style="color: #A6ACCD"> </span></span> <span class="line"><span style="color: #5DE4C7">127.0</span><span style="color: #A6ACCD">.</span><span style="color: #5DE4C7">0.1</span><span style="color: #A6ACCD"> </span><span style="color: #E4F0FB">localhost</span><span style="color: #A6ACCD"> </span><span style="color: #E4F0FB">localhost</span><span style="color: #A6ACCD">.</span><span style="color: #E4F0FB">localdomain</span><span style="color: #A6ACCD"> </span><span style="color: #E4F0FB">localhost4</span><span style="color: #A6ACCD"> </span><span style="color: #E4F0FB">localhost4</span><span style="color: #A6ACCD">.</span><span style="color: #E4F0FB">localdomain4</span></span> <span class="line"><span style="color: #A6ACCD">::</span><span style="color: #5DE4C7">1</span><span style="color: #A6ACCD"> </span><span style="color: #E4F0FB">localhost</span><span style="color: #A6ACCD"> </span><span style="color: #E4F0FB">localhost</span><span style="color: #A6ACCD">.</span><span style="color: #E4F0FB">localdomain</span><span style="color: #A6ACCD"> </span><span style="color: #E4F0FB">localhost6</span><span style="color: #A6ACCD"> </span><span style="color: #E4F0FB">localhost6</span><span style="color: #A6ACCD">.</span><span style="color: #E4F0FB">localdomain6</span></span> <span class="line"><span style="color: #5DE4C7">127.0</span><span style="color: #A6ACCD">.</span><span style="color: #5DE4C7">0.1</span><span style="color: #A6ACCD"> </span><span style="color: #E4F0FB">east</span><span style="color: #A6ACCD"> </span><span style="color: #E4F0FB">east</span><span style="color: #A6ACCD">.</span><span style="color: #E4F0FB">lnx03</span><span style="color: #A6ACCD">.</span><span style="color: #E4F0FB">ash</span><span style="color: #A6ACCD">.</span><span style="color: #E4F0FB">local</span></span> <span class="line"><span style="color: #5DE4C7">127.0</span><span style="color: #A6ACCD">.</span><span style="color: #5DE4C7">0.1</span><span style="color: #A6ACCD"> </span><span style="color: #E4F0FB">west</span><span style="color: #A6ACCD"> </span><span style="color: #E4F0FB">west</span><span style="color: #A6ACCD">.</span><span style="color: #E4F0FB">lnx03</span><span style="color: #A6ACCD">.</span><span style="color: #E4F0FB">ash</span><span style="color: #A6ACCD">.</span><span style="color: #E4F0FB">local</span></span> |
For multiple websites, to be hoisted, create a dedicated directory for each website file and keep all the website content on those directories respectively as shown below. In this example, my east and west website files are kept separately.
1 2 3 4 5 6 7 8 9 |
<span class="line"><span style="color: #A6ACCD">[</span><span style="color: #E4F0FB">root</span><span style="color: #A6ACCD">@</span><span style="color: #E4F0FB">lnx03</span><span style="color: #A6ACCD"> </span><span style="color: #E4F0FB">conf</span><span style="color: #A6ACCD">]# </span><span style="color: #E4F0FB">mkdir</span><span style="color: #A6ACCD"> </span><span style="color: #91B4D5">-</span><span style="color: #E4F0FB">p</span><span style="color: #A6ACCD"> </span><span style="color: #91B4D5">/var</span><span style="color: #A6ACCD">/</span><span style="color: #E4F0FB">www</span><span style="color: #A6ACCD">/html/east</span></span> <span class="line"><span style="color: #A6ACCD">[</span><span style="color: #E4F0FB">root</span><span style="color: #A6ACCD">@</span><span style="color: #E4F0FB">lnx03</span><span style="color: #A6ACCD"> </span><span style="color: #E4F0FB">conf</span><span style="color: #A6ACCD">]# </span><span style="color: #E4F0FB">mkdir</span><span style="color: #A6ACCD"> </span><span style="color: #91B4D5">-</span><span style="color: #E4F0FB">p</span><span style="color: #A6ACCD"> </span><span style="color: #91B4D5">/var</span><span style="color: #A6ACCD">/</span><span style="color: #E4F0FB">www</span><span style="color: #A6ACCD">/html/west</span></span> <span class="line"><span style="color: #A6ACCD">[</span><span style="color: #E4F0FB">root</span><span style="color: #A6ACCD">@</span><span style="color: #E4F0FB">lnx03</span><span style="color: #A6ACCD"> </span><span style="color: #E4F0FB">conf</span><span style="color: #A6ACCD">]# </span><span style="color: #E4F0FB">echo</span><span style="color: #A6ACCD"> </span><span style="color: #E4F0FB">This</span><span style="color: #A6ACCD"> </span><span style="color: #E4F0FB">is</span><span style="color: #A6ACCD"> </span><span style="color: #E4F0FB">my</span><span style="color: #A6ACCD"> </span><span style="color: #E4F0FB">east</span><span style="color: #A6ACCD"> </span><span style="color: #E4F0FB">webserver</span><span style="color: #A6ACCD"> </span><span style="color: #E4F0FB">$HOSTNAME</span><span style="color: #A6ACCD"> </span><span style="color: #91B4D5">></span><span style="color: #A6ACCD"> </span><span style="color: #91B4D5">/var</span><span style="color: #A6ACCD">/</span><span style="color: #E4F0FB">www</span><span style="color: #A6ACCD">/html/east/index.html</span></span> <span class="line"><span style="color: #A6ACCD">[</span><span style="color: #E4F0FB">root</span><span style="color: #A6ACCD">@</span><span style="color: #E4F0FB">lnx03</span><span style="color: #A6ACCD"> </span><span style="color: #E4F0FB">conf</span><span style="color: #A6ACCD">]# </span><span style="color: #E4F0FB">echo</span><span style="color: #A6ACCD"> </span><span style="color: #E4F0FB">This</span><span style="color: #A6ACCD"> </span><span style="color: #E4F0FB">is</span><span style="color: #A6ACCD"> </span><span style="color: #E4F0FB">my</span><span style="color: #A6ACCD"> </span><span style="color: #E4F0FB">west</span><span style="color: #A6ACCD"> </span><span style="color: #E4F0FB">webserver</span><span style="color: #A6ACCD"> </span><span style="color: #E4F0FB">$HOSTNAME</span><span style="color: #A6ACCD"> </span><span style="color: #91B4D5">></span><span style="color: #A6ACCD"> </span><span style="color: #91B4D5">/var</span><span style="color: #A6ACCD">/</span><span style="color: #E4F0FB">www</span><span style="color: #A6ACCD">/html/west/index.html</span></span> <span class="line"><span style="color: #A6ACCD">[</span><span style="color: #E4F0FB">root</span><span style="color: #A6ACCD">@</span><span style="color: #E4F0FB">lnx03</span><span style="color: #A6ACCD"> </span><span style="color: #E4F0FB">conf</span><span style="color: #A6ACCD">]# </span><span style="color: #E4F0FB">mkdir</span><span style="color: #A6ACCD"> </span><span style="color: #91B4D5">-</span><span style="color: #E4F0FB">p</span><span style="color: #A6ACCD"> </span><span style="color: #91B4D5">/var</span><span style="color: #A6ACCD">/</span><span style="color: #E4F0FB">log</span><span style="color: #A6ACCD">/httpd/west/</span></span> <span class="line"><span style="color: #A6ACCD">[</span><span style="color: #E4F0FB">root</span><span style="color: #A6ACCD">@</span><span style="color: #E4F0FB">lnx03</span><span style="color: #A6ACCD"> </span><span style="color: #E4F0FB">conf</span><span style="color: #A6ACCD">]# </span><span style="color: #E4F0FB">mkdir</span><span style="color: #A6ACCD"> </span><span style="color: #91B4D5">-</span><span style="color: #E4F0FB">p</span><span style="color: #A6ACCD"> </span><span style="color: #91B4D5">/var</span><span style="color: #A6ACCD">/</span><span style="color: #E4F0FB">log</span><span style="color: #A6ACCD">/httpd/east</span></span> <span class="line"><span style="color: #A6ACCD">[</span><span style="color: #E4F0FB">root</span><span style="color: #A6ACCD">@</span><span style="color: #E4F0FB">lnx03</span><span style="color: #A6ACCD"> </span><span style="color: #E4F0FB">conf</span><span style="color: #A6ACCD">]# </span><span style="color: #E4F0FB">touch</span><span style="color: #A6ACCD"> </span><span style="color: #91B4D5">/var</span><span style="color: #A6ACCD">/</span><span style="color: #E4F0FB">log</span><span style="color: #A6ACCD">/httpd/west/error_log</span></span> <span class="line"><span style="color: #A6ACCD">[</span><span style="color: #E4F0FB">root</span><span style="color: #A6ACCD">@</span><span style="color: #E4F0FB">lnx03</span><span style="color: #A6ACCD"> </span><span style="color: #E4F0FB">conf</span><span style="color: #A6ACCD">]# </span><span style="color: #E4F0FB">touch</span><span style="color: #A6ACCD"> </span><span style="color: #91B4D5">/var</span><span style="color: #A6ACCD">/</span><span style="color: #E4F0FB">log</span><span style="color: #A6ACCD">/httpd/east/error_log</span></span> <span class="line"></span> |
Open the main configuration file /etc/httpd/conf/httpd.conf and make the below changes at the end of the file.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
<span class="line"></span> <span class="line"><span style="color: #E4F0FB"><</span><span style="color: #5DE4C7">VirtualHost</span><span style="color: #E4F0FB"> </span><span style="color: #D0679D">*:80></span></span> <span class="line"><span style="color: #E4F0FB"> </span><span style="color: #91B4D5; font-style: italic">ServerAdmin</span><span style="color: #E4F0FB"> </span><span style="color: #D0679D">admin@ash.local</span></span> <span class="line"><span style="color: #E4F0FB"> </span><span style="color: #91B4D5; font-style: italic">ServerName</span><span style="color: #E4F0FB"> </span><span style="color: #D0679D">east.ash.local</span></span> <span class="line"><span style="color: #E4F0FB"> </span><span style="color: #91B4D5; font-style: italic">DocumentRoot</span><span style="color: #E4F0FB"> </span><span style="color: #D0679D">/var/www/html/east</span></span> <span class="line"><span style="color: #E4F0FB"> </span><span style="color: #91B4D5; font-style: italic">ErrorLog</span><span style="color: #E4F0FB"> </span><span style="color: #D0679D">/var/log/httpd/east/error_log</span><span style="color: #E4F0FB"> </span></span> <span class="line"><span style="color: #E4F0FB"> </span><span style="color: #91B4D5; font-style: italic">TransferLog</span><span style="color: #E4F0FB"> </span><span style="color: #D0679D">/var/log/httpd/east/access_log</span><span style="color: #E4F0FB"> </span></span> <span class="line"><span style="color: #D0679D"></VirtualHost></span></span> <span class="line"></span> <span class="line"><span style="color: #D0679D"><VirtualHost</span><span style="color: #E4F0FB"> </span><span style="color: #D0679D">*:80></span></span> <span class="line"><span style="color: #E4F0FB"> </span><span style="color: #91B4D5; font-style: italic">ServerAdmin</span><span style="color: #E4F0FB"> </span><span style="color: #D0679D">admin@ash.local</span></span> <span class="line"><span style="color: #E4F0FB"> </span><span style="color: #91B4D5; font-style: italic">ServerName</span><span style="color: #E4F0FB"> </span><span style="color: #D0679D">west.ash.local</span></span> <span class="line"><span style="color: #E4F0FB"> </span><span style="color: #91B4D5; font-style: italic">DocumentRoot</span><span style="color: #E4F0FB"> </span><span style="color: #D0679D">/var/www/html/west</span></span> <span class="line"><span style="color: #E4F0FB"> </span><span style="color: #91B4D5; font-style: italic">ErrorLog</span><span style="color: #E4F0FB"> </span><span style="color: #D0679D">/var/log/httpd/west/error_log</span><span style="color: #E4F0FB"> </span></span> <span class="line"><span style="color: #E4F0FB"> </span><span style="color: #91B4D5; font-style: italic">TransferLog</span><span style="color: #E4F0FB"> </span><span style="color: #D0679D">/var/log/httpd/west/access_log</span><span style="color: #E4F0FB"> </span></span> <span class="line"><span style="color: #D0679D"></VirtualHost></span></span> <span class="line"></span> |
Test the config file
12 <span class="line"><span style="color: #A6ACCD">[</span><span style="color: #E4F0FB">root</span><span style="color: #A6ACCD">@</span><span style="color: #E4F0FB">lnx03</span><span style="color: #A6ACCD"> </span><span style="color: #E4F0FB">conf</span><span style="color: #A6ACCD">]# </span><span style="color: #E4F0FB">apachectl</span><span style="color: #A6ACCD"> </span><span style="color: #E4F0FB">configtest</span></span><span class="line"><span style="color: #E4F0FB">Syntax</span><span style="color: #A6ACCD"> </span><span style="color: #E4F0FB">OK</span></span>Test the east and west website page
123456 <span class="line"><span style="color: #ADBAC7">[root@lnx03 </span><span style="color: #F47067">~</span><span style="color: #ADBAC7">]# curl east.lnx03.ash.local</span></span><span class="line"><span style="color: #ADBAC7">This is my east webserver lnx03</span></span><span class="line"><span style="color: #ADBAC7">[root@lnx03 </span><span style="color: #F47067">~</span><span style="color: #ADBAC7">]# </span></span><span class="line"><span style="color: #ADBAC7">[root@lnx03 </span><span style="color: #F47067">~</span><span style="color: #ADBAC7">]# curl west.lnx03.ash.local</span></span><span class="line"><span style="color: #ADBAC7">This is my west webserver lnx03</span></span><span class="line"><span style="color: #ADBAC7">[root@lnx03 </span><span style="color: #F47067">~</span><span style="color: #ADBAC7">]# </span></span>
Grep command example to strip out data and see what are all the uncommented lines in our config file.
1 2 3 |
<span class="line"><span style="color: #ADBAC7">egrep </span><span style="color: #F47067">-</span><span style="color: #ADBAC7">v </span><span style="color: #96D0FF">"^#|^$"</span><span style="color: #ADBAC7"> </span><span style="color: #F47067">/</span><span style="color: #ADBAC7">etc</span><span style="color: #F47067">/</span><span style="color: #ADBAC7">httpd</span><span style="color: #F47067">/</span><span style="color: #ADBAC7">conf</span><span style="color: #F47067">/</span><span style="color: #ADBAC7">httpd.conf </span><span style="color: #F47067">|</span><span style="color: #ADBAC7"> less</span></span> <span class="line"><span style="color: #ADBAC7">or</span></span> <span class="line"><span style="color: #ADBAC7">grep </span><span style="color: #F47067">-</span><span style="color: #ADBAC7">v </span><span style="color: #96D0FF">"^#"</span><span style="color: #ADBAC7"> </span><span style="color: #F47067">/</span><span style="color: #ADBAC7">etc</span><span style="color: #F47067">/</span><span style="color: #ADBAC7">httpd</span><span style="color: #F47067">/</span><span style="color: #ADBAC7">conf</span><span style="color: #F47067">/</span><span style="color: #ADBAC7">httpd.conf </span><span style="color: #F47067">|</span><span style="color: #ADBAC7"> less</span></span> |