Laravel env file is not loading - php

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.

Maybe you could try to clear config cache:
php artisan config:clear

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.

Have you tried this-
Copied from the official Documentation
After installing Laravel, you may need to configure some permissions. Directories within the storage and the bootstrap/cache directories should be writable by your web server or Laravel will not run. If you are using the Homestead virtual machine, these permissions should already be set.

Related

Laravel running on an existing Ubuntu Web Server

So I am setting up a laravel project on my existing Ubuntu Dev server. (So I won't need to run php artisan serve)
I managed to make it work by renaming server.php to index.php and copied the htaccess from public to project root.
However I am concerned if this might create a security issue? Is there a better way how to do this?
I believe This would also apply once the app is deployed to a live server.
Any feedback would be appreciated!
EDIT:
This is for development environment only as in my /var/www I have other projects not related to laravel and cannot change apache's virtual host to point to this laravel project. (Basically I need to run laravel in a subdirectory)

Lumen Artisan Issue: No memcached servers added

I have just begun to work in a working project. I was trying to mount a docker-compose set of servers for DB, Lumen, and more. When I try some command involving artisan (just like php artisan --versionor php artisan migrate) I get the error message:
No memcached servers added
Well, then I go to Laravel docs to see how memcached cache driver works and it says that this is configured in config/cache.php. Well, this project has no cache.php file. In the other hand, the .env file does not contain CACHE_DRIVER environment variable.
I tried mounting a memcached server dockerized, but still same error. Where can I configure the memcached server nor socket in the project if I don have any configuration related to memcached???
Could this be happening 'cause Laravel finds no cache configuration and it selects any driver with no configuration?
Finally I could reach the solution by myself. Thanks everybody for watching.
When a Lumen project has no .env file configuration files gets some strange configurations. In this case was using memcached as server driver.
Solution: Create a .env file and set the cache driver.

Laravel 5.3. How to configure a production environment?

I got started with Laravel 5.3 and I got my development environment working on local, but now I need to upload the app to production server. I cant found nothing about configuring two environments on same app.
I use Apache web server on both (local and production).
Any guide/doc is well received!
The docs (as pointed by Marcin) suggest to use the .env file to configure your environment. Different environments = different .env files. Thus, on local machine you'd have an .env file with your local enviroment configuration, and on production you'd have a different .env file, and a diffrent one for staging, and so on... APP_ENV=production
Which can be brought forth with App::environment()
Remember to exclude the .env from versioning, cheers.
Better to follow this blog:
https://devmarketer.io/learn/deploy-laravel-5-app-lemp-stack-ubuntu-nginx/
With that blog, if you're not using Nginx but Apache, that's fine because we are more concerned with the Laravel configuration and permissionings on files and folders than the web server.

Laravel5 deployment share env variables between both CLI and web server

I am deploying a Laravel app and a part of my build script is to run ./artisan migrate. While I can pass environment variables to web server by adding them to nginx site config in sites-available, they for obvious reasons do not get shared with CLI.
Is there a way to include the same env variables to both web server and CLI to use? I tried adding a config file with values to /etc/php/7.0/fpm/pool.d/ but it did not work.
My /etc/php/7.0/fpm/pool.d/env.conf
[env]
env[APP_ENV] = production
As far as I know, you need to create same file in /etc/php/7.0/cli/pool.d/env.conf or make symlink.
We assume, php-cli is installed.

Uploading Laravel 5 Project to Shared Hosting

I want to deploy a Laravel 5 project to shared hosting from my localhost but I am facing so many problems. I have uploaded all files in a subfolder of my shared hosting (PHP 5.5) and when I try http://domain.com/subfolder/public its showing me 500 error. I check the laravel.log but found nothing, set the storage/ to 777 but still no changed (showing last error from localhost).
I also check .htaccess and it seems good. I search a lot and try so many thing but still facing same problem.
Now, my shared hosting give access of SSH so I have installed a new Laravel project. Then copy my edited and added file except vendor from my localhost to Hosting. Then I update the composer and dump-autoload, Now my application is working file.
But I am not sure about the process I did. Is it the right way (I don't think so)? Please let me know what was the problem of directly uploaded file and is there any problem if I use second system for my production app.
There are chances that your route cache is messed up. It is safe to artisan route:clear, artisan cache:clear, and artisan view:clear before uploading your files to ensure that no compiled script left - which usually tied to specific path.
But it is unclear, could you share your stacktrace for your error (and if possible share where your .htaccess file and it's content)?
sorry i can't comment, need higher point. However, by looking at your statement that it works by moving your files (controller, views, public, etc) but not the entire project, i believe clearing caches is the best to try.
As for the deployment of laravel project, there are methods suggested in laravel.io. It is not a good idea to expose your entire laravel files in public folder. Nevertheless, there are many ways to deploy it.
I know it's a little late but you need to either:
1. Make laravel's public folder the root folder of your domain or
2. Make a sub-domain and point the root folder to your projects public folder. The disadvantage with this is that your sessions cannot be connected directly to your main domain's sessions.

Categories