32

I'm trying Laravel for the first time after reading an announcement of the Laravel4 beta releasing.

I followed these steps I installed composer and laravel with all the dependencies it needed. I put the laravel inside my ~/public_html directory - as I'm used to do it with Codeigniter, but I think something's wrong here.

If I point to the browser to http://localhost/~carlo/laravel-develop/, it just displays the content of the directory.

Then, while on the filesystem I had a laravel-develop/public folder, it didn't appear on the browser.

I've found that changing the .htaccess like this:

<IfModule mod_rewrite.c> 
RewriteEngine on 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule ^(.*)$ index.php/$1 [L] 
</IfModule>

resulted in an error when I try to access the public folder. The error:

ErrorException: Warning: file_put_contents(/home/carlo/public_html/laravel-develop/app/config/../storage/meta/services.json): failed to open stream: Permission denied in /home/carlo/public_html/laravel-develop/vendor/laravel/framework/src/Illuminate/Filesystem/Filesystem.php line 77

another one:

/home/carlo/public_html/laravel-develop/vendor/laravel/framework/src/Illuminate/Filesystem/Filesystem.php line 77

then a long list of errors. The last one is:

require_once('/home/carlo/public_html/laravel-develop/start.php') in /home/carlo/public_html/laravel-develop/public/index.php line 53

Laurence
  • 58,936
  • 21
  • 171
  • 212
Carlo
  • 4,016
  • 7
  • 44
  • 65

14 Answers14

70

Try to change the folder permissions for the storage folder using the terminal:

chmod -R 777 storage

More info on this matter can be found here.

adridev
  • 1,150
  • 10
  • 15
16

Your errors resulted because laravel couldn't write to the app/storage folder. The rest was just a stack trace. In order to make the storage folder writable, cd into your app folder and then run:

chmod -R 777 storage
girlcode
  • 3,155
  • 5
  • 27
  • 41
  • I don't think it's a matter of permissions since when I point the browser to `http://localhost/~carlo/laravel-develop/` the `public` directory doesn't even appear in the directory tree. I changed the permissions anyway, as you suggested, but it didn't work. – Carlo Jan 16 '13 at 09:09
  • Then you probably put that .htaccess in the root folder, which is why it's not displaying the public folder... .htaccess goes in the public directory. – girlcode Jan 16 '13 at 15:02
  • 1
    755 won't make the directory writable for the web server as you have RWX RX RX but you need RWX on each so `chmod -R 777 storage` – Gazzer Apr 02 '13 at 09:13
11

Production way, moderate complexity for people not familiar with Unix, but more secure:

  1. Go in super user mode (sudo -s or su).
  2. Create group web (groupadd web)
  3. Add you main user to group web (suppose your user is cool_user, so run usermod -a -G web cool_user)
  4. Add php-fpm or web server user (if php is used as a SAPI module) to web group (for example, on CentOS php-fpm utilize apache user name, so in most cases this will work: usermod -a -G web apache)
  5. Change your project root directory group owner to web recursively (chgrp -R web /path/to/project/root/)
  6. Grant recursively write permission for group (chmod -R g+w /path/to/project/root/
  7. Optionally To allow all newly created by apache (or some other) user files and folders be accessible from your user, make them receive group ownership same as their parent folder by setting groupid bit recursively on your project root directory (chmod -R g+s /path/to/project/root/).

Voila!.

Fast and dirty way, for those who doesn't care about security and want make it works at any cost, not secure:

  1. Go in super user mode (sudo -s or su).
  2. Grant recursively full permission (read, write, execute) for all users (chmod -R o=rwx /path/to/project/root/
verheesj
  • 1,438
  • 2
  • 16
  • 24
pinepain
  • 12,453
  • 3
  • 60
  • 65
5

In my case I resolved this error by modifying in file /app/config/app.php the default setting:

'url' => 'http://localhost',

to my local custom virtualhost host url:

'url' => 'http://mydomain.local',

This seemed to be THE essential change that resolved the issue (I also chmod'ed the storage folder, as suggested here)

hope this helps some of you..

user2316785
  • 51
  • 1
  • 1
3

further to above, if you're using a virtualbox/vagrant VM type environment, then on my Mac I needed to issue the chmod on the host (mac) system but on my Windows box, it was fine issuing the chmod direcly on the VM.

jacanterbury
  • 1,435
  • 1
  • 26
  • 36
2

You need to add: Options +FollowSymLinks

<IfModule mod_rewrite.c> 
RewriteEngine on 
Options +FollowSymLinks
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule ^(.*)$ index.php/$1 [L] 
</IfModule>
  • now it just gives me a 500 error: Internal Server Error The server encountered an internal error or misconfiguration and was unable to complete your request. – Carlo Jan 15 '13 at 20:39
2

You need to read the installation documentation:

http://laravel.com/docs/installation#configuration

Pay attention to the bit here:

Laravel requires one set of permissions to be configured - folders within app/storage require write access by the web server.

There is also other stuff thats useful in that document, so make sure you read it all.

verheesj
  • 1,438
  • 2
  • 16
  • 24
Relaxing In Cyprus
  • 1,976
  • 19
  • 25
2

I had the same problem, here is how I solve it: In your httpd-vhosts.conf files you need to add the configurations to your folders, this is what I have in mine

<VirtualHost *:80>
    ServerAdmin your@mail.com
    DocumentRoot "/home/carlospublic_html"
    ServerName carlos.local
    <Directory "/home/carlos/public_html">
        Options Indexes FollowSymLinks MultiViews
        AllowOverride All
        Order allow,deny
        allow from all
    </Directory>
</VirtualHost>>
Flavio
  • 408
  • 4
  • 13
1

The webroot of your server should point to the /public folder of your Laravel installation. This is where the index.html file recides from where Laravel is initialized.

sidneydobber
  • 2,790
  • 1
  • 23
  • 32
0

First, this answer here will help you with permissions. Second, you may need to add RewriteBase ~/carlo/public_html/laravel-develop to your .htaccess since you're running it out of a home directory.

Community
  • 1
  • 1
ChrisMoll
  • 365
  • 1
  • 12
0

Hey I got this error too and changing the write permissions didn't seem to work either. It turned out I needed to change the User and Group settings in apache's httpd.conf file. Here's a good tutorial for it: Enable Write Permissions for the Native Built-In Apache in Mac OS X Lion

displayname
  • 43
  • 1
  • 7
0

Checking on the Requirement for the LR4, your local server must have these: PHP >= 5.3.7 MCrypt PHP Extension

Otherwise, will fail. I am facing this trouble also and now looking for an updated PHP and its extension for my XAMPP.

jsdecena
  • 572
  • 2
  • 7
  • 22
0

I like this method better than changing permissions to 777. Set Apache to run as you.

  1. In terminal type id to get uid=123(Myname).

  2. Open /etc/apache2/httpd.conf and edit it to use your username.

    <IfModule unixd_module>
       User Myname
       Group staff
    </IfModule>
    
  3. Back to terminal: sudo apachectl restart

Justin
  • 26,443
  • 16
  • 111
  • 128
-1

I ran into this problem a few minutes back and using sudo chmod -R 777 storage seemed to help make the storage/meta/services.json writable. Just to add to what everyone has been saying. This worked for me.

Dammy
  • 7
  • 3
  • 4
    Glad to hear it worked, Dammy. However, if the other answers helped you, there's no need to post a duplicate - just upvote! – David Cain Jun 10 '13 at 22:07