laravel image optimizer file does not exists - php

I am using spatie/laravel-image-optimizer package to optimize my images.
I receive the error message:
storage/app/public/files/car/9/km_declaration/2022/uE5DMCYh6hCuQXrOZ4yOSLCtLEnNdsE9e9OriNVw.jpg does not exist
Although the file is there, and it can access it locally, in production it cannot find it.
I am using the optimizer as it supposted to be used, and I am using the filesystem public:
ImageOptimizer::optimize($this->url);
Do you have any guess why is it working locally with homestead but not on production?
(Folder permissions 755 on prod)
Update:
The code: ImageOptimizer::optimize($this->url); is run from a cron job.
If I do file_exists($url) from the controller I got true, but false from the job. I think that is the source of my issue.

In the storage folder, you need to set permissions 775
chmod -R 775 storage

Related

I get an error at first run of Yii1 application

i am new to Yii. I am trying to setup a yii 1 app and i get this error.
"Application runtime path "C:\xampp\htdocs\gfs_design\protected\runtime" is not valid. Please make sure it is a directory writable by the Web server process."
I am using Xampp and the frontend and the yii folders are in my htdocs directory.
What I Have Done:
I have made the Yii folder writable from properties\security\advanced and so on
But i still get the error.
Can any one help?
Runtime folder must have access to read write and also should be available for publically.
Please give permission to runtime folder
chmod -R 777 /path/to/project/protected/runtime
The first time the app is installed, it doesn't come with a runtime directory. Just creating the folder in protected helped.
Since runtime folder should be publicly accessible, just use the following commands to make the folder writable/readable from the web:
chown -R www-data:www-data /path/to/project/protected/runtime
chmod -R 777 /path/to/project/protected/runtime
Hope this helps.
EDIT:
JFYI, runtime directory is internally used by Yii framework to store some cached data, such as logs, session and assets.

Laravel: Writing to /.../.config/psysh is not allowed

I have installed a Laravel app locally using the Laravel Installer. Now I want to upload the app to my production server which is a managed virtual server, but it fulfills all the needed requirements.
I have uploaded the app and changed in the .env file the APP_URL and the DB_* settings accordingly. When I login to my server via ssh, go inside the app folder and try to use tinker
php artisan tinker
I get the following error message:
The error message makes sense, because the wp10*** folder does not contain a .config folder. However, I do not have permission to create folders at the same level as the www folder. Is it possible to put the folder inside the Laracast project folder? In my example this would be /is/htdocs/wp_10**/www/laracast/p1/.config/psysh. If so, how do I tell Laravel the new location?
If you can't give access to use the default directory,
You can change the directory path in .env file:
XDG_CONFIG_HOME=/home/some/directory
Thanks to bernhardh
Tinker is trying to create the .config folder, and it's not per-app configuration, it's stored against the user.
I don't think you can change the directory path, but creating the directory and setting permissions on it will allow you to use tinker.
mkdir -p ~/.config/psysh
chmod -R 755 ~/.config
It is worth double checking the user permissions before you try this, as you should always be able to write directly to your users home directory.
Or you can use :
sudo chmod -R 755 ~/.config
then make directory:
mkdir -p ~/.config/psysh
and :
php artisan tinker.
Verify that .config and psysh belong to your user, try changing the owner with chown and set the permissions to 700
I had the same issue on a Laravel 9 app running in a non-root Docker container.
I fixed it by creating the matching user inside of the container so that it gets a home directory. Then, Psysh was able to write its config in the user's home.
With that setup, no need to change any XDG_CONFIG_HOME or PSYSH_CONFIG vars.
Moreover, using those XDG_CONFIG_HOME or PSYSH_CONFIG env vars is irrelevant if you use Laravel config caching.
Try this
sudo chmod -R 777 ~/.config
If Directory is not exists
mkdir -p ~/.config/psysh
Then check again
php artisan tinker
if working with Laragon on windows you can try go to c drive then click on the user folder you are using then right click and then properties go to security and then click edit(all/everyone). Then check all the boxes so you are permitted to write to the file.how it looks here
Fixed! For Windows, run your terminal or app as an administrator.

Yii2 framework error

I'm new with framework and recently, i install yii2 on my computer, but then when i'm trying to test the frontend of yii2, it show this error. This is my first time using this, so i didn't know what is really the error is.
So, anybody can tell me what should i do to fixed the error and make the framework run on my computer successfully.
enter command line chmod -R 777 runtime in your folder where the framework itself is located. If you use an extended application, then in the root of the project it will be so сhmod -R 777 frontend/runtime
You have a problems with permissions. The runtime directory should have permissions set to 0777

premisson to working correctly laravel

I created a project with Laravel 4 but when I go to the folder localhost /my_project/public get some errors related to the permissions. I solved it setting to 777 all the permissions of the folder and files contained in my_project. Is there a way to solve this thing is not to make 777?
What's happen when you set 755 permission to my_project directory? Try to change permissions and check it. Your directory should be able to read all files in public directory.
I set my ownership to be owned by www-data:
chown -R auser:www-data /path/to/laravel/root
I also make all my subfolders and files read and write by group:
chmod -R g+rw /path/to/laravel/root
I also make my folders have a sticky bit so if you add a new file, it inherits:
chmod -R g+s /path/to/laravel/root
This has always worked for me. Perhaps Linux experts might have better ideas but this is what I use.
Please refer to Laravel's documentation about installation located at http://laravel.com/docs/installation. Under no circumstances you should run laravel on production with full permissions to the whole world. You must also remember that your "application" will be executed from the public directory so there is NO reason to allow read/write/execute for the whole world to the whole project directory unless you don't care about security at all.
Anyway, extracted from Laravel's documentation from the permissions section:
"Laravel may require one set of permissions to be configured: folders
within app/storage require write access by the web server."
This whould make your project run smooth.

symfony2 cache/log permission issues

I've just uploaded a simple symfony2 app on a production server, and I get this configuration error:
2 MAJOR PROBLEMS
Change the permissions of the "app/cache/" directory so that the web server can write into it.
Change the permissions of the "app/logs/" directory so that the web server can write into it.
editing "app/console", "web/app.php" and "web/app_dev.php" with: umask(0000) doesn't work, and if I right click on that folders with FileZIlla, their permissions are already 777. And so?
thanks...
You need to recursively set the permissions, most likely. I'm guessing FileZilla has that option, if not, ssh into the box, and run (replacing /path/to with the actual path)
sudo chmod 777 -R /path/to/app/cache
sudo chmod 777 -R /path/to/app/logs
Sidenote: setting the permissions to 777 is usually a really bad idea.
umask(0000) doesn't actually increase the permissions available to the script. It just ensures that files & directories created by those scripts are accessible from both the command line and the web server. If you're not using the command line, you probably don't need it at all.

Categories