Reputation: 12708
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:
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/public
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
Upvotes: 1
Views: 723
Reputation: 106
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:
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
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.
Upvotes: 3