megacolorboy

Abdush Shakoor's Weblog

Writings, experiments & ideas.

Symbolic storage link in shared hosting

If you're hosting a laravel project via cPanel, chances are that it could be a shared hosting server and that means you can't really use php artisan storage:link for this. But don't worry, there's another way to this. Just follow the steps below:

1. Create a symlink

In your public_html/public directory, remove the storage folder. Next, create a symlink.php file in your public_html directory and add the following code:

<?php
$targetFolder = $_SERVER['DOCUMENT_ROOT'].'/storage/app/public';
$linkedFolder = $_SERVER['DOCUMENT_ROOT'].'/public/storage';
symlink($targetFolder, $linkedFolder);
echo "done";
?>

2. Create a custom route to access storage

Alright, this is kind of a hack but it works extremely fine. Just add the following route in your routes/web.php file:

<?php
Route::get('/storage/anyfolder/{filename}', function($filename){
    // Your folder path
    $folder_path = storage_path('app/public/anyfolder/'.$filename);

    // check if the file exists
    if(!File::exists($folder_path)) {
        abort(404);
    }

    $file = File::get($folder_path);
    $type = File::mimeType($folder_path);

    $response = Response::make($file, 200);
    $response->header("Content-Type", $type);

    return $response;
})
?>

Now, you can access your images or any other assets easily using:

<?php
asset('storage/anyfolder/'.$filename)
?>

Hope this helps you out!

View battery status

This comes in handy if you're using the terminal in full screen but still want to know your battery life. Just type the following:

upower -i /org/freedesktop/UPower/devices/battery_BAT0

View hardware info

Want to check the specs of your system? Just type this:

lshw

Too long? Then type this for a shorter version:

lshw -short

Zip a file

This comes in handy especially whenever you want to download multiples files from a server or take backups.

zip [option] output_file input1 input2

For example: if you want to zip an entire directory with it's file contents, just do this:

zip -r myfiles.zip folder/