Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
Setting Up Fuel to work in a MultiSite/Virtual Subdirectory Environment
  • Hello, This is my first FuelPHP forum post so I hope I am putting it in the right place :P My Backstory: I have a CodeIgniter "organiser" project that gives users their own "installations (subdomains), and I wish to re-write it from scratch in FuelPHP. Here is the file structure I am using at the moment.
    /
     public_html/
      programs/
       user_install/
        application/
         config/
          config.php
        core/
       cool_space/
        application/
         config/
          config.php
        core/
      website/
    
    So basically through a little .htaccess magic when someone requests [url=http://user_install.mydomain.com]http://user_install.mydomain.com[/url] they are actually accessing /public_html/programs/user_install folder. Now the question??? How can I translate this into FuelPHP land. I understand that the core of Fuel prefers to be above the public_html folder for security reasons. I love this idea but I also like organising the "installs" into the /public_html/programs/ folder. Also, I need to deal with a multisite environment so obviously the individuals installs config files (such as database variables) need to be within the /programs/user_install folder. In my dream world I would love to have the following file structure:
    /
     fuel/
      core/
      packages/
     public_html/
      programs/
       user_install/
        .htaccess/
        app/
        assets/
        index.php
       cool_space/
        .htaccess/
        app/
        assets/
        index.php
     oil
    
    Is this possible with FuelPHP? Thanks for your help. Tim
  • Harro Verton wrote on Thursday 12th of January 2012:
    I have gone a step further, and separated core and packages from app, so for all sites hosted on a server I only have a single core and packages folder, the index.php files for all apps point to these folders. Core and all packages are git clones in my development setup, which makes it very easy to test the application with different versions of the FuelPHP code: just switch branches.

    WanWizard, This sounds exactly what I am looking for! Are you able to provide more clues as to how you have achieved this? I have heard Symlinks could be used but haven't had a chance to try them out. Thanks, Tim
  • This is my FuelPHP structure:
    /data/www/fuelphp/
        1.0.master
        1.1.develop
        1.1.master
    
    in each I have 'core' and 'packages'. The master versions contains static versions (from the zip), the develop a git clone that I can easily update. Then, the index.php (and oil) files of my app contain
    /**
     * Path to the application directory.
     */
    define('APPPATH', realpath(__DIR__.'/../app/'));
    
    /**
     * Path to the default packages directory.
     */
    define('PKGPATH', '/data/www/fuelphp/1.1.master/packages/');
    
    /**
     * The path to the framework core.
     */
    define('COREPATH', '/data/www/fuelphp/1.1.master/core/');
    
    Which is an example of an app that runs on 1.1 master. You also see I moved 'app' one level up, so I can remove the entire 'fuel' directory (as core and packages are no longer required too). On my development machine I only have 1.1 develop installed (but same way), and I use 'git checkout' to swap branches in case I need to test an upgrade, or changes in develop that I'm making.
  • I currently run a few sites on hostmonster, so they are all hosted under the same public_html path. I'm hoping to move some of these sites into using Fuel, which I'm guessing is what you mean by multisite implementation, if not please forgive me for the rest of this response.
    So far in my dev environment I wanted to get a few different instances of Fuel working, one instance for each site. My structure looks like this:
    /
      site1/
           fuel/      (fuel instance specific for site1)
      site2/
           fuel/      (instance specific for site2)
      docs/
      public_html/
           site1/
               index.php
           site2/
               index.php
      oil
    
    Then in each of the index.php for the sites, I point the app, pkg, and core path to that specific fuel instance. Example:
    define('APPPATH', realpath(__DIR__.'/../../site1/fuel/app/').DIRECTORY_SEPARATOR);
    

    Not sure if that helps you guys out or not. I'm actually doing this for add-on domains instead of subdomains, but they all live in the same place inside of the public_html folder. Hope this helps out a little bit. This is also my first post, and Im in the middle of my first Fuel site, so if there are any pro's reading this, please let me know if this directory structure is a bad idea. Otherwise, I see no issues with doing this.
  • I have gone a step further, and separated core and packages from app, so for all sites hosted on a server I only have a single core and packages folder, the index.php files for all apps point to these folders. Core and all packages are git clones in my development setup, which makes it very easy to test the application with different versions of the FuelPHP code: just switch branches.
  • What happened to your project now? I'm also doing multisite implementation. Any updates on what happened to your site?
  • Hi, I'm a complete newbie here. Can someone please explain or give me example on how to do this (copied from the manual installation instruction): - Edit the paths in index.php to point to your app, core & packages directories. Now looking at the index.php, I'm sorry to say that I'm completely clueless on what to do here:
    /**
    * Website document root
    > Please give me example on how to define this?
    */
    define('DOCROOT', __DIR__.DIRECTORY_SEPARATOR); /**
    * Path to the application directory.
    */
    define('APPPATH', realpath(__DIR__.'/../fuel/app/').DIRECTORY_SEPARATOR); /**
    * Path to the default packages directory.
    */
    define('PKGPATH', realpath(__DIR__.'/../fuel/packages/').DIRECTORY_SEPARATOR); /**
    * The path to the framework core.
    */
    define('COREPATH', realpath(__DIR__.'/../fuel/core/').DIRECTORY_SEPARATOR); Please give me some example on how to define all of these, and also I don't know what is DIRECTORY_SEPARATOR function. What is that, and what is it supposed to do? Thanks.
  • You shouldn't modify DOCROOT. It points to where the index.php file is, which is per definition the current directory (as you're in the index.php). APPPATH should point to your app folder. By default, that's one folder up from where your index file is (public), and then in "fuel/app". COREPATH should point to your core folder. By default, that's one folder up from where your index file is (public), and then in "fuel/core". Same drill for packages. The realpath() call is used here to get rid of the relative path ( the "../" ). In a standard setup (and it is very strongly adviced you follow this), there is no need to change any of these values, it should work out of the box. If you decide to deviate from the standard, you'll have to modify the paths that you have changed. In my setup for example, I use the standard folder layout for all my virtual hosts, but I have moved the core and the packages out of it to a shared location for all virtual hosts. So I have changed the path for COREPATH and PKGPATH to point to that location.
  • Hi Harro, thx for ur reply. I haven't changed anything. I just downloaded the fuelphp 1.2rc1, and then copied it in my localhost: C:\AppServ\www\fuelphp (Please note that I haven't moved my fuel core to somewhere else). Since I thought it was derived from CI, I expected it to work right out of the box and give me a welcome message when I type 'localhost/fuelphp/public' but then I got the message: Notice: Use of undefined constant __DIR__ - assumed '__DIR__' in C:\AppServ\www\fuelphp\public\index.php on line 11 Notice: Use of undefined constant __DIR__ - assumed '__DIR__' in C:\AppServ\www\fuelphp\public\index.php on line 16 Notice: Use of undefined constant __DIR__ - assumed '__DIR__' in C:\AppServ\www\fuelphp\public\index.php on line 21 Notice: Use of undefined constant __DIR__ - assumed '__DIR__' in C:\AppServ\www\fuelphp\public\index.php on line 26 Warning: require(\bootstrap.php) [function.require]: failed to open stream: No such file or directory in C:\AppServ\www\fuelphp\public\index.php on line 33 Fatal error: require() [function.require]: Failed opening required '\bootstrap.php' (include_path='.;c:\\\\\\\\\\\\\\\\appserv\\\\\\\\\\\\\\\\zend\\\\\\\\\\\\\\\\bin include_path = .') in C:\AppServ\www\fuelphp\public\index.php on line 33
    The prob is, when I look at the index.php, I don't know how to point the index.php to the correct location of APPPATH, COREPATH, PKGPATH, and so on. I think the thing that really confuse me is the .DIRECTORY_SEPARATOR, as I don't have any clue whatsoever of its use. Can u give me an example on how to point the path to the correct location? Thx.
  • Upgrade your PHP version. FuelPHP requires PHP 5.3+.
  • *double facepalms... Thanks :D
  • Check out the public/index.php file, you can configure the paths to core, packages and app individually. I'd still recommend against it, your executable code is publicly accessable this way. If you must, at least put a .htaccess in the programs dir with "deny from all" (should prevent direct access).

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

In this Discussion