Laravel cannot find public dir - php

I worked on a team and then clone the laravel/php codes from our repository. When I serve the laravel on localhost, it cannot find all the file inside the public directory and throw an error on the terminal:
[404]: GET /public/css/style.css - No such file or directory
Many answers to similar issues advise me to change the codes in the blade.php file. The problem is that I can't edit the blade.php because it works fine on other team members even though we have the same ubuntu, PHP, and laravel version and .env file.
What I have tried:
Run composer install and composer update
Try different browsers such as firefox and chromium-based browsers
Run php artisan storage:link
Restart apache2
Run npm install and npm run dev
I think there is some package or something missing.
List of paths I get from dd($__data):
"path" => "/project-directory/project-name/app"
"path.base" => "/project-directory/project-name"
"path.lang" => "/project-directory/project-name/resources/lang"
"path.config" => "/project-directory/project-name/config"
"path.public" => "/project-directory/project-name/public"
"path.storage" => "/project-directory/project-name/storage"
"path.database" => "/project-directory/project-name/database"
"path.resources" => "/project-directory/project-name/resources"
"path.bootstrap" => "/project-directory/project-name/bootstrap"

Have you tried?
php artisan storage:link

You need first run
php artisan storage:link
For more details check https://laravel.com/docs/8.x/filesystem
Then you must be check your .env values.
Is correctly APP_URL=
Also in your exception is strange
/public/.../...
Reason is wrong configuration.
First check your .env values like
APP_URL=...
FILESYSTEM_DRIVER=public
then check config/filesystems.php

Related

Deploy Laravel 6 App on Google App Engine Standard Error: Please provide a valid cache path

