Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

torriv's avatar

Zero downtime deployment - symbolic link not working

hi,

I'm trying to get the symbolic link to work. using storage:link doesn't work, so i have to do it manually.

I can see that there is a storage folder in my public folder with a link, but when i try to click on it through my FTP client, i get "no such file or directory", and on my page it say 403 forbidden.

My folder structure is like this:

  • current (with a symbolic link to the lastes release, working!)
  • releases
    • random release number
      • all the app files
      • storage
      • public/storage

I have left out a lot of folders, but hope you get the idea.

I'm using buddy.works for deployment,

and here is the code being run at the end:

if [ -d "releases/$BUDDY_EXECUTION_REVISION" ] && [ "$BUDDY_EXECUTION_REFRESH" = "true" ];
then
 echo "Removing: releases/$BUDDY_EXECUTION_REVISION"
 rm -rf releases/$BUDDY_EXECUTION_REVISION;
fi
if [ ! -d "releases/$BUDDY_EXECUTION_REVISION" ];
then
 echo "Creating: releases/$BUDDY_EXECUTION_REVISION"
 cp -dR deploy-cache releases/$BUDDY_EXECUTION_REVISION;
fi
echo "Linking current to revision: $BUDDY_EXECUTION_REVISION"
rm -f current
ln -s releases/$BUDDY_EXECUTION_REVISION current
ln -s current/storage/app/public current/public/storage    <---- My attempt to make a symbolic link
echo "Removing old releases"
cd releases && ls -t | tail -n +11 | xargs rm -rf
cd $BUDDY_EXECUTION_REVISION
composer install -o --no-interaction
php artisan optimize
php artisan cache:clear
php artisan route:cache
php artisan view:clear
php artisan config:cache

If anyone know what's going on, please help! :)

Yes i have checked the permissions on my folders.

Thanks in advance

0 likes
9 replies
torriv's avatar

That didn't work. Should i put it in the htaccess file in the root or the one inside public folder?

sr57's avatar

That

What ?

Why do you want to modify your .htccess?

Please share :

  • server error logs

  • ls -la public

torriv's avatar

ls -la public:

drwxr-xr-x  4 u495-ruggxp3xpugw u495-ruggxp3xpugw 4096 Feb 17 05:19 .
drwxr-xr-x 14 u495-ruggxp3xpugw u495-ruggxp3xpugw 4096 Feb 17 03:59 ..
-rw-r--r--  1 u495-ruggxp3xpugw u495-ruggxp3xpugw  603 Feb 18 09:29 .htaccess
drwxr-xr-x  2 u495-ruggxp3xpugw u495-ruggxp3xpugw 4096 Feb 17 03:59 css
-rw-r--r--  1 u495-ruggxp3xpugw u495-ruggxp3xpugw    0 Feb 17 03:59 favicon.ico
-rw-r--r--  1 u495-ruggxp3xpugw u495-ruggxp3xpugw 1731 Feb 17 03:59 index.php
drwxr-xr-x  2 u495-ruggxp3xpugw u495-ruggxp3xpugw 4096 Feb 17 03:59 js
-rw-r--r--  1 u495-ruggxp3xpugw u495-ruggxp3xpugw   71 Feb 17 03:59 mix-manifest.json
-rw-r--r--  1 u495-ruggxp3xpugw u495-ruggxp3xpugw   24 Feb 17 03:59 robots.txt
lrwxrwxrwx  1 u495-ruggxp3xpugw u495-ruggxp3xpugw   26 Feb 17 05:19 storage -> current/storage/app/public
-rw-r--r--  1 u495-ruggxp3xpugw u495-ruggxp3xpugw 1194 Feb 17 03:59 web.config

server error logs:

2021-02-18 09:28:51 UTC [apache][core:error] [pid 23434] AH00037: Symbolic link not allowed or link target not accessible: /home/usernamehere/www/support1.riveraconsulting.no/public_html/current/public/storage, referer: https://support1.riveraconsulting.no/admin/dashboard
sr57's avatar

Same pb as the link posted, same solution put .htaccess in the root directory.

That said the pb is that apache user (standard www-data) has not the rights to access your file.

To see this, ssh to your server , su www-data , cd ...

To change : change owner or group access and make apache in the user group.

torriv's avatar

so, you mean, put the htaccess that now is in public folder, into root folder?

right now i have this htaccess file under public_html folder:


<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{HTTP_HOST} ^support1.riveraconsulting.no$ [NC,OR]
RewriteCond %{HTTP_HOST} ^https://support1.riveraconsulting.no$
RewriteCond %{REQUEST_URI} !^current/public/
RewriteRule (.*) /current/public/ [L]
</IfModule>

and this in under public folder:


<IfModule mod_rewrite.c>
    <IfModule mod_negotiation.c>
        Options -MultiViews -Indexes
    </IfModule>

    RewriteEngine On

    # Handle Authorization Header
    RewriteCond %{HTTP:Authorization} .
    RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]

    # Redirect Trailing Slashes If Not A Folder...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_URI} (.+)/$
    RewriteRule ^ %1 [L,R=301]

    # Send Requests To Front Controller...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^ index.php [L]
</IfModule>

sr57's avatar

As written in the link I send, you have only to add SymLinksIfOwnerMatch in your .htaccess root, try it (don't forget to restart apache) and if not work, add also in your public .htaccess

As written in the link too, It's not my prefer solution I have better to work with the standard owner or at least change group access.

torriv's avatar

well, that was my first respond to you. it doesn't work. (put the code in both htaccess files)

i also don't have access to restart any server, this is on siteground's servers. (shared hosting)

bare in mind that i also have another Laravel project on siteground, and it works fine. but there i don't have zero downtime deployment.

sr57's avatar

Forgot that point, I don't have simple solution without restarting apache

Please or to participate in this conversation.