H. R. LEPROFESSEUR  SUBJECTS  SHOP

 SUBJECTS } LINUX } Host multiple websites on VPS without cpanel

Sept 6, 2023.

Webhosting software cpanel has become too costly, every year they increase license cost, not very good for consumers. I was looking for alternatives, and came to conclusion that I can host emails with other server (email configuration is complex specially with spam protection, postfix, dovecot, multiple software handling), and host websites on other bare-metal virtual private server. This will lower down cost with better configuration hardware. The simple steps below may be helpful if you are looking to find alternatives of cpanel on vps. I am using centos 7, if you are using debian or other linux distributions, you may search for equivalent commands for that distributions.

1: Good to have OS updated, try: sudo yum update

2: Install firewall, try: sudo yum install firewalld

3: Install httpd, try: sudo yum install httpd

4: Start apache, try: sudo systemctl start httpd

5: Check whether httpd running and active, try: sudo systemctl status httpd

Now fun part begins, on centos it reads websites data from /var/www/ directory. It is good idea to keep websites data under /home/ folder and link it to /var/www/ folder. Let's say we want to have two websites: abc.com and xyz.com hosted on vps. I am going to use abc and xyz in following code examples, you may like to change these to your websites names.

6: Create users, I recommend user name to be same as website name, try: sudo useradd -m abc /sbin/nologin ; sudo useradd -m xyz /sbin/nologin

7: Create website folders under /home/ directory, try: sudo mkdir /home/abc ; sudo mkdir /home/xyz

8: Create html folders, try: sudo mkdir /home/abc/html ; sudo mkdir /home/xyz/html

9: Create log folders, try: sudo mkdir /home/abc/log ; sudo mkdir /home/xyz/log

10: Change folders permissions, try: sudo chown abc:abc -R /home/abc ; sudo chown xyz:xyz -R /home/xyz

11: Link website folders to /va/www/, try: cd /var/www ; sudo ln -s /home/abc . ; sudo ln -s /home/xyz .

We need to update httpd configurations for each website.

12: open /etc/httpd/conf/httpd.conf, and add this to end of file: IncludeOptional sites-enabled/*.conf

13: Create sites-available and sites-enabled directories, try: sudo mkdir /etc/httpd/sites-available ; sudo mkdir /etc/httpd/sites-enabled

13: Create httpd configuration for each website, create abc.conf and xyz.conf files under /etc/httpd/sites-available directory, and write following code in the file.

sudo vi (if you do not have vi installed, try yum install vim) /etc/httpd/sites-available/abc.conf:

< VirtualHost *:80 >

ServerName www.abc.com

ServerAlias abc.com

DocumentRoot /var/www/abc/html

ErrorLog /var/www/abc/log/err.log

CustomLog /var/www/abc/log/requests.log combined

< / VirtualHost *:80 >

repeat above steps for creating xyz.conf under /etc/httpd/sites-available/xyz.conf

Create links for configuration files from sites-available directory to sites-enabled directory, try: sudo ln -s /etc/httpd/sites-available/abc.conf /etc/httpd/sites-enabled/ ; sudo ln -s /etc/httpd/sites-available/xyz.conf /etc/httpd/sites-enabled/

14: Start apache, try: sudo systemctl start httpd

At this stage you are mostly done, now you need to update DNS entries for both web domains. After DNS propogates (you can check how much time it will take from your VPS hosting provider) websites will point to websites directory. You can install wordpress in html/ directory if you want to go with wordpress solutions, until then create an index.html file inside html/ directory for both websites.

Please leave a short message for errors, comments or anything else: hr@Leprofesseur.org