phpurlfuelphp

FuelPHP remove public from url


First sorry, but im a really big beginner, so you can down vote this question if you feel like.

So i went over lots of tutorials, and the only thing what would work for me is to pull the public folder content out.

And the problem is i get a bunch of errors.

error:

Warning: require(\bootstrap.php) [function.require]: failed to open stream: No such file or directory in C:\EasyPHP\www\fuelphp\index.php on line 33

Fatal error: require() [function.require]: Failed opening required '\bootstrap.php' (include_path='.;C:\php\pear') in C:\EasyPHP\www\fuelphp\index.php on line 33

so i discovered that the DOCROOT is C:\EasyPHP\www\fuelphp\, so i will need to pull stuff in this way localhost/fuelphp/fuel/core

the original index looks like this

<?php
/**
 * Set error reporting and display errors settings.  You will want to change these when in production.
 */
error_reporting(-1);
ini_set('display_errors', 1);

/**
 * Website document root
 */
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);

// Get the start time and memory for use later
defined('FUEL_START_TIME') or define('FUEL_START_TIME', microtime(true));
defined('FUEL_START_MEM') or define('FUEL_START_MEM', memory_get_usage());

// Boot the app
require APPPATH.'bootstrap.php';

// Generate the request, execute it and send the output.
try
{
    $response = Request::forge()->execute()->response();
}
catch (HttpNotFoundException $e)
{
    $route = array_key_exists('_404_', Router::$routes) ? Router::$routes['_404_']->translation : Config::get('routes._404_');
    if ($route)
    {
        $response = Request::forge($route)->execute()->response();
    }
    else
    {
        throw $e;
    }
}

// This will add the execution time and memory usage to the output.
// Comment this out if you don't use it.
$bm = Profiler::app_total();
$response->body(
    str_replace(
        array('{exec_time}', '{mem_usage}'),
        array(round($bm[0], 4), round($bm[1] / pow(1024, 2), 3)),
        $response->body()
    )
);

$response->send(true);

than modified to this

<?php
/**
 * Set error reporting and display errors settings.  You will want to change these when in production.
 */
error_reporting(-1);
ini_set('display_errors', 1);

/**
 * Website document root
 */
define('DOCROOT', '/');

/**
 * Path to the application directory.
 */
define('APPPATH', 'fuel/app/').DIRECTORY_SEPARATOR;

/**
 * Path to the default packages directory.
 */
define('PKGPATH', 'fuel/packages/').DIRECTORY_SEPARATOR;

/**
 * The path to the framework core.
 */
define('COREPATH', 'fuel/core/').DIRECTORY_SEPARATOR;

// Get the start time and memory for use later
defined('FUEL_START_TIME') or define('FUEL_START_TIME', microtime(true));
defined('FUEL_START_MEM') or define('FUEL_START_MEM', memory_get_usage());

// Boot the app
require APPPATH.'bootstrap.php';

// Generate the request, execute it and send the output.
try
{
    $response = Request::forge()->execute()->response();
}
catch (HttpNotFoundException $e)
{
    $route = array_key_exists('_404_', Router::$routes) ? Router::$routes['_404_']->translation : Config::get('routes._404_');
    if ($route)
    {
        $response = Request::forge($route)->execute()->response();
    }
    else
    {
        throw $e;
    }
}

// This will add the execution time and memory usage to the output.
// Comment this out if you don't use it.
$bm = Profiler::app_total();
$response->body(
    str_replace(
        array('{exec_time}', '{mem_usage}'),
        array(round($bm[0], 4), round($bm[1] / pow(1024, 2), 3)),
        $response->body()
    )
);

$response->send(true);

now the public is not in the url, but im getting a bunch of errors when i open the site, i see insted of a forward slash uts a back slash, but cant really find the problem

Warning: require_once(fuel/core/classes\error.php) [function.require-once]: failed to open stream: No such file or directory in C:\EasyPHP\www\fuelphp\fuel\core\base.php on line 25

Fatal error: require_once() [function.require]: Failed opening required 'fuel/core/classes\error.php' (include_path='.;C:\php\pear') in C:\EasyPHP\www\fuelphp\fuel\core\base.php on line 25

could please someone give me a hint how to modify the index to be all okay?

thank you


Solution

  • You shouldn't need to modify the index file in order to achieve what you're attempting.

    Fuel is designed to reside above the document root (docroot). Your docroot appears to be www/.

    This means that your directory structure should in fact be as follows:

    C:\EasyPHP\fuelphp\
    C:\EasyPHP\www\
    

    The FuelPHP zip file or git clone (or however you may obtain it) contains a folder entitled public. This folder is the assumed name of your docroot, and therefore in your situation the contents of public/ should be copied into www/

    You can however set it up all inside the docroot as you're attempting and the process is documented on the FuelPHP website here.

    As explained in point 3, for security reasons it is strongly advised NOT to install Fuel inside your webserver's document root.

    However, there are cases where you would like to do that, [...]

    In that case, you need an additional .htaccess file that you need to place in your document root, which will redirect requests to the site root to your public folder, and also modifies the rewrites to include the public folder:

    <IfModule mod_rewrite.c>
        RewriteEngine on
    
        RewriteBase /public
    
        RewriteRule ^(/)?$ index.php/$1 [L]
    
        RewriteCond %{REQUEST_FILENAME} !-f
        RewriteCond %{REQUEST_FILENAME} !-d
    
        RewriteRule ^(.*)$ index.php/$1 [L]
    </IfModule>
    

    The default configuration of index.php takes into account the position of the /fuel/ folder by default. Take for example the following path definition

    define('COREPATH', realpath(__DIR__.'/../fuel/core/').DIRECTORY_SEPARATOR);
    
    __DIR__    - Path of current working directory, i.e. wherever index.php is
    ..         - go up a directory, i.e. directory above wherever index.php is
    fuel/      - Fuel folder
    core/      - Core folder within fuel/
    
    realpath() - Resolves the .. to it's real location and makes sure / is correct or changes to \ depending on the OS
    

    The reason you're getting slashes of varying directions is because you've hardcoded / into the code without using realpath()