2

I'm trying to upload some images on public/images directory. Upload worked but when I want to access to uploaded image by its address, I get permission denied error.

403

Forbidden

Access to this resource on the server is denied!

Image path is:

/public_html/public/images/someimage.jpg

and when I want to access to this image by this URL:

http://example.com/images/someimage.jpg

I get the permission denied error.

I used the below htaccess to send all requests to public folder

<IfModule mod_rewrite.c>
    RewriteEngine On 
    RewriteRule ^(.*)$ public/$1 [L]
</IfModule>

My images folder has 0777 permission and my files have 0644 permission.

By the way, I'm using shared host and I don't access to shell.

=============== EDIT

I found something new maybe help us to find the solution. Files that uploaded by Laravel have UID 99 (first photo) but files that uploaded by FTP (and old files) have UID 715 (second photo) !!!!

enter image description here

enter image description here

Saeed M.
  • 2,216
  • 4
  • 23
  • 47
  • so I assume you every thing else works expect the image access? when you want to view an image. You get the problem, can you let me know how one URL with image looks like, that you have problem with – Maytham Fahmi Apr 17 '16 at 17:32
  • @maytham-ɯɐɥʇʎɐɯ : thanks. I updated my question. – Saeed M. Apr 17 '16 at 17:54
  • can you for fun write http://example.com/public/images/someimage.jpg and see what happen – Maytham Fahmi Apr 17 '16 at 17:58
  • yes I did this before. I get `NotFoundHttpException in RouteCollection.php line 161` error – Saeed M. Apr 17 '16 at 18:10
  • I will get back Soon I am out now, – Maytham Fahmi Apr 17 '16 at 18:28
  • What does your `route.php` file look like? – Lloyd Banks Apr 17 '16 at 18:53
  • I am back now, yes please how does your `route` looks like? since exception comes from Laravel that means Laravel is responding to the link but it is not well defined in route. this is a typical scenario with Laravel hosted solutions. – Maytham Fahmi Apr 17 '16 at 19:02
  • you know its a weird situation. Old images show correctly but every images that I try to upload by Laravel, have permission denied problem. Uploaded images by ftp don't have problem and show. I'm confused. what do you think? – Saeed M. Apr 18 '16 at 15:18
  • @maytham-ɯɐɥʇʎɐɯ : please check updated question ! – Saeed M. Apr 18 '16 at 17:47
  • Ok the problem is very clear, it is a typicall problem with shared hosts, I think you need to look at this http://stackoverflow.com/questions/16683046/how-to-install-laravel-4-to-a-web-host-subfolder-without-publicly-exposing-app it is for Laravel 4 but that will give you some idea what the problem is, another solution is to switch to VPS at places like DigitalOcean for 5 dollar a month works fast and good for Laravel. – Maytham Fahmi Apr 18 '16 at 19:39
  • https://laracasts.com/discuss/channels/general-discussion/l5-on-shared-hosting – Maytham Fahmi Apr 18 '16 at 19:40
  • @maytham-ɯɐɥʇʎɐɯ: thanks man. I found the problem. check my answer. – Saeed M. Apr 20 '16 at 11:07
  • no problem, thump up for hardwork and good luck – Maytham Fahmi Apr 20 '16 at 11:14

1 Answers1

1

OK

I finally found the problem.

If you use PHP Selector in cPanel or maybe you used the following .htaccess code :

AddType application/x-httpd-php56 php56
AddHandler application/x-httpd-php56  .php

and you selected PHP 5.6 maybe you have this problem.

just change PHP version to 5.5 by htaccess :

AddType application/x-httpd-php56 php55
AddHandler application/x-httpd-php55  .php

or change your shared host. I don't know why this problem occurred, but when I change my PHP version my problem solved.

Saeed M.
  • 2,216
  • 4
  • 23
  • 47