Running Multiple Domain Names on PHP Server

Using multiple domains provides you with the ability to increase the usability, efficiency, and scalability of your PHP application and of course saves your money without the necessity to set up separate instances.

So, let's see how to run multiple domains on the php application server to make your PHP application even more scalable and effective.

1.  Log in to CloudJiffy dashboard.

2.  Click Create an environment at the top left corner of the dashboard.

3. In the opened wizard navigate to PHP tab, pick application server and specify the number of resources your application needs. After that enter the name for the environment and click Create button.

   

4.  In some seconds your environment will appear on the CloudJiffy dashboard.

    

5.  You need to have the names in DNS, resolving to your IP address. So, buy domain names for your environment. It can be done in two ways: by adding CNAME record or by setting A Records. You can read more here.

6. After that click the Settings button for your environment and bind your domains.  As an example, we use the following URLs: mydomain.com and myseconddomain.com.
   

Note: In this case, we put entries in our host's file for local testing and it will work only from the machine with those hosts entries.

7. Now you can upload zip packages with your apps to the Deployment manager and deploy them to the environment you've created earlier.    

 
   

   
Once your applications are successfully deployed you need to specify your virtual host configurations.
 
    • For Apache

8.  Click Config button next to the Apache server and open the httpd.conf file (in conf directory). Set VirtualHost parameters for two domain names separately by specifying the paths to the deployed contexts and the names of domains:

1
2
3
4
5
6
7
8
9
10
11
12
Listen 80
<VirtualHost *:80>
    DocumentRoot /var/www/webroot/firstapp
    ServerName mydomain.com
    ...
</VirtualHost>
 
<VirtualHost *:80>
    DocumentRoot /var/www/webroot/secondapp
    ServerName myseconddomain.com
    ...
</VirtualHost>

 

    • For NGINX

9. Click Config button next to the NGINX server and open the nginx.conf file in the conf directory.

      Specify your settings in the server block:
      • server_name (your domain);
      • ROOT (the context you stated while deploying)
      Note that you need to have a separate server
      block with its own settings for each domain which you bind.
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
server {
        listen       80;
        server_name  localhost;
 
include /etc/nginx/aliases.conf;
        location / {
            root   /var/www/webroot/ROOT;
            index  index.html index.htm index.php;
 
            location ~ \.php$ {
                location ~ /\. { deny all; access_log off; log_not_found off; }
            include /etc/nginx/fastcgi_params;
            fastcgi_pass 127.0.0.1:9000;
            fastcgi_param SCRIPT_FILENAME /var/www/webroot/ROOT$fastcgi_script_name;
            fastcgi_param PATH_INFO $fastcgi_script_name;
            fastcgi_param DOCUMENT_ROOT /var/www/webroot/ROOT;
            }
 
        }
        index  index.php index.html index.htm;
 
error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
 
location ~ /\. { deny all; access_log off; log_not_found off; }
 
location ~ \.php$ {
        location ~ /\. { deny all; access_log off; log_not_found off; }
            include /etc/nginx/fastcgi_params;
            fastcgi_pass 127.0.0.1:9000;
            fastcgi_param SCRIPT_FILENAME /var/www/webroot$fastcgi_script_name;
            fastcgi_param PATH_INFO $fastcgi_script_name;
            fastcgi_param DOCUMENT_ROOT /var/www/webroot;
        }
 
    }
      In our case, the settings will be following-
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
    server {
        listen       80;
        server_name  mydomain.com;
         
    include /etc/nginx/aliases.conf;
        location / {
            root   /var/www/webroot/firstapp;
            index  index.html index.htm index.php;
 
            location ~ \.php$ {
                location ~ /\. { deny all; access_log off; log_not_found off; }
            include /etc/nginx/fastcgi_params;
            fastcgi_pass 127.0.0.1:9000;
            fastcgi_param SCRIPT_FILENAME /var/www/webroot/firstapp$fastcgi_script_name;
            fastcgi_param PATH_INFO $fastcgi_script_name;
            fastcgi_param DOCUMENT_ROOT /var/www/webroot/firstapp;
            }
 
        }
        index  index.php index.html index.htm;
 
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
 
        location ~ /\. { deny all; access_log off; log_not_found off; }
      
        location ~ \.php$ {
        location ~ /\. { deny all; access_log off; log_not_found off; }
            include /etc/nginx/fastcgi_params;
            fastcgi_pass 127.0.0.1:9000;
            fastcgi_param SCRIPT_FILENAME /var/www/webroot$fastcgi_script_name;
            fastcgi_param PATH_INFO $fastcgi_script_name;
            fastcgi_param DOCUMENT_ROOT /var/www/webroot;
        }
 
    }
 
 
server {
        listen       80;
        server_name  myseconddomain.com;
         
        include /etc/nginx/aliases.conf;
        location / {
            root   /var/www/webroot/secondapp;
            index  index.html index.htm index.php;
 
            location ~ \.php$ {
                location ~ /\. { deny all; access_log off; log_not_found off; }
            include /etc/nginx/fastcgi_params;
            fastcgi_pass 127.0.0.1:9000;
            fastcgi_param SCRIPT_FILENAME /var/www/webroot/secondapp$fastcgi_script_name;
            fastcgi_param PATH_INFO $fastcgi_script_name;
            fastcgi_param DOCUMENT_ROOT /var/www/webroot/secondapp;
            }
 
        }
        index  index.php index.html index.htm;
 
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
 
    location ~ /\. { deny all; access_log off; log_not_found off; }
    
    location ~ \.php$ {
        location ~ /\. { deny all; access_log off; log_not_found off; }
            include /etc/nginx/fastcgi_params;
            fastcgi_pass 127.0.0.1:9000;
            fastcgi_param SCRIPT_FILENAME /var/www/webroot$fastcgi_script_name;
            fastcgi_param PATH_INFO $fastcgi_script_name;
            fastcgi_param DOCUMENT_ROOT /var/www/webroot;
        }
 
    }

 

 Don't forget to Save the changes and Restart the application server in order to apply new settings.

  
 
 
 Hope this instruction will be useful for you. Domain names are very crucial pieces of your online identity so don't forget to protect them.

 

  • 0 Users Found This Useful
Was this answer helpful?

Related Articles

Deploy PHP Project > via GIT/SVN

Deploy PHP Project via GIT/SVN You can host any public or your private PHP project at...

Deploy PHP Project > via Archive / URL

Upload and Deploy Your PHP Application In CloudJiffy there is the automatic function of the...

MariaDB > PHP connection

Connection to MySQL/MariaDB for PHP MySQL and MariaDB are highly popular open source...

MongoDB > PHP Connection

PHP Connection to MongoDB MongoDB is a widely used NoSQL database, implemented based on the...

PostgreSQL > PHP Connection

Connection to PostgreSQL for PHP Applications Follow the instruction below to learn how to...

Powered by WHMCompleteSolution