简体   繁体   中英

PHP Slim throws Internal Server Error 500

I'm trying to deploy a RESTful web application which was developed in a local machine. The same code works perfectly in the local XAMPP server but fails to load upon uploading into a remote Linux server.

Here'e the .htaccess file ,

RewriteEngine On 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteRule ^(.*)$ %{ENV:BASE}index.php [QSA,L]

Since it doesn't works, I've also tried with the small modification,

RewriteEngine On 
RewriteBase /slim/
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php [QSA,L]

I'm still getting error 500. Seems like the remote server is preventing the scripts or its files from getting executed. This is absolutely strange because the same codes works perfectly in local server. Any kind of help or suggestion would be realty appreciated.

The file permission for the file is also set to 777 (read, write, execute)

Current PHP version in remote server is PHP V5.6

I think you are using suphp on your server and you have setup 777 permission for your all files and that is the reason you are facing this issues. Please change you all file permission to 644 and folder permission to 755 and check your domain URL.

To be able to run your PHP slim app on live server eg IONOS servers,
there are two things you need to sort out:
1. The webserver:
Create a .htaccess file in /var/www/html/myapp (root directory path) where myapp directory stores all your slim app files.

RewriteEngine On
RewriteBase /myapp
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^ index.php [QSA,L]

The key thing here is the RewriteBase directive which must be set.
2. Your Slim 4 app config
In your index.php, add:

$app->setBasePath('/myapp');

Viola!

Follow link for detailed explanation https://akrabat.com/running-slim-4-in-a-subdirectory/#the-web-server-apache

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM