0

Cakephp 3 and Subdomain

I have an application cakephp 3 inside the root of my server and need to create a subdomain that this also goes in the same root with the cake.

example:

bin

config

src

...

shop (Sub domain)

How have the cake in my root it does not allow access subdomio. What can I do to get around this problem?

2 Answers2

0

Because the file convention of cakephp is sometimes hard to get the result you want to.

Correct me if I'm wrong. Your situation looks like this?

www.maindomain.com, which run by 'src'. But you want the sub.maindomain.com use other files outside the cakephp file structure

I think it's too much effort to work outside the file convention. I think this is more '.htaccess' and 'virtual hosts' issue.

I've found a link that maybe can you help you "CakePHP subdomains with htaccess"

UPDATE: Also keep in mind the folder-permission issue when you try to fix this.

Community
  • 1
  • 1
shaw kwok
  • 241
  • 5
  • 11
-1

I think the best approach is to have a VirtualHost configured, I am assuming you use Apache, so that the shop folder isn't part of the root of the server. Here you can see how to do it:

  1. Move shop folder to outside Apache root so it's not part of the main website. If it's in /var/www/html/shop move it to /var/www/
  2. Add a VirtualHost to Apache httpd.conf file or add it as shop.conf into /etc/apache2/sites-available/ assuming your server is an Ubuntu 14.04, you must know where to save the file according to your distro.

    # The ServerName directive sets the request scheme, hostname and port that # the server uses to identify itself. This is used when creating # redirection URLs. In the context of virtual hosts, the ServerName # specifies what hostname must appear in the request's Host: header to # match this virtual host. For the default virtual host (this file) this # value is not decisive as it is used as a last resort host regardless. # However, you must set it for any further virtual host explicitly. ServerName shop.local ServerAlias shop.local

        ServerAdmin alejandro@ulfix.com
        DocumentRoot /var/www/shop/    
    
        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined
    
        # For most configuration files from conf-available/, which are
        # enabled or disabled at a global level, it is possible to
        # include a line for only one particular virtual host. For example the
        # following line enables the CGI configuration for this host only
        # after it has been globally disabled with "a2disconf".
        #Include conf-available/serve-cgi-bin.conf
    

  3. Optional: Edit /etc/hosts file so that you can reach the new subdomain if it is in a VM o you can't resolve it from your computer:

    192.168.100.14 shop.local # Change IP to your Server's IP

  4. Enable site in Apache (In Ubuntu you'll need to run: sudo a2ensite shop.local) and restart Apache Server.

See CakePHP 2.x virtual host file for Apache2 for reference.

  • 1
    While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes. – Richard Oct 29 '15 at 19:47
  • Totally agree, I added suggestions to my original answer – Alex L. Hernandez Oct 30 '15 at 16:39