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

ccarstens's avatar

Need help with deployment scrip on managed server

Hey there,

I'm creating a laravel app and I'm at a point where I need help with my deployment script. The app should be deployed on a managed server, the client wants that.

My deployment script works so far but is rather messy.

  1. I make save my public folder under a different name
  2. I pull my git repo and then create a symlink with 'ln -s' to the entry point within the web root.
  3. I copy the files from the renamed public folder to the symlink folder
  4. I adjust the require paths in public/index.php to reflect the just created structure

All of that is an ok thing to do (I guess?) but the just performed changes are unstaged changes when I try to deploy next. So what I do before the four mentioned steps is to remove the created public folder and to just stash away the created changes with 'git stash save --keep-index'.

Is this best practice? Is there a better way of doing it? Somehow it feels very messy and un-laravel.

Here is my script (didn't use the Envoy task runner yet):

#!/bin/sh
rm public
rm -r public_bak

git stash save --keep-index
git pull "https://USER@REPOSITORY" dev

mv public public_bak
ln -s ~/public_html/entry public
cp -a public_bak/* public/
cp public_bak/.htaccess public/

sed -i "s/__DIR__\.'\/../'\/usr\/MY\/DEPLOYMENT\/PATH/g" public/index.php

php -d allow_url_fopen=On composer.phar install
php -d allow_url_fopen=On composer.phar dumpautoload -o
php artisan config:cache
php artisan route:cache

Thank you for taking the time and helping me! Best ccarstens

0 likes
0 replies

Please or to participate in this conversation.