earmsby's avatar

How to add image to storage on Forge server

This is probably a dumb question:

I have a Filament table with a column like this:

ImageColumn::make('head_shot')
                    ->label('')
                    ->disk('public')
                    ->visibility('public')
                    ->defaultImageUrl(url('storage/authors/default_avatar.png'))
                    ->circular(),

On my local server (Herd), I just added the file default_avatar.png to the storage/authors directory and all is working. Now I'm ready to push my new column to the app on my Forge server. Of course, the storage directory is ignored by version control in my IDE. So, how do I get the default_avatar.png file to the storage/authors directory on Forge? Can I just upload it via SFTP or something?

0 likes
1 reply
LaryAI's avatar
LaryAI
AI
Best Answer
Level 58

Absolutely, this is a common scenario when deploying to production servers like those managed by Laravel Forge!

Here's how you can handle it:

1. Manually Upload via SFTP/SSH

Yes, you can simply upload the default_avatar.png via SFTP or SSH directly to the storage directory on your Forge server.

Steps:

  1. Connect to your server via SFTP or SSH.
  2. Navigate to your Laravel project directory, then go to storage/app/public/authors/.
  3. Upload your default_avatar.png file into that directory.

Note: If the authors folder does not exist, create it first.

2. Ensure Proper Symbolic Link

Make sure you've run:

php artisan storage:link

on your production server. This will ensure that the public/storage symbolic link points to storage/app/public and your images are served correctly.

3. Set Correct Permissions

Depending on your server configuration, ensure the uploaded file has the correct file permissions so that the web server can serve it:

chmod 664 storage/app/public/authors/default_avatar.png

(or use chmod -R 775 storage for broader coverage)

4. (Optional) Automate during Deployment

For repeated deployments, you can add a deployment script/step (in Forge or your CI pipeline) to copy this image into place.

5. Alternative: Keep in Public Directory

If you don't mind the image being truly public and not managed via Laravel's storage system, you could place default_avatar.png in public/images/authors/ and set your path accordingly.


Summary:
Yes, uploading the file via SFTP/SSH is the quickest solution for occasional/single files not managed in version control. Make sure the storage symlink exists and permissions are correct.

Let me know if you need code examples or more automated approaches!

Please or to participate in this conversation.