I've been trying to deploy my Laravel 6 App to the standard environment of Google App Engine the whole day, but seems like I'm just stuck at how to make cache and some "local" files to work.
This is the error I get when I try to load any page:
(1/1) InvalidArgumentException
Please provide a valid cache path.
in Compiler.php line 36
at Compiler->__construct(object(Filesystem), false)
in ViewServiceProvider.php line 92
at ViewServiceProvider->Illuminate\View\{closure}(object(Application), array())
in Container.php line 799
at Container->build(object(Closure))
in Container.php line 681
at Container->resolve('blade.compiler', array(), true)
in Application.php line 785
(...)
I followed every tip at this question, this tutorial and this issue, but anything seemed to help me.
As CACHE_DRIVER, for convenience, I'm trying to just use file, instead of database or any other else. So, my app.yaml, have the additional env_variables :
CACHE_DRIVER: file
SESSION_DRIVER: cookie
APP_STORAGE: /tmp
VIEW_COMPILED_PATH: /tmp
APP_SERVICES_CACHE: /tmp/services.php
APP_PACKAGES_CACHE: /tmp/packages.php
APP_CONFIG_CACHE: /tmp/config.php
APP_ROUTES_CACHE: /tmp/routes.php
I know that the /tmp folder is the only writable folder for the App Engine Standard Environment. With that in mind, I put the above at app.yaml, and even tried renaming /storage folder to /tmp.
I've added the following line to my bootstrap/app.php file:
$app->useStoragePath(env('APP_STORAGE', base_path() . '/tmp'));
At my composer packages, I made sure that it doesn't have facade/ignition. Also, as I can't run any command after deploy my app to Google App Engine, at composer.json I have:
"post-autoload-dump": [
"Illuminate\\Foundation\\ComposerScripts::postAutoloadDump"
],
"post-install-cmd": [
"composer dump-autoload",
"php artisan config:clear",
"php artisan view:clear",
"php artisan cache:clear"
]
I also tried to put at post-install-cmd php artisan storage:link, while using $app->useStoragePath(env('APP_STORAGE', base_path() . '/storage')); and the /storage folder as storage itself, but nothing worked.
I have the whole folder tree for caching at my /temp (or /storage, if this is the right way) folder:
/tmp
/framework
/cache
/data
/sessions
/testing
/views
/logs
/medialibrary
/temp
Also, besides the views not rendering, I noticed that when trying to load the favicon.ico, located at /public folder, it returns an 500 error. I am new to AppEngine, but even reading everything I can find I've been struggling to make it work. I really appreciate any help.
I figured out I had some config files published at /config, and besides changing /bootstrap/app.php, some of them had their own path to /storage folder. So, my solution was just gave up on using files cache, and for the views cache, and some other packages I had, use the path /tmp, at their respective config files. Also, I removed all cache cleaning artisan commands from composer, as I wasn't sending any cache files to deploy.
Also, I needed to make some changes in order to be able to access /public files, like some local css and js. For this, I followed these docs.
I was struggling with the same problem today and the solution was I changed the 'compiled' value in config/view.php to a root folder:
Go to root directory.
mkdir compiled_views
Change 'compiled' value to 'compiled' => realpath(base_path('compiled_views/')),
I solved it by explicitly adding the APP_STORAGE env in config/view.php:
'compiled' => realpath(env('APP_STORAGE', realpath(storage_path('framework/views')))),
(which surprises because I do have $app->useStoragePath(env('APP_STORAGE', base_path() . '/storage')); added to app.php - but it seems that it didn't yet(?) override storage_path )

env values from Linux not loaded by Laravel config app

Some time ago I asked about setting env settings and how to properly use them. I was quickly pointed to a comparable question and I found out that indeed it was bad practice to use env('KEY') throughout your code.
So now I am in the process of migrating my env settings to config/app.php.
However, if I play with Tinker, the env variables from Linux are not loaded by Laravel. For instance, if I place:
'test' => 'testing123',
within the config/app.php
and do a
sudo php artisan config:cache
and employ Tinker
config('app.test');
=> "testing123"
So that seems to work. However, if I place the following
'test' => env('DB_PORT'),
and do a
sudo php artisan config:cache
and test this with tinker:
config('app.test');
=> null
But when I am in the console and use:
env|grep DB_PORT
I see the right value for the DB_PORT key. I am supplying these in AWS frontend, these properties are then passed in the application as environment properties.
Anyone any idea why these are not imported/loaded correctly?
php artisan config:clear
Or you can just manually delete bootstrap/config.php, which is what artisan does after all.
See: vendor\laravel\framework\src\Illuminate\Foundation\Console\ConfigClearCommand.php

Continuous Integration and Development with Laravel

I'm new to Laravel, currently working on my first project. I have worked with CI before but never with Laravel. So, here's my deploy script for our Dev server. Not sure if this is the best approach. Anyway, the migrate part is giving me an error. After I get this to work I will try some php plugins to analyze code quality, duplication, unit tests, etc.
Please, see below
Script:
rsync -a . /var/www/html/dev/
cd /var/www/html/dev/
# cfg file for dev
cp .env.dev .env
# run composer
composer clearcache
composer install --optimize-autoloader
# optimize
php artisan cache:clear
php artisan optimize
php artisan route:cache | true
# migrate DB
php artisan migrate
Error:
[Illuminate\Database\QueryException]
SQLSTATE[42S01]: Base table or view already exists:
Am I supposed to delete all my tables before doing the migration? If so, I don't see what's the useful part of using them for auto deployment. Besides, we have our tables filled with data for testing (manually filled as we don't want to auto seed).
You shouldn't delete all your tables before run migration.
This error come from your migrations table and your migrations at database\migrations folder have conflict.
You should resolve this conflict before return to continue configure Jenkins.
My suggestion:
You should use Rocketeer for control release versions of your projects.
You can share your .env file by shared folder.
You can run composer install and npm install by default configure of Rocketeer.
Here is my steps install and configure Rocketeer:
Install Rocketeer:
$ wget http://rocketeer.autopergamene.eu/versions/rocketeer.phar
$ chmod +x rocketeer.phar
$ mv rocketeer.phar /usr/local/bin/rocketeer
//TODO Install PHP for Jenkins server
$ sudo apt-get install php
//TODO Check rocketeer
$ rocketeer check
No connections have been set, please create one: (production) <~ Succeed
Setup remote server information
$ cd /var/lib/jenkins/drone-deploy/drone-deploy/server-dev
$ rocketeer ignite
No connections have been set, please create one: (production)develop
No host is set for [develop], please provide one:35.166.x.x
No username is set for [develop], please provide one:ec2-user
No password or SSH key is set for [develop], which would you use? (key) [key/password]key
Please enter the full path to your key (/var/lib/jenkins/.ssh/id_rs/var/lib/jenkins/.ssh/xxx.pem
If a keyphrase is required, provide it
No repository is set for [repository], please provide one:git#bitbucket.org:xx/xxxxxx.git
No username is set for [repository], please provide one:xxx
No password is set for [repository], please provide one:
develop/0 | Ignite (Creates Rocketeer's configuration)
What is your application's name ? (drone-php)drone_deploy
The Rocketeer configuration was created at server-dev/.rocketeer
Configure
$ cd /var/lib/jenkins/drone-deploy/drone-deploy/drone-php
$ nano .rocketeer/config.php
Replace connections name production --> develop //It's Rocketeer bug
$ nano .rocketeer/remote.php
'root_directory' => '/var/www/html/',
'shared' => [
'storage/logs',
'storage/framework/sessions',
'.env',
],
'permissions' => [
// The folders and files to set as web writable
'files' => [
//'app/database/production.sqlite',
'bootstrap',
'storage',
'public',
],
// Here you can configure what actions will be executed to set
// permissions on the folder above. The Closure can return
// a single command as a string or an array of commands
'callback' => function ($task, $file) {
return [
sprintf('chmod -R 777 %s', $file),
sprintf('chmod -R g+s %s', $file),
sprintf('chown -R ec2-user:ec2-user %s', $file),
];
},
],
$ nano .rocketeer/strategies.php
//'test' => 'Phpunit',
'test' => '',
//return $composer->install([], ['--no-interaction' => null, '--no-dev' => null, '--prefer-dist' => null]);
return $composer->install([]);
Running test
rocketeer deploy --on="develop" --tests

Laravel looking for path on my localhost instead of deployed server

I have Laravel installed on my localhost. And when I try to deploy it to the server, it throws an error: View [frontend.layouts.login] not found.
And I can see that it is looking at my local file path when on my machine aka:
/Applications/MAMP/htdocs/personal/project_name/resources/views
Instead of the server's file path.
If I try and copy the project outside of the personal folder (on my local machine), so make the file path:
/Applications/MAMP/htdocs/project_name/resources/views
It gives the same issue?
Is it something with caching the views?
The other error on the same page is:
file_put_contents(/Applications/MAMP/htdocs/personal/project_name/storage/framework/sessions/7a0aaa6c977031111312b785c7b7e22a659b6a36): failed to open stream: No such file or directory
And again, the server has nothing to do with my local machine.
What could be going on?
This issue is due to the Laravel Configuration Caching.I suggest you
Remove the configuration cache file
Flush the application cache
Create a cache file for faster configuration loading
To do this, run the following Artisan commands on your command line
php artisan config:clear
php artisan cache:clear
php artisan config:cache
Where you don't have access to the command line on your server, you can programmatically execute commands like this:
Route::get('/clear-cache', function() {
$exitCode = Artisan::call('config:clear');
$exitCode = Artisan::call('cache:clear');
$exitCode = Artisan::call('config:cache');
return 'DONE'; //Return anything
});
I hope this is helpful.
I think this might fix it
Go to config/app.php
and change the url to your production url
'url' => 'http://localhost',
I had the same issue so i tried many things including all the solutions in this question, but it didn't work.
What worked for me is that i just deleted this file bootstrap/cache/config.php and it worked.

Laravel 5.2 not reading env file

After upgrading to Laravel 5.2, none of my .env file values are being read. I followed the upgrade instructions; none of my config files were changed except auth.php. They were all working fine in previous version, 5.1.19
.env contains values such as
DB_DATABASE=mydb
DB_USERNAME=myuser
config/database.php contains
'mysql' => [
'database' => env('DB_DATABASE', 'forge'),
'username' => env('DB_USERNAME', 'forge'),
]
I get this error:
PDOException: SQLSTATE[HY000] [1045] Access denied for user 'forge'#'localhost' (using password: NO)
Clearly not pulling in my env config. This is affecting every single one of my config files, including third party such as bugsnag.
I also tried
php artisan config:clear
php artisan cache:clear
Update
Trying php artisan tinker
>>> env('DB_DATABASE')
=> null
>>> getenv('DB_DATABASE')
=> false
>>> config('database.connections.mysql.database')
=> "forge"
>>> dd($_ENV)
[]
I have tried installing a fresh copy of Laravel 5.2. I basically only copied in my app folder; no additional composer packages are included. Still having the same issue. I have other Laravel 5.2 projects on the same server that are working fine.
If any of your .env variables contains white space, make sure you wrap them in double-quotes. For example:
SITE_NAME="My website"
Don't forget to clear your cache before testing:
php artisan config:cache
php artisan config:clear
From the official Laravel 5.2 Upgrade Notes:
If you are using the config:cache command during deployment, you
must make sure that you are only calling the env function from within
your configuration files, and not from anywhere else in your
application.
If you are calling env from within your application, it is strongly
recommended you add proper configuration values to your configuration
files and call env from that location instead, allowing you to convert
your env calls to config calls.
Reference: https://laravel.com/docs/5.2/upgrade#upgrade-5.2.0
For me it has worked this in this order:
php artisan config:cache
php artisan config:clear
php artisan cache:clear
And I've tried all the rests without luck.
Wow. Good grief. It's because I had an env value with a space in it, not surrounded by quotes
This
SITE_NAME=My website
Changed to this
SITE_NAME="My website"
Fixed it. I think this had to do with Laravel 5.2 now upgrading vlucas/phpdotenv from 1.1.1 to 2.1.0
I had a similar issue in my config/services.php and I solved using config clear and optimize commands:
php artisan config:clear
php artisan optimize
You can solve the problem by the following recommendation
Recommendation 1:
You have to use the .env file through configuration files, that means you are requrested to read the .env file from configuration files (such as /config/app.php or /config/database.php), then you can use the configuration files from any location of your project.
Recommendation 2: Set your env value within double quotation
GOOGLE_CLIENT_ID="887557629-9h6n4ne.apps.googleusercontent.com"
GOOGLE_CLIENT_SECRET="YT2ev2SpJt_Pa3dit60iFJ"
GOOGLE_MAP="AIzaSyCK6RWwql0DucT7Sl43w9ma-k8qU"
Recommendation 3: Maintain the following command sequence after changing any configuration or env value.
composer dump-autoload
composer dump-autoload -o
php artisan clear-compiled
php artisan optimize
php artisan route:clear
php artisan view:clear
php artisan cache:clear
php artisan config:cache
php artisan config:clear
Recommendation 4: When the syntax1 is not working then you can try another syntax2
$val1 = env('VARIABLE_NAME'); // syntax1
$val2 = getenv('VARIABLE_NAME'); // syntax2
echo 'systax1 value is:'.$val1.' & systax2 value is:'.$val2;
Recommendation 5: When your number of users is high/more then you have to increase the related memory size in the server configuration.
Recommendation 6: Set a default probable value when you are reading .env variable.
$googleClinetId=env("GOOGLE_CLIENT_ID","889159-9h6n95f1e.apps.googleusercontent.com");
$googleSecretId=env("GOOGLE_CLIENT_ID","YT2evBCt_Pa3dit60iFJ");
$googleMap=env("GOOGLE_MAP","AIzaSyCK6RUl0T7Sl43w9ma-k8qU");
I missed this in the upgrade instructions:
Add an env configuration option to your app.php configuration file that looks like the following:
'env' => env('APP_ENV', 'production')
Adding this line got the local .env file to be read in correctly.
I had the same issue on local environment, I resolved by
php artisan config:clear
php artisan config:cache
and then cancelling php artisan serve command, and restart again.
Same thing happens when :port is in your local .env
again the double quotes does the trick
APP_URL="http://localhost:8000"
and then
php artisan config:clear
Also additional to what #andrewtweber suggested make sure that you don't have spaces between the KEY= and the value unless it is between quotes
.env file e.g.:
...
SITE_NAME= My website
MAIL_PORT= 587
MAIL_FROM_NAME= websitename
...
to:
...
SITE_NAME="My website"
MAIL_PORT=587
MAIL_FROM_NAME=websitename
...
I solved this problem generating a new key using the command: php artisan key:generate
if you did call config:cache during local development, you can undo this by deleting the bootstrap/cache/config.php file. and this is work for me.
In my case laravel 5.7 env('APP_URL') not work but config('app.url') works. If I add new variable to env and to config - it not works - but after php artisan config:cache it start works.
if you did call config:cache during local development, you can undo this by deleting the bootstrap/cache/config.php file. and this is work for me.
#Payal Pandav has given the comment above.
I want to tell a simple workaround. Just edit the config.php file in the bootstrap/cache/ folder. And change the credentials. This worked for me. Please don't delete this file since this may contain other crucial data in the production environment.
I experienced this. Reason was that apache(user www-data) could not read .env due to file permissions.
So i changed the file permissions to ensure that the server (apache) had read permissions to the file. Just that and boom, it was all working now!
Update:How to do this varies, depending on who owns the .env file, but assuming it belongs to the Apache www-data group, you can do this:
sudo chmod g+r .env
Modify it depending on your permission structure.
In my case, I needed to restart my Supervisord jobs (i.e. my queue workers). After doing so, a new environment variable I had added to my .env file was successfully pulled into my application.
Remember, queue workers, are long-lived processes and store the booted application state in memory. As a result, they will not notice changes in your code base after they have been started. So, during your deployment process, be sure to restart your queue workers. In addition, remember that any static state created or modified by your application will not be automatically reset between jobs.
Source: Official Laravel Docs - Queues
I know this is super old, but today I discovered another reason why my .env was not loaded:
I had a (commited) .env.local
I recently switched APP_ENV from dev to local
With L8 (and maybe before), what happens is that it tries to find .env.<APP_ENV> and if it finds it, uses it.
Fun fact: in my case, .env.local was a blue-print file with non-sensitive information and not meant to be directly used, but that's what happened.
Removing the .env.local led to Laravel looking for .env instead.
In my case I was using VSCODE and it turned out my .env file was auto-dectected by the IDE as a shell script file and not an Ini which was causing me the issue. It's a rare occurrence, but I hope it will save someone time.
For Laravel coder. We can use config() to solve this problem
in file "config/app.php":
'same_url' => env('SAME_URL', 'http://localhost'),
in your code base:
$sameURL = config('app.same_url').'/orders/';
If you've come here because you have multiple .env.* files and php artisan config:cache resulted in incorrect settings, it's because it (tried to) read the .env file and not the one specific to your environment. Try this instead (where CODE corresponds to .env.CODE):
APP_ENV=CODE php artisan config:cache
I made the mistake by doing dd/die/dump in the index.php file. This causes the system to not regenerate the configs.
Just do dump in view files will do. The changes to .env file update instantly.
I had some problems with this.
It seemed to be a file permission issue somewhere in the app - not the .env-file.
I had to
- stop my docker
- use chown to set owning-rights to my own user for the whole project
- start docker again
This time it worked.
If you're using sail environment right after you change your environment variable just restart a server, otherwise it's going to show the old value.
In my case (Laravel 7.x) it happen because I had set environmental variable on server. To be precise in Docker container.
And because environments variables are higher priority than .env file, nothing changes during .env file edit.
Check if you set the env variable on the server:
echo $VAR_NAME
Tried almost all of the above. Ended up doing
chmod 666 .env
which worked. This problem seems to keep cropping up on the app I inherited however, this most recent time was after adding a .env.testing. Running Laravel 5.8

Categories