I have a CentOS VPS with LAMP installed. I set up CakePhP and I have my httpd.conf set up with 1 virtual host which points to my CakePhP directory. I have various sub-domains in my CakePhP environment, which reside as sub-directories within my overall CakePhP directory.

But now I'd like to have a sub-domain that runs raw PhP, outside the CakePhP environment.

It's like this:

  • www.example.com/sub1 resides in /www/var/cakephp_install/sub1
  • www.example.com/sub2 resides in /www/var/cakephp_install/sub2
  • www.example.com/sub3 resides in /www/var/html/sub3

So sub3 is not a CakePhP App. It does not reside within the CakePhP environment. What is the best way to route or index or configure this? I've played with the httpd.conf, .htaccess, and index.php files. Nothing I've tried works.

1 Answer 1


You'll need to:

1) Create a new A record for the subdomain, the process differs depending on your DNS setup. You may need to do this through your registrar, or if you're hosting your own DNS servers create the record yourself.

2) Setup a second virtual host in Apache. This should look something like

<VirtualHost *:80>
    ServerName subdomain.domain.com
    DocumentRoot /var/www/html/sub3
    # Other directives can go here

3) Restart Apache sudo apachectl restart or service httpd restart

Now if you drop a file called index.php containing <?php phpinfo(); into /var/www/html/sub3 and browse to subdomain.domain.com you should see your PHP settings page.

  • Thanks for your answer. This would only work if my domains were in DNS correct? If I'm using raw IP numbers (because it's an internal website and I'm just testing it anyway) then there's no way to identify a separate virtual host, correct?
    – Joe C
    Commented Jun 30, 2015 at 14:51
  • Sort of... if it's just for testing on your own machine, you can create a dubdomain, or any hostname really, in your /etc/hosts file that points to (localhost), and then create the VirtualHost for that hostname. You could also just setup the VirtualHost to listen on a different port, say port 81, and then use your IP address with port 81. Commented Jun 30, 2015 at 14:56
  • Well it's just for testing right now and I don't have the domains in DNS, but it isn't localhost either. These sites are on a VPS. I'd been accessing them with my browser using raw IP number. I was hoping that could go to the CakePhP stuff but could go to the html stuff.
    – Joe C
    Commented Jun 30, 2015 at 15:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.