Over a million developers have joined DZone.

Running Multiple Domain Names on Apache Server

DZone's Guide to

Running Multiple Domain Names on Apache Server

· DevOps Zone ·
Free Resource

Get the fastest log management and analysis with Graylog open source or enterprise edition free up to 5GB per day

Of course your PHP website domain name is a front-page online property. Your customers use it to access your site and it’s closely connected with your site’s brand. BTW  the words that make up a domain names are used by search engines to evaluate websites in search results.

It is a good idea to register multiple domain names that are similar to your website’s main domain name to protect your website’s online brand.  But it’s not the only advantage of using multiple domains, it gives you the ability to increase the usability, efficiency and scalability of your PHP application and of course to save your costs without having to set up separate instances.

So, let’s consider how to run multiple domains on Apache server to make your PHP application even more scalable and effective.

1. Log into your Jelastic account and click Create environment.

2. In the appeared window navigate to PHP tab, pick Apache server and specify the number of resources your application needs. After that enter your environment name and click Create.

PHP Environment with Apache Server

In some seconds your environment will appear on the Jelastic dashboard.

Multiple Domain Names Apache Environment

3. You need tohave 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. Read more here

4. Then click the Settings button for the environment you have created earlier and bind your domains. In this case we use the next URLs: mydomain.com and myseconddomain.com.

Binding Domain Name in Jelastic

Note: In this casewe put entries in our hosts file for local testing and this will work only from the machine with those hosts entries.

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

PHP Application Deployment

Second PHP Application Deployment

6. Once your applications are successfully deployed click Config button for Apache server and navigate to the httpd.conf  file (conf directory) to specify your virtual host configurations:

Listen 80
<VirtualHost *:80>
    DocumentRoot /firstapp
    ServerName mydomain.com

<VirtualHost *:80>
    DocumentRoot /secondapp
    ServerName myseconddomain.com

Multiple Domain Names Apache Server Configuration

7. Save the changes and restart Apache in order to apply new settings.

Restart Apache Server

8. Now you can check the results to ensure the all works properly.

PHP Application in a Browser

Hope this stuff will be useful for you. Domain names are very crucial pieces of your online identity so don’t forget to protect them. With Jelastic it’s only few minutes. Enjoy!

Get the fastest log management and analysis with Graylog open source or enterprise edition free up to 5GB per day


Published at DZone with permission of

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}