images not found assetics load - symfony2 - php

I have cloned a Symfony2 project on my local machine.
I got it up and running but assets in my web/Resources folder won't load (be it images or json files).
I have noticed that after running assetic:dump the css and js files are placed into the web folder and can be accessed from my app at:
localhost:8000/localFolder/web/app_dev.php/css/725c7d7_inuit.min_1.css?version=4.22
I have tried to place my images in the web folder and in the web/Resources/public/images folder as suggested in the Symfony good practices. However when I try to access my image with this link:
​
http://localhost:8000/localFolder/web/Resources/public/images/phone-service/on-the-clock.jpg
it doesn't work.
Any idea ?

You should add your images file (same for css file and javascript file) in
Resources/public/images( same for css : Resources/public/css, js files: Resources/public/js) under your bundle.
Like this:
AppBundle/Resources/public/images
And run this command to generate resources in your web folder
php app/console assets:install
Note that you should run this command line after every modification in your public folder.
if you don't want to make this every time and attribute --symlink
php app/console assets:install --symlink

Related

Issue with Storage on shared hosting

I am deploying my first project on a shared hosting.
I followed this tutorial to deploy the website and turn the public folder into the public_html folder of my hosting plan.
When I upload an image from my website (with storeAs() method), the file is uploaded in the private/storage folder, not the public one (where I would like).
The asset() function try to display the image from public_html/storage.
What can I do ?
Thank you :)
My files are like this :
private/
- app/
- bootstrap/
- config/
- database/
- resources/
- routes/
- storage/
- tests/
- vendor/
public_html/
- css/
- js/
- images/
- js/
- storage/
(Laravel 8, trying to be hosted on Hostinger)
The tutorial : https://dev.to/pushpak1300/deploying-laravel7-app-on-shared-hosting-hostinger-31cj
Why does this problem happen?
If you implement and need storage matter in your project then you need to link storage folder to the public folder for security reason and to make the URL simple, clean and readable by the users, so when you upload the laravel project to a server, you need to run the following command line to complete the linking process:
php artisan storage:link
and since you host the laravel project to a shared server, so you don’t have access to a terminal to run the above-mentioned command line . so I’ll show you a way to do that manually without using SSH or the terminal.
Steps to fix the problem
1- At localhost server-side (before uploading the project to the server), make sure that you have done filesystem configuration, then run the following command line:
php artisan storage:link
after that you will get a message “The links have been created.” and that is ok for now.
2- Upload the project to the server, the storage link will not work as you expected, so we need to start fixing this.
3- Go to the public folder you will find a folder called “storage”, delete it.
4- Go to routes folder and open “web.php” file, then copy & paste the following code at the top of the file:
Route::get('/linkstorage', function () {
Artisan::call('storage:link') // this will do the command line job
});
Don’t forget to save the changes.
Also, you can do the same process via “api.php” and using requests tools like postman.
5- Now we just need to run this code, so we need to do the GET request by entering the following URL at browser search bar:
“https://www.your-domain.com/public/index.php/linkstorage”
or
“https://www.your-domain.com/public/linkstorage”
this request will run the above code “Artisan::call('storage:link')” which is, in turn, will run the command line
PHP artisan storage: link
now you can go to the public folder and you will see the “storage” folder created again and marked as a shortcut folder and that means the public storage folder now is linked to the storage folder of the project.
6- Now if you upload or create a file to the storage folder, then it will appear in the public/storage folder too, now you can hit the URL of the file at the search bar of the browser and you will get the file successfully :).
Ok guys i found the solution !
Here is how to deploy your Laravel project on one shared hosting using public_html folder : https://dev.to/pushpak1300/deploying-laravel7-app-on-shared-hosting-hostinger-31cj
This will work but you can have a problem (like me) with the storeAs() method if you deal with file uploads.
To solve this problem, I edited the MyProject/config/filesystem.php by adding this in the available disks :
'public_folder' => [
'driver' => 'local',
'root' => 'PATH',
'url' => env('APP_URL').'/storage',
'visibility' => 'public',
]
Replace PATH with the complete path to your public storage (for example /home/you/domains/mydomain.com/public_html/storage/).
Now, open the controller which manage file upload and edit it like this :
request()->image->storeAs('/uploads', 'filename.png', 'public_folder');
This will upload the request()->image in public_html/storage/uploads/filename.png.
I hope it will help you if you had the same problem as me.

Laravel Storage Linking is not working using symlinks command

I have uploaded my Laravel Web application to my server and tried to run the symlinks command but the media/images are not syncing. Anyone here can help me how to fix the storage issue?
here is my symlinks command :
<?php symlink('/home/webcxsol/shog/storage/app/public','/home/webcxsol/public_html/storage'); ?>
My public folder is in the public_html folder of the server and all the other files are in the other folder.
If you are or wish to follow the framework conventions, there is a specific command for this which you could take a look at using: php artisan storage:link.

Yii2 MINIMIZING THE ASSETS IN YII 2 FRAMEWORK

I am trying to minimize the assets in yii2 test project, but with no result. I used this tutorial: https://www.dunebook.com/how-to-minimize-the-assets-in-yii-2-framework/2/. I use openserver. In assets directory I created a file named compression. In that file I put yuicompressor.jar(YUI compressor) and compiler.jar(Google Closure compiler). After that, I tried to create configuration file for the compressor
running this command in the openserver console(being in the project root):
$ ./yii asset/template assets/compression/config.php. But here I get the following error:
"$" Is not internal or external
Command, executable program or batch file.
Please help with this!

How to use the css and js file from the vendor folder in Symfony 3?

I'd like to involve jQuery Smart Wizard in my application.
I have update the composer.json and then run composer update.
Here I get the related files in the vendor folder as techlab\smartwizard.
How could I link the css and js file from the twig template?
I have tried to use below command to generate link to the resources.
php bin\console assets:install --symlink --relative
It seems that the command only deal with the folder in resources\Public in each Bundle.
I hope I could use some link as below to get the files.
<link rel="stylesheet" href="{{ asset('bundles/XXX/static//styles/XXX.css') }}">
I know I could create CSS and JS folder under web folder and then copy the related files there. I just wonder if I have to do this manually then why I use composer to install it. I could just download the file and put them in the target folder. That's all.
I am not sure if there is some better way to manage the resource.
Thank you very much for your help.
assets:install command works only if it finds directories/files in Resources/public directory.
I see two options here:
1) create a bundle and add the files in the Resources public directory
2) use bower and install this package as a dependency for frontend.
For this, you may create a `.bowerrc` file to set the
target directory which can be `web/bower`.
Composer is used to manage php dependencies, not frontend ones, except somebody made a package to work with composer and to be integrated in framework.
So, you can use:
1) composer -> php related, backend dependencies
2) bower, npm -> frontend dependencies
I use a precompiler with gulp that manages css, images and js files in the project
Try
php bin\console
To
php bin/console
Where in your command line

Copying Assets to Web root folder instead of Web/Bundles

I have Symfony project in which i want to copy images to web folder. So I used bellow command.
php app/console assets:install web
It copy all images to Web/bundles/framework. I want all images in Web root folder.
Please suggest me how can i change the path to store all images or assets to root folder of web instead of storing in bundles.
You cannot do that, because the default bundles/ directory is hardcoded in the source code:
Symfony\Bundle\FrameworkBundle\Command\AssetsInstallCommand - Line 83
$bundlesDir = $targetArg.'/bundles/';
So I suggest either sticking to that convention or submitting a PR to the Symfony core repository to parametrize this directory.

Categories