Search code examples
phplaravelserverlaravel-5.3production-environment

Laravel env file is not loading


I have moved my laravel project from local to production server which is centos vps. Strange thing I'm facing is laravel can't read from .env file, And I have tested everything to make it work but no success.

I have set it's permission to 777 and it's owner to the owner of vps.

still no success.

FYI : it is in gitignore but I have created .env file on server so this problem has nothing to do with gitignore.

Can someone walk me through step by step running laravel on production server? Exactly what should be done and what commands do I need to execute, where should I put project and where should put public directory files ?

please help me out.


Solution

  • In production environments you should never have a .env file. Instead, create the appropriate environment variables and PHP will read them from there.

    Taken from the official DotEnv docs:

    phpdotenv is made for development environments, and generally should not be used in production. In production, the actual environment variables should be set so that there is no overhead of loading the .env file on each request. This can be achieved via an automated deployment process with tools like Vagrant, chef, or Puppet, or can be set manually with cloud hosts like Pagodabox and Heroku.