Silex 500 Error Off The Bat - php

This is a very noob question. I'm basically just trying to run the "hello world" of Silex. I've installed the silex.phar file in my directory, setup the .htaccess file as such:
<IfModule mod_rewrite.c>
Options -MultiViews
RewriteEngine On
#RewriteBase /projects/silex/ ###--> commented out because file is in root dir. <--##
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
and then run these two lines of code on the index.php file:
require_once __DIR__.'/silex.phar';
$app = new Silex\Application();
I am getting a 500 internal server error. ("File does not exist")
I am running php 5.3.8 on Linux.
Is there a PHP setting I should be looking for?

Turns out there is a bug called the phar-stub bug. It will tell you that Silex\Application could not be found. A workaround is using the following include line:
require_once 'phar://'.__DIR__.'/silex.phar/autoload.php';
source

Related

Laravel 8 application shows blank page on webserver

So I am trying to run my Laravel 8 application on my server. I don't have root/SSH access, so I do everything with an FTP client. I uploaded all my content to my webserver and added my .htaccess file in order to run the application. It works fine in my local environment, but on my server it shows only a blank page. I put some debugging outputs in the public/index.php file and it can var_dump the $app variable.
$app = require_once __DIR__.'/../bootstrap/app.php';
var_dump($app); //Works
But it cannot var_dump $response.
$response = tap($kernel->handle(
$request = Request::capture()
))->send();
var_dump($response); //Never reached statement
I guess it just aborts somewhere deep in the Laravel execution jungle and this would be hard to trace.
This is my project root .htaccess file:
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews -Indexes
</IfModule>
RewriteEngine On
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
RewriteRule ^(.*)$ public/$1 [L,QSA]
</IfModule>
I cleared everythin in the storage folder but this doesnt make any impact. I also changed permissions of storage, vendor and bootstrap folder to 755 but it didn't change anything.
Locally it works both with php artisan serve or by placing everything in my htdocs folder of my XAMPP installation and browsing there.
What is the problem here?

URL not found when trying to use slim framework with PHP and Apache

I have this code using the slim framework and php with apache2 on linux:
<?php
use \Psr\Http\Message\ServerRequestInterface as Request;
use \Psr\Http\Message\ResponseInterface as Response;
require '../../vendor/autoload.php';
$app = new \Slim\App;
#doesn't work results in URl not found in browser
$app->get('/hello','sayhi');
#works, when i just type in 'localhost/' into my webbrowser
$app->get('/',function()
{
return 'testing';
});
$app->run();
#functions
function sayhi()
{
echo 'hello world again';
}
.htaccess (same directory as my index.php file)
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule . index.php [L]
000-default.conf has the documentroot set to the directory of where my php file and .htaccess file.
When i type in 'localhost/' into my web browser the anonymous function is executed. As that's what it will do if the server recieves '/'
However when i type in 'localhost/hello' it results in URL not found, when it should execute the 'sayhi' function when the server receives this type of url.
Why is it doing this? is there something wrong in my code, as i don't understand how to go about sorting this.
I also tried setting the option to the directory of my php file
AllowOverride All
However this results in a 500 Internal error, when i have this option set. I tried following this guide: 500 internal error guide to no avail.
I have no idea how to sort this, help?
You can tell Apache to redirect all routes to index. Try something like in your vhost or in a .htaccess file :
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php [QSA, L]
I think you need to configure apache so that all requests would go into index.php in which your code are located. It seems that when you request localhost/hello your web server tries to find file hello.

htaccess in laravel application

I've setup a laravel application on a shared server, the direct url works fine but when I access the other pages I receive the error message: The requested URL /contact was not found on this server.
but if I then type "http://unit13productions.co.uk/index.php/contact" this shows the correct page.
I'm not sure if this is the htaccess file or the index.php file?
My file directories on the server are as follow:
unit13 folder:
public_html folder:
my file directories inside my index.php is:
autoloader:
require __DIR__.'/../unit13/vendor/autoload.php';
turn the lights on:
$app = require_once __DIR__.'/../unit13/bootstrap/app.php';
contents of my htaccess file:
AddType x-httpd-php71 .php
This sounds like it could be an issue with your .htaccess file more than anything else. Try renaming your .htaccess file to .htaccess1 just so it isn't used and then create a new one and add the following to it
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
The details on how to configure your application for either Apache or Nginx is listed on the laravel documentation which I've listed below.
https://laravel.com/docs/5.7/installation#pretty-urls
Hope this helps!

Slim Framework - Blank page when I deploy

I need some help to use Slim Framework. Indeed, I'm a beginner in PHP and I would like to migrate my API using Slim Framework in order to have a clean code. I successed to run Slim Hello Word app on my WAMP server locally, but when I deploy it on my OVH server shared, I have a blank page on route [root]/myproject/hello/test.
The question has already asked but the problem was not exactly the same.
For information I had a 500 internal error locally which was resolved when I've activated rewrite_module on my WAMP server.
I have a SSH access to OVH server but composer is not installed. It seems that mod_rewrite is enabled. WAMP and OVH server use PHP 5.5
This is my folder directory:
Project/
src/
public/
.htaccess
index.php
vendor/
autoload.php
slim/
slim/
Slim/
App.php
...
composer.json
composer.lock
This is my .htaccess file
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule . index.php [L]
And my index.php
<?php
use \Psr\Http\Message\ServerRequestInterface as Request;
use \Psr\Http\Message\ResponseInterface as Response;
require '../vendor/autoload.php';
$app = new \Slim\App;
$app->get('/hello/{name}', function (Request $request, Response $response) {
$name = $request->getAttribute('name');
$response->getBody()->write("Hello, $name");
return $response;
});
$app->run();
Any ideas to resolve it?
Thanks.
try to use this .htaccess config
<IfModule mod_rewrite.c>
Options -MultiViews
RewriteEngine On
#RewriteBase /path/to/app
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [QSA,L]
</IfModule>
Also install monolog https://github.com/Flynsarmy/Slim-Monolog

Internal 500 error laravel 5.2

I have a domain say www.example.com and on the root of the domain I have a folder called development. Inside development I have a folder called hunterlp and inside the hunterlp folder all my laravel files are placed when I navigate to http://www.example.com/development/hunterlp/ i am greeted by a 500 internal server error.
I moved all my folders from public to the hunterlp root folder and placed a .htaccess with the following in
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
Options +FollowSymLinks
RewriteEngine On
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
# Handle Authorization Header
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
How can I make my laravel site work in that folder?
please follow this instruction its work for you
1. connect to hosting via SSH
2. install composer
3. in cpanel open Select PHP version and choose 5.4. (I also set phar extension)
4. install laravel: php composer.phar create-project laravel/laravel myproject --prefer-dist
5. copy everything from myproject/public to public_html
6. open public_html/index.php and set:
7. require __DIR__.'/../myproject/bootstrap/autoload.php';
8. $app = require_once __DIR__.'/../myproject/bootstrap/start.php';
for the 7 and 8 steps give the path where you source has so that file find that files
Hope this is works.

Categories