Create symlink manually - laravel

I am in shared hosting. I am facing the problem to display image from my storage. I can't access through ssh so can't create symlink with php artisan . Can anyone teach me how to create symlink manually>

Add this to the route file.
Route::get('example',function() {
Artisan::call('storage:link');
});
And visit the example.

Related

How to link public storage without ssh access or cron jobs?

I need to deploy a laravel app, which uses the storage folder as public storage but I don't have ssh access. I'm trying to find a substitute for:
php artisan storage:link
I've found this thread: Generating a link by putting this route into web.php:
Route::get('generate', function (){ \Illuminate\Support\Facades\Artisan::call('storage:link'); echo 'ok'; });
But it didn't solve the problem. Am I doing it wrong? How do I link public storage?
Edit: The shitty server I'm trying to deploy to doesn't offer cron jobs.
create a corn job if available and after the job run the first time. delete this
ln -s /home/user/laravel/storage/app/public /home/user/public_html/storage
The problem was that I didn't understand how to use the storage link route correctly. I had to add:
Route::get('/linkstorage', function (){
\Illuminate\Support\Facades\Artisan::call('storage:link');
echo 'storage linked!';
});
to web.php and actually navigate to domain-name/linkstorage to trigger the artisan call. After that the storage was linked and everything worked.

Symbolic link not working in Laravel and image not loading

My problem is that when I upload the archim with my site to the hosting and then unpack it there, I lose the symbolic link and the images stop working. How can this be fixed? Everything is fine on the local computer, and I use php artisan storage:link, but there is no terminal on the hosting.
If you have no ssh/terminal access, then create symbolic link with Route, run it once & delete it.
route/web.php :
Route::get('/sym', function () {
Artisan::call('storage:link');
});
Hope this helps
Well, if you have ssh access to the hosting, execute the command.
If you don't have ssh access, like basic hosting with cpanel, you need to configure a cronjob to execute the command. Example:
* * * * * /path/to/php /home/path/to/project/php artisan storage:link

how do i solve the image upload issue of laravel while hosting it on shared hosting?

i am using hostinger to deploy my laravel project i uploaded all the files into the public_html folder and then did all the necessary changes needed for the application to work.The app seems to work pretty fine but when an user tries to upload a image the image gets stored in the storage/app/public/avatar folder and on public/storage/avatar folder as i have used symlink to link the two folders but yet the photos cannot be viewed by the users. this is how i recall my photo
div class="profile-avatar" style="width: 400px;height:500px; border-radius: 0%;background-image: url('#if(Auth::user()->avatar == "avatar.png") {{ url("/imgs/".Auth::user()->avatar) }} #else {{ url("/storage/avatar/".Auth::user()->avatar) }} #endif');"
please help me to solve this issue
As you have no ssh access to run some command in shell,
try this when uploading the image
1. Store image here: public_path() . 'img/filename.jpg'*
2. Save the 'img/filename.jpg' in database
3. Generate the image URL with url('img/filename.jpg')
// Output http://www.your-domain.com/img/filename.jpg
If you can manage shell access then try this:
Remove your current app/public/avatar directory, which is created inside of storage folder.
Also remove your storage folder inside public !
After that via ssh cli, cd to your laravel project folder and create a symbolic link via following command
ln -sr storage public/storage
Hopefully it will solve your issue. I had same issue and mine got fixed via second method ( I had ssh access to my server ).

Laravel Symbolic Link not working

I have some problems creating a symbolic link with laravel to access files that are in my storage
I am storing my files in
storage\app\public
I used the php artisan command to create the link
php artisan storage: link
The [public/storage] directory has been linked.
Earlier files were storing in storage\app\public and were also visible in public\storage folder
But now they are only storing in storage\app\public and not visible in public\storage folder
I am using link to show file path
{{ Storage::url($package->reportPath['path']) }}
Path is showing correct but it redirect to 404 page as there is no file I guess.
This solved it for me on laravel 8, hosted on a ec2 server.
rm public/storage
php artisan optimize:clear
php artisan storage:link
Try removing your public/storage directory and try running storage:link again. This worked for me.
If you are trying to Show the stored file use asset()
asset('storage/further_path/').$file_name;
To store file you can do
$destinationPath = storage_path('app/public/further_path');
if (!is_dir($destinationPath)) {
mkdir($destinationPath, 0777, TRUE);
}
$request->file->move($destinationPath,$filename);
Hope this Helps You.
Let me Know if You have any problem.

How to run laravel 5.0 project on localhost without use php artisan serve

I have created a laravel 5.0 project with php artisan serve, now i need to know how to run laravel 5.0 project run without start php artisan serve, i have already browse lot of websites no one help me..
You need to change "server.php" to "index.php" then copy ".htaccess" from public to root directory.
See: https://stackoverflow.com/a/30053989/3948755
Laravel sever Folder is "public". There is an index.php so you can run you project from there.
Suppose if you using UbuntuOS then you have to create your local server in public directory. Suppose your folder name is laravel_test then go in that directory and run some thing like this
php -S localhost:8000 -t public
If you using windows then access public folder from URL.
localhost/laravel/public
Actually it's bad practise to access folder from URL but for local its good. You also can go with host entry. Just make sure that your target folder is "public" directory.
Normally you would have WAMP/XAMPP installed. You can access Laravel project like below
localhost/laravel/public
But this is not recommended. You should create Virtual host for example
laravel.local that pints to server-root/laravel/public.
this is how you create virtual host.
Or even better go for a Laravel Homestead .
How is your .htaccess file configured?
Try with localhost/laravel/public/index.php
Use http://localhost/projectName/public
It will be work. but in case if you have another Route and you can not access that Route and get the error like " Page Not Found " then please use the following command
sudo a2enmod rewrite
Now open the http://localhost/projectName/public/yourRoute
This is a little late but still applicable, what I like to do (using ubuntu 14.x+) is put my laravel project (let's say Project1) in my var directory, so it would be in /var/Project1, then symlink the public folder to somewhere in /var/www(+/html depending on apache version).
Symlink can be done something like this:
ln -s /var/Project1/public /var/www/html
This keeps your internal files off the grid so to speak, this is untested so if I've missed anything just comment and I will amend this post.
EDIT:
Obviously if your http root is /var/www/html you can put your project in /var/www/Project1
If you have access to xampp or wampp on your operating system you can more or less configure your virtual host like in the instruction below:
https://bestin-it.com/creating-virtualhost-on-your-local-computer-to-start-simple-index-php/
This instruction shows how to run it locally on your PC, but it works generally the same on any hosting portals. In most case in payed portals you have any web panels to configure your public folder that reference to /public folder in laravel folder's structure.

Resources