1

I'm following this guide on setting up Laravel 5.1 on Ubuntu (LAMP stack) for Digital Ocean. When I try to access my Laravel app on the one-click droplet, I get:

enter image description here

I went through the steps of installing Composer then Laravel, and then placed ~/.composer/vendor/bin directory in my PATH "so the laravel executable can be located by your system."

root@phpmyadmin-512mb-nyc3-01:/# cat ~/.bashrc:

   echo 'export PATH="$PATH:$HOME/.composer/vendor/bin"' >> ~/.bashrc
   export PATH="$PATH:$HOME/.composer/vendor/bin"

Then follow this guide on changing my webroot so I can serve from /public like Laravel expects:

nano /etc/apache2/sites-enabled/000-default.conf

I change DocumentRoot /var/www/html/ to DocumentRoot /var/www/html/publicenter image description here

Then restarted sudo systemctl restart apache2

I cannot access my Laravel app. It gives a 500 error. Why is this?


PHP Fatal error: Uncaught UnexpectedValueException: The stream or file "/var/www/html/storage/logs/laravel-2017-05-17.log" could not be opened: failed to open stream: Permission denied in /var/www/html/vendor/monolog/monolog/src/Monolog/Handler/StreamHandler.php:107\nStack trace:\n#0 /var/www/html/vendor/monolog/monolog/src/Monolog/Handler/RotatingFileHandler.php(106): Monolog\Handler\StreamHandler->write(Array)\n#1 /var/www/html/vendor/monolog/monolog/src/Monolog/Handler/AbstractProcessingHandler.php(37): Monolog\Handler\RotatingFileHandler->write(Array)\n#2 /var/www/html/vendor/monolog/monolog/src/Monolog/Logger.php(336): Monolog\Handler\AbstractProcessingHandler->handle(Array)\n#3 /var/www/html/vendor/monolog/monolog/src/Monolog/Logger.php(615): Monolog\Logger->addRecord(400, Object(UnexpectedValueException), Array)\n#4 /var/www/html/vendor/laravel/framework/src/Illuminate/Log/Writer.php(202): Monolog\Logger->error(Object(UnexpectedValueException), Array)\n#5 /var/www/html/vendor/laravel/framework/src/Illuminate/Log/Writer.php(11 in /var/www/html/vendor/monolog/monolog/src/Monolog/Handler/StreamHandler.php on line 107

11
  • 1
    i think you may have not change the permission of storage and bootstrap/cache directory. Commented May 17, 2017 at 6:50
  • @reza what do I need to change it to? cat'ing the file shows that it's empty. Commented May 17, 2017 at 6:54
  • give this directory write permission. check Directory Permissions section in the following link laravel.com/docs/5.4/installation Commented May 17, 2017 at 6:56
  • @reza I'm on Laravel 5.1, not 5.4. Does that matter? Commented May 17, 2017 at 6:57
  • sudo chown -R :www-data /var/www/laravel & sudo chmod -R 775 /var/www/laravel/storage - where laravel is your project name. Also, please add your log files for 500 error. Commented May 17, 2017 at 6:57

1 Answer 1

3

Do you have access to the error log of apache? (or, in case you've defined a custom log file, then check in there). A 500 error will typically leave an entry in the apache log file (/var/log/apache2/error.log) or your custom error log.

In case the error is a permissions issue in writing to "laravel.log", there can be multiple reasons:

  1. You haven't given write permissions to your storage or bootstrap/cache directories. Try that.

    cd /var/www/html/<projectname>
    chmod +777 -R storage
    chmod +777 -R bootstrap/cache
    

    You will need to be root to use chmod

  2. SELinux does not allow your http user to write to these files (for example, on CentOS). use the following commands from within your application's base directory (the directory that contains your 'app' folder, as well as storage and bootstrap folders:

    chcon -R -t httpd_sys_rw_content_t storage
    chcon -R -t httpd_sys_rw_content_t bootstrap/cache
    

In case its SELinux, and your application plans on connecting to MySQL as well, you will also need to run :

setsebool -P httpd_can_network_connect_db 1

This is to allow httpd to connect to database. Some locations may try to dissuade the usage of SELinux and tell you to turn it off as a whole, but that is not recommended.

Sign up to request clarification or add additional context in comments.

2 Comments

Error posted above
That is a permission issue, file "/var/www/html/storage/logs/laravel-2017-05-17.log" could not be opened: failed to open stream: Permission denied in /var/www/html/vendor/monolog/monolog/src/Monolog/Handler/StreamHandler.php You should try the steps I've mentioned in my answer, that should solve the problem.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.