I have a Laravel 4 app deployed on shared Hostgator server.
When I navigate to:
http://mydomain.com/laravel/public/
I can see the Laravel splash screen.
but when I try to access any other route to, say, /users or /posts I am getting
Internal Server Error 500
http://mydomain.com/laravel/public/posts
Controller:
public function index()
{
$posts = $this->post->all();
return View::make('posts.index', compact('posts'));
}
In Routes.php:
Route::resource('posts', 'PostsController');
I use Jeffrey Way's Generator to scaffold the posts entity.
The same works fine on my local machine. Controllers don't contain any logic, they only output the fetched data.
Error logs are empty.
Any ideas what to check? .htaccess, maybe?
Here is what I have there:
AddType application/x-httpd-php53 .php
<IfModule mod_rewrite.c>
Options -MultiViews
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
As mentioned in comments, a 500 error without a corresponding log file entry from the application logger is likely an .htaccess file issue.
Since the OP found the issue is related to the rewrite (and not the directive to use php 5.3):
Since this is probably a common issue on Hostgator, you should check with their help docs.
However, my first stab at a fix would be to add a RewriteBase directive:
RewriteBase /
So it would look like:
<IfModule mod_rewrite.c>
Options -MultiViews
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
Note that this assumes you're running the web application form the web root and not a sub-directory.
Related
My laravel 5 project is works well on localhost. After moving the project to the server it shows an internal server error.
Error message
The server encountered an internal error or misconfiguration and was unable to complete your request.
I checked the requirements. All requirements are correct.
PHP = 5.5
Mcrypt PHP Extension = Enabled
OpenSSL PHP Extension = Enabled
Mbstring PHP Extension = Enabled
Tokenizer PHP Extension = Enabled
Both .htaccess files on the root and public folder are same,
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
# Redirect Trailing Slashes...
RewriteRule ^(.*)/$ /$1 [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
I tested by removing the both .htaccess files but it still shows the Internal server error.
How Can I fix this issue ? Any suggestions ?
check if mod_negotiation is enabled. I had the same issue just now
I have faced the same issue while migrating the shared server . The solution that worked me is as below.
Let's say there is laravel folder called test which contains folder structure of laravel.
I have use 2 different .htaccess file
1) one in the root folder of the (installed) laravel , i.e Along with test folder with content as below.
RewriteEngine On
RewriteCond %{REQUEST_URI} !^test/public
RewriteRule ^(.*)$ test/public/$1 [L]
2) One in the public folder i.e inside test/public with content as below.
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
It worked for me.
The following .htaccess was able to allow my symfony project domain to be served without app.php in the URL, as intended. The only issue is that it is breaking all other (non-symfony related) urls and causing an internal server error.
Right now, after deleting the .htaccess file from the server, all my domains work but the project tied to symfony must be accessed using app.php in URL ?
Is it possible to modify the below .htaccess to rewrite the symfony url to not require app.php in the URL while still allowing for all other URLs, not tied to symfony, to be accessed successfully?
Not sure this is needed, but assume the domain tied to symfony is www.apples.com.
Thanks in advance!
<IfModule mod_rewrite.c>
Options +FollowSymlinks
RewriteEngine On
# Explicitly disable rewriting for front controllers
RewriteRule ^app.php - [L]
RewriteCond %{REQUEST_FILENAME} !-f
# Change below before deploying to production
RewriteRule ^(.*)$ /app.php [QSA,L]
</IfModule>
Edit
I also tried the following:
<IfModule mod_rewrite.c>
Options +FollowSymlinks
RewriteEngine On
# Explicitly disable rewriting for front controllers
RewriteRule ^app.php - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# Change below before deploying to production
RewriteRule ^(.*)$ app.php [QSA,L]
DirectoryIndex index.php
</IfModule>
Right after
RewriteCond %{REQUEST_FILENAME} !-f
add
RewriteCond %{REQUEST_FILENAME} !-d
and set DirectoryIndex to index.php
A bit late to this game but I just found an Apache directive that saves so much time and makes your htaccess cleaner. The only caveat is you must have Apache 2.2.16+. To have all urls except valid files (images, etc) use app.php as a front controller use the FallbackResource directive.
<Directory "/web/symfony-project">
FallbackResource /app.php
</Directory>
does anybody know how to setup Laravel that it´ll work on a shared Server based on Linux?
I´ve tried default and alternative .htaccess files:
when I type a url which doesn´t exists and isn´t defined in routes.php I get this:
.
Internal Server Error
The server encountered an internal error or misconfiguration and was unable to complete your request. Please contact the server administrator, and inform them of the time the error occurred, and anything you might have done that may have caused the error. More information about this error may be available in the server error log. Additionally, a 500 Internal Server Error error was encountered while trying to use an ErrorDocument to handle the request.
when I type a url to a folder which exists but isn´t defined in routes.php I get a Redirect Loop
when I type a url to a file which exists but isn´t defined in routes.php I get same Error like first one
here the .htaccess files I´ve tried with (both behave same)
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
# Redirect Trailing Slashes...
RewriteRule ^(.*)/$ /$1 [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
.
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
I got my Symfony site installed on my GoDaddy production sever. It works fine when I use the url www.amcolan.info/Symphony/web/app.php/index. I want it to set it up to work as www.amcolan.info/index.
I altered the domain to point to the folder amcolan/Symfony/web via a GoDaddy control panel. It used to point to /amcolan which contains the working version of my site. After I got that set up, I installed the following .htaccess file:
<IfModule mod_rewrite.c>
Options +FollowSymlinks
RewriteEngine On
# Explicitly disable rewriting for front controllers
RewriteRule ^/app_dev.php - [L]
RewriteRule ^/app.php - [L]
# Fix the bundles folder
RewriteRule ^bundles/(.*)$ bundles/$1 [QSA,L]
RewriteCond %{REQUEST_FILENAME} !-f
# Change below before deploying to production
RewriteRule ^(.*)$ app.php [QSA,L]
#RewriteRule ^(.*)$ app_dev.php [QSA,L]
</IfModule>
I got the code from another related question on this site and modified to my purpose. The original was intended to live in the Symfony directory. I then cleared the production cache and attempted to access a page. It resulted in an Internal server error. Are there any errors in my code? You'd think this would be well documented by Sensio as I imagine 99% of all implementations would have to do this. Now I'm just getting bitter.
As suggested, I tried the following code that came with Symfony:
<IfModule mod_rewrite.c>
RewriteEngine On
<IfModule mod_vhost_alias.c>
RewriteBase /
</IfModule>
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ app.php [QSA,L]
</IfModule>
I also tried:
<IfModule mod_rewrite.c>
RewriteEngine On
#<IfModule mod_vhost_alias.c>
#RewriteBase /
#</IfModule>
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ app.php [QSA,L]
</IfModule>
I got the same error as before with both. To make sure I was getting to the directory, I added a index.php file to it and I was able to access it.
Update 2
After rooting around some more about goDaddy specific issues, I found a post on a goDaddy forum saying the RewriteEngine is already on. I deleted that code without affect. I then decided to try this:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ http://www.amcolan.info/app.php/index [QSA,L]
That got it to work although I suspect not correctly. I had first tried it without the index after app.php/. That got me into symfony, but generated a get error. It appeared to be because of a null argument so I added the index. So, regardless of what someone might enter after www.amcolan.info, it's going to go to the index. Once you are on a Symfony page, you can navigate to other pages in the site. So now I have three new questions:
Any idea to where the web server is pointing when it reads the .htaccess file? You would think in the /web directory as that's where the file lives. Since just specifying app.php instead of the full path didn't work, it must not be the case. Would it be the base of my site?
After the successful redirection of www.amcolan.info, the resulting displayed URL is www.amcolan.info/app.php/index. I'd like to not see the /app.php in the URL, but I suspect that's not possible in as much as it is the actual destination. Is that a correct assumption?
How do I get www.amcolan.info/somepage to go to www.amcolan.info/app.php/somepage rather than the hard coded index?
Update 3
I thought I was stuck, but then I tried:
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ app.php/index [QSA,L]
That got rid of having to use the full URL and now the destination pages no longer display the app.php. I have a new problem: just specifying www.amcolan.info causes the get error mentioned above. Specifying www.amcolan.info/somepage no longer takes me to the index, but to the specified page. Stay tuned, I may be able to solve my last problem with a little more digging.
Update 4
I fixed the last problem by adding the following to my routing file:
nopage:
pattern: /
defaults: { _controller: ZetchoAmColAnBundle:Default:index }
requirements:
_method: GET
I think I'm a happy camper now.
index action is not necessary. You can easily configure any action for root routing as well.
Here is my full .htaccess file on GoDaddy that finally works. It works only for prod config (app.php), app_dev.php is not working well, but that is OK for me since it is used for production environment.
DirectoryIndex app.php
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ /app.php/ [QSA,L]
</IfModule>
I've been trying to set up .htaccess to create clean PHP URL. My goal is to achieve clean URLs within the folder CL.
.htaccess:
# Use PHP5 Single php.ini as default
AddHandler application/x-httpd-php5s .php
<IfModule mod_rewrite.c>
# This is the initialization
# For security reasons, Option followsymlinks cannot be overridden.
#Options +FollowSymLinks
Options +SymLinksIfOwnerMatch
RewriteEngine On
RewriteBase /
# /CL/var1/var2/var3
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^CL/([a-zA-Z0-9\-]+)/([a-zA-Z0-9\-]+)/([a-zA-Z0-9\-]+)/?$ /CL/index.php?var1=$1&var2=$2&var3=$3 [L,QSA]
# /CL/var1/var2
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^CL/([a-zA-Z0-9\-]+)/([a-zA-Z0-9\-]+)/?$ /CL/index.php?var1=$1&var2=$2 [L,QSA]
# /CL/var1
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^CL/([a-zA-Z0-9\-]+)/?$ /CL/index.php?var1=$1 [L,QSA]
</IfModule>
However, for some reason, I get a 500 internal server error when y enter the folder CL. I've used similar .htaccess configurations in the past, but now its not working fore some reason.
Any ideas?
"I've used similar .htaccess configurations in the past, but now its not working fore some reason."
OK, so the ruleset works. I've just tested in on one my test VMs so it still works, so your problem isn't the mod_rewrite functionality in this .htaccess file. So where could it be?
Think laterally. A 500 status is usually a mod_rewrite loop. Have you got an .htaccess file in /CL? This could create a perdir indefinite loop.
Unfortunately DS suggestion of trying to get an answer on error_log content from a shared hosting provider for a $100 pa shared service is a no-no. Morale: set up a test VM on your PC to debug this stuff where you can get root access to the log as article here.