What is an easy way to get a CraftCMS site up and running? I found this to be a rather simple method with help of ploi.io, a Hetzner CX11 virtual cloud server (max. € 4.51 / month) and DDEV for local development.
Beware: I'm a CraftCMS newbie! 🤓
Prerequisites
- Install DDEV for local development
- Sign up for a Hetzner Cloud account
- Sign up for a ploi.io account
- Connect the Hetzner account via API key on ploi.io (as service provider)
- Create your first server via ploi dashboard
Create GitHub repository, clone it locally
Create a new GitHub project (with README), clone it locally and run these commands for the CraftCMS installation:
# Set up the DDEV environment:
ddev config --project-type=craftcms --docroot=web --create-docroot
# Boot the project and install the starter project:
ddev start
ddev composer create -y --no-scripts craftcms/craft
# Run the Craft installer:
ddev craft install
ddev launch
Push the new files to your GitHub repository.
Dump the local database
For the initial installation we need a dump of the database. This can be achieved via ddev export-db -f dump.sql.gz
.
This database dump will be later imported into the live sites database.
But do not worry: After that initial DB import, changes to the data structure will be applied via files in git and by CLI migrate commands (for example php craft migrate/all --no-content --interactive=0
).
Create a new database on ploi.io (server)
Databases are managed via Server
Install phpMyAdmin, connect via DB user and password
Import the database dump file
Create a new site via ploi
You don't have to connect the real domain immediately, you can also generate a test domain later. Therefore you can also use "mysite.example.com" e.g.
Install from git repository
We use a git repository, not the 1-click installer for CraftCMS.
If you use a public repository, you can just paste the URL:
Adjust the deploy script
These are commands which are executed when you hit the "deploy now" button.
# ploi standard commands
cd /home/ploi/craft-playground.mandrasch.dev
git pull origin main
# NodeJS support, e.g. for vite
# npm install
# npm run build
composer install --no-dev --no-interaction --prefer-dist --optimize-autoloader
# deployment best practices by craftcms docs:
# https://craftcms.com/knowledge-base/deployment-best-practices
php craft update/composer-install --interactive=0
php craft migrate/all --no-content --interactive=0
php craft project-config/apply
php craft migrate --track=content --interactive=0
echo "" | sudo -S service php8.2-fpm reload
echo "🚀 Application deployed!"
Add .env values via "Edit environment"
Copy the .env values from .env.example.production
, add a security key and adjust the database connection settings. For the security key you can use a generator like Bitwarden Generator.
Add a free "Let's encrypt" SSL certificate
Optional: Add a test domain
If you haven't connected a real domain yet, you can also use a test domain freely provided by ploi.io (for test usage / development).
gitignore the license.key
One last thing I would suggest is adding config/license.key
to your .gitignore
, otherwise you will end up with "Your local changes to the following files would be overwritten by merge: config/license.key" after the first deployment.
Ready for deployment! 🎉
Hit the "Deploy now" button and pull the craftcms installation from your GitHub repository:
That's it. Open your site and enjoy developing with Craft CMS! 🎉
If you want to trigger auto deployment when pushing to GitHub, check out this guide: ploi.io - How to trigger deployments via GitHub actions
If you're interested in integrating Vite, there is an awesome plugin nystudio107/vite for CraftCMS. Check out example code and tutorial here: https://github.com/mandrasch/ddev-craftcms-vite.
In future it would be cool to have a good and robust ddev pull
script to download media assets and live content into local development.
Also make sure to join the DDEV discord. 💚
Top comments (2)
This looks really cool and straight forward!
Do you by any chance also know how to do that for NetCup?
And also are you still using CraftCMS nowadays?
hey!
yes, using CraftCMS is my current work as developer in a web agency :)
For NetCup: You would have to deploy via SSH/rsync github.com/marketplace/actions/rsy... - or checkout the git repository on your server if git is available), or use Docker, another deployment option. Don't know what NetCup is offering.
For SSH/rsync deployment, see for example
webstoemp.com/blog/github-actions-...
(Just did a quick google search)
If you don't want to fiddle around yourself with GitHub Actions and such, platforms like buddy.works/ are a bit easier to get started.
Or you could also check out Deployer (dev.to/mandrasch/deploy-craft-cms-...), but I found it a bit to complicated in the end.
Also joining Craft Discord could be a good option, maybe someone could assist you there as well if you have questions. Maybe someone already deploys on NetCup.
Have fun with CraftCMS!