CentOS 7 Server Part 3 Page 1
- Edward Kimmel
January 26, 2020
Host Multiple Web Sites
The main reason I created this tutorial is the fact that I have registered web domains and decided to cancel the VPS server I was paying for which hosted these domains. I was hoping to build up a hosting company which hosted web sites for other people. This dream soon became the reality that I was paying for a server that only hosted my web domains. The company was increasing the monthly fee again which pushed me to decision to drop the service.
I was already paying for a very dependable and powerful hosting package provided by Ionos.com (formally 1and1.com), I could of moved these domains into my Ionos.com hosting package. I decided instead to see if I could use my own fiber broadband Internet service to host my domains on my own web server. My domains are mostly sentimental to me, there again I was hoping someone would offer to purchase them from me, another dream that hasn't come true.
So now these domains have become a part of my new self-teaching project and are hosted on my CentOS 7 server. These domains are LaurelHosting.com (this web site). A-TDS.com which stood for Alarms, Telecommunications & Data Systems, a company I thought about founding. MyAlarm.Systems and MyAlarmSystem.net which are for my own personal home automation project I've used to teach me interactive scripting. ThePoorSportsman.com, OnDemand.productions and AllStar.hosting I was hoping to resale as I felt those names were worth owning.
Future tutorials I create will be about detecting hacking and administrating the server I have built. Just wanted to give you a little background about the domain names that appear in this tutorial and why I am using them. Let's get the CentOS 7 server configured to host multiple web sites and be able to use PHP, Perl, Python and Ruby scripting.
Configure Apache Web Server
Now that we have the software packages installed on the CentOS server, it's now time to start to configure these software packages. This part of the tutorial is where you will learn how to set up and configure your server into a fully operational hosting server to host multiple web sites. This will be done without the assistance of any type of control panel, there will be many steps to obtain the end result. By doing it this way we are able to maintain that SELinux security is fully operational which results in a more secure hosting server for your web sites.
Create Virtual Host Directories
The Apache web server by default will host one web domain. I have 7 web domains I need to host on my server so I need to establish "Virtual Hosts". We will need to create 7 directories for each of the domains you'll be hosting. Keep the format similar to this:
/var/www/html/domain1/html /var/www/html/domain1/cgi-bin /var/www/html/domain1/html/errors /var/log/httpd/domain1 /var/www/html/domain2/html /var/www/html/domain2/cgi-bin /var/www/html/domain2/html/errors /var/log/httpd/domain2 /var/www/html/domain3/html /var/www/html/domain3/cgi-bin /var/www/html/domain3/html/errors /var/log/httpd/domain3 etc...
Let's create our directories for laurelhosting.com:
mkdir -p /var/www/html/domain1/html mkdir -p /var/www/html/domain1/cgi-bin mkdir -p /var/www/html/domain1/html/errors mkdir -p /var/log/httpd/domain1
Let's create our directories for a-tds.com:
mkdir -p /var/www/html/domain2/html mkdir -p /var/www/html/domain2/cgi-bin mkdir -p /var/www/html/domain2/html/errors mkdir -p /var/log/httpd/domain2
Let's create our directories for myalarm.systems:
mkdir -p /var/www/html/domain3/html mkdir -p /var/www/html/domain3/cgi-bin mkdir -p /var/www/html/domain3/html/errors mkdir -p /var/log/httpd/domain3
Let's create our directories for myalarmsystem.net:
mkdir -p /var/www/html/domain4/html mkdir -p /var/www/html/domain4/cgi-bin mkdir -p /var/www/html/domain4/html/errors mkdir -p /var/log/httpd/domain4
Let's create our directories for ondemand.productions:
mkdir -p /var/www/html/domain5/html mkdir -p /var/www/html/domain5/cgi-bin mkdir -p /var/www/html/domain5/html/errors mkdir -p /var/log/httpd/domain5
Let's create our directories for thepoorsportsman.com:
mkdir -p /var/www/html/domain6/html mkdir -p /var/www/html/domain6/cgi-bin mkdir -p /var/www/html/domain6/html/errors mkdir -p /var/log/httpd/domain6
Let's create our directories for allstar.hosting:
mkdir -p /var/www/html/domain7/html mkdir -p /var/www/html/domain7/cgi-bin mkdir -p /var/www/html/domain7/html/errors mkdir -p /var/log/httpd/domain7
Log files will be stored in var/log/httpd/... subfolders, which is the default place to store log files in Linux. People often store Apache log files in /var/www/ subfolders, but in CentOS with SELinux enabled this can cause access denied errors. This can be fixed with chcon command, but I prefer to store all my log files in /var/logs...
We should modify our our permissions a little bit to ensure that read access is permitted to the general web directory, and all of the files and folders inside, so that pages can be served corectly:
chmod -R 755 /var/www
Your web server should now have the permissions it needs to server content.