I am new to slim framework. Currently on my existing webserver which is on centos 7 I have other php based application running. So currently my directory structure is like this.
var/www/html
phpapp1
phpapp2
apislim
The folder for the apislim I created was for slim framework. Below are the exact steps I did was
composer create-project slim/slim-skeleton
I rename the slim-skeleton
folder to apislim
I make sure the owner is apache chown -R apache:apache apislim
In the httpd.conf
I ensure this AllowOverride
is enabled to be All
<Directory "/var/www"> AllowOverride All # Allow open access: Require all granted Options -Indexes
Also below I enabled All
<Directory "/var/www/html">
Options -Indexes -FollowSymLinks
AllowOverride All
</Directory>
.htaccess
file as below.<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_URI}::$1 ^(/.+)/(.*)::\2$
RewriteRule ^(.*) - [E=BASE:%1]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ %{ENV:BASE}index.php [QSA,L]
</IfModule>
The I have also the index.php
file in the public folder which also links up to the src
for the routes and the main folder apislim
I created another .htaccess
file and added this.
RewriteEngine on RewriteRule ^$ public/ [L] RewriteRule (.*) public/$1 [L]
The issue now I want my existing application to work along with this REST api which is based on Slim framework. So when I go to this link
http://*.*.*.*/apislim/
http://*.*.*.*/apislim/public/
http://*.*.*.*/apislim/public/index.php
Neither of it works all are giving me 403 forbidden. Then I check the error log it show error regarding FollowSymLinks
So I added
Options -Indexes +FollowSymLinks
into <Directory "/var/www/html">
So next error I get now is 500 interval server error.
The following steps are necessary for your Slim 3 application to work within subdirectories.
Directory structure:
public/
Web server files (the DocumentRoot)
.htaccess
Apache redirect rules for the front controllerindex.php
The front controller.htaccess
Internal redirect to the public/ directoryThe content of the file: .htaccess
:
RewriteEngine on
RewriteRule ^$ public/ [L]
RewriteRule (.*) public/$1 [L]
The content of the file: public/.htaccess
:
# Redirect to front controller
RewriteEngine On
# RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [QSA,L]
Add this container entry to the file: dependencies.php
:
// Activating routes in a subfolder
$container['environment'] = function () {
$scriptName = $_SERVER['SCRIPT_NAME'];
$_SERVER['SCRIPT_NAME'] = dirname(dirname($scriptName)) . '/' . basename($scriptName);
return new Slim\Http\Environment($_SERVER);
};
Edit: In Slim 4 you should use the $app->setBasePath($basePath);
method. More details