Automate your laravel project deployments to shared hosting
Learn about ftp-uploader and how to use
I have been struggling to find a suitable tool for deploying my Laravel application to shared hosting with FTP access, and I wanted to practice writing Golang applications.
I also didn't want to upload my entire git repository. There was no need to upload markdown files, deployment scripts, etc., to the FTP servers. Therefore, the tool needed some sort of file/directory exclusion logic.
In my quick search I found the go-gitignore package, that perfectly matched my requirements.
I wanted to easily use this tool inside my CI/CD pipelines and safely upload files locally, so I decided to create a CLI application.
How ftp-uploader works?
At its core, uploads files and runs a file path check with gitignore-like exclusion logic. It is primarily designed for CI/CD pipelines and has a Docker image if you need it.
ftp-uploader
How to install ftp-uploader?
Currently the tool is available only for Linux, I believe it should work on Mac without problems but I haven’t tested it on it. If you want to use it on Mac or Windows you will have to compile it from source, but let me know if you need this tool on these platforms, I will create binaries for them.
You can install ftp-uploader with the following commands:
sudo curl -fsSL -o /usr/local/bin/ftp-uploader https://github.com/Ragueel/ftp-uploader/releases/latest/download/ftp-uploader-linux-amd64
sudo chmod +x /usr/local/bin/ftp-uploader
It will download the latest release from the github repository and adds it into your bin folder.
To check if it is installed properly run the following command:
ftp-uploader
How to use ftp-uploader to deploy laravel projects?
The tool requires configuration file to be present where uploading happens. To create this configuration file run the following command:
ftp-uploader init
It should generate something similar to this:
configs:
default:
root: . # local root directory
uploadRoot: my-relative-path/
ignorePaths:
- ftp-uploader.yaml
I prefer to leave root as so it just copies files from the git repo.
.
should be changed to a folder outside of the uploadRoot folder. This could be something like public_html if your FTP account points to ../app/ by default, or it could be the full path to the desired folder.
public_html
If you have staging or dev environments where you test the code before deploying into production, you can just add another config and change uploadRoot
With configuration file present you can start uploading to your ftp server with the following command:
ftp-uploader upload --username MY_USER --pasword MY_PASSWORD --host MY_HOST --config default
I prefer using environment variables to authenticate when deploying my applications. You can find more about them here:
https://github.com/Ragueel/ftp-uploader/tree/main?tab=readme-ov-file#creating-config
If you set the environment variables just run the following command:
ftp-uploader upload -t 10
With this you can now deploy your projects with one command. Hope it helps!
Liked what you read? Don't forget to upvote!
Indie developer & author of this blog. I worked in game dev studio before, and launched many games. My main focuses are core gameplay mechanics and project infrastructure management.