Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Rook's avatar
Level 1

Configuring laravel app for production

Hi everyone. I've recently encountered problems trying to deploy my laravel app to production-like server. So far I've been using it in homestead environment and everything was just fine.

My .env contains something like this:

APP_URL=http://public.server.url
DB_CONNECTION=mysql 
DB_HOST=localhost 
DB_PORT=3306 
DB_DATABASE=homestead 
DB_USERNAME=myusername 
DB_PASSWORD=mypassword

In mysql (running on port 3306) I've set up user 'myusername'@'localhost' with mypassword and indeed I can connect using

mysql -u myusername -p

Even 'php artisan migrate' command works and modifies my database properly.

config/database.php

'mysql' => [
        'driver' => 'mysql',
        'host' => env('DB_HOST', '127.0.0.1'),
        'port' => env('DB_PORT', '3306'),
        'database' => env('DB_DATABASE', 'homestead'),
        'username' => env('DB_USERNAME', 'myusername'),
        'password' => env('DB_PASSWORD', 'mypassword'),
        //'unix_socket' => env('DB_SOCKET', ''),
        'charset' => 'utf8mb4',
        'collation' => 'utf8mb4_unicode_ci',
        'prefix' => '',
        'strict' => true,
        'engine' => null,
    ],

Problem is my http controllers don't behave correctly. I am getting 500 server error when sending requests on my routes (no matter how dummy logic they do) and 404 not found when trying to reach non-existing route. Also nothing is appended in the log file. So I am guessing as far as registering routes my app works, but right after that it fails. Any suggestions? I would really appreciate any tips.

EDIT: I am running on apache2, which I've configured to serve /public folder of my project on port 80. I've also enabled rewrite so apache can use prepared .htaccess file. The output can be seen on http://swinpro.fit.cvut.cz

Apache error.log

[Wed Apr 19 21:40:17.497080 2017] [:error] [pid 16377] [client 94.230.146.225:53046] PHP Fatal error:  Uncaught UnexpectedValueException: The stream or file "/home/kosvape1/Outcast/storage/logs/laravel.log" could not be opened: failed to open stream: Permission denied in /home/kosvape1/Outcast/vendor/monolog/monolog/src/Monolog/Handler/StreamHandler.php:107\n

SOLVED: Following the error log from apache, I remembered reading something about write permissions into storage and bootstrap/cache folders. I managed to grant apache write permissions to these folders and voila, problems solved.

Thank for being helpful guys :)

0 likes
3 replies
Screenbeetle's avatar

Evening

What's your server set up? And how did you deploy?

If you add ``` before and after your code it will format it nicely (and you'll get more responses :-)

2 likes
moyvera's avatar

Please share more information, like the current structure of your URL's, type of server, etc. Valuable information to help you.

1 like
Rook's avatar
Level 1

Thanks for replies, I added some server info, apache error log and formatting :)

Please or to participate in this conversation.