Skip to content

Instantly share code, notes, and snippets.

@githubgobi
Created July 11, 2018 06:04
Show Gist options
  • Save githubgobi/dc9a1b8817def7fe2864c44dbf90f95a to your computer and use it in GitHub Desktop.
Save githubgobi/dc9a1b8817def7fe2864c44dbf90f95a to your computer and use it in GitHub Desktop.
Running multiple Slim Framework sites with XAMPP

Running multiple Slim Framework sites with XAMPP

Slim 3 cannot work in a subdirectory by default.

Here I will show you a simple soultion to run multiple Slim applications under Apache.

Fixing the slim environment

The directory skeleton structure:

C:\xampp\htdocs\slim3-app
-- config
---- container.php
-- public
---- .htaccess
---- index.php
-- vendor
-- .htaccess

slim3-app/.htaccess

RewriteEngine on
RewriteRule ^$ public/ [L]
RewriteRule (.*) public/$1 [L]

slim3-app/config/container.php

Add this fix to the container:

<?php

// ...

$container['environment'] = function () {
    $scriptName = $_SERVER['SCRIPT_NAME'];
    $_SERVER['REAL_SCRIPT_NAME'] = $scriptName;
    $_SERVER['SCRIPT_NAME'] = dirname(dirname($scriptName)) . '/' . basename($scriptName);
    return new Slim\Http\Environment($_SERVER);
};

Now just open the application: http://localhost/slim3-app

Links

Keywords

Apache, XAMPP, PHP, Slim Framework

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment