A handful of shell scripts to aid Silverstripe development (especially when using Laravel Valet as your dev environment):
ssdownload
- Download content (assets and database) from a live Silverstripe sitelaunch
- Open dev site URL in browsernewsite
- Creates a new Silverstripe site in Valetsetupsite
- Sets up an existing Silverstripe site for local development in Valetdeletesite
- Deletes a Valet site and matching database
- Check out the repo to a location of your choice. e.g. to
~/Sites/_SS-SCRIPTS
- Make the scripts executable.
cd ~/Sites/_SS-SCRIPTS chmod u+x *.sh
- Copy
ssscripts.conf.example
tossscripts.conf
and customise as required. - Add aliases to the scripts, so they'll work anywhere, e.g. if using ZSH on mac OS:
- Create/edit
~/.zshrc
and add the following, adjusting the path based on where you checked out the repo in step 1:
alias newsite='~/Sites/_SS-SCRIPTS/newsite.sh' alias deletesite='~/Sites/_SS-SCRIPTS/deletesite.sh' alias setupsite='~/Sites/_SS-SCRIPTS/setupsite.sh' alias launch='~/Sites/_SS-SCRIPTS/launch.sh'
- Create/edit
These scripts were primarily created for macOS. You may need to make some adjustments for them to work on Windows.
The ssdownload
and setupsite
scripts require some details about the site in question, such as the SSH conenction details.
As you will likely wish to run ssdownload
multiple times, these settings can be stored in a config file in your site's root:
~/Sites/MYSITE/ssdownload.conf
REMOTEHOST=example.com
USERNAME=example
REMOTESITEROOT=www
DEVSITEURL=https://example.dev/
Quickly update your local dev version of a site with the latest content and assets from the live site, by simply running ssdownload
in the local site's root.
This script:
- Uses
rsync
to pull down only changed/added assets. - Uses
sspak
to download a copy of the live database to replace the local database.
Local requirements:
sspak
Downloadrsync
ssdownload.conf
file in local site root with SSH details:REMOTEHOST = example.com
USERNAME = example
REMOTESITEROOT = www
- OR: pass the 3 values as arguments, e.g.:
ssdownload example example.com www
- A working copy of a Silverstripe site (version 3 or 4)
Remote requirements:
- SSH access
- With an existing public key setup
Usage:
- Once set up as above, simply run
ssdownload
from the site root and it will download the assets and database from the live site.
Often forgetting the local dev URL for each of your sites? Just store it in ssdownload.conf
and then run launch
from the terminal to open it in your browser.
Requirements:
ssdownload.conf
in local site root with:DEVSITEURL = https://example.dev/
Usage:
launch
from site root
Quickly spin up a fresh Silverstripe site in Laravel Valet.
This script first prompts for:
- A name for the site, e.g.
myexamplesite
(or takes it as an argument.) - Which version of Silverstripe you'd like to install, defaults to the latest.
Then it automatically:
- Creates a new directory (using the entered name)for the site in
~/Sites
(Customisable inssscripts.conf
) - Links this directory as a Laravel Valet site.
- Creates a new database for the site in your local database server. e.g. DBngin
- Installs the desired Silverstripe version using Composer.
- Sets Valet to use the appropriate PHP version (Customisable in
ssscripts.conf
) - Setups up the
.env
file for the site.- Adds database details
- Adds default admin login details (Customisable in
ssscripts.conf
)
- Runs
/dev/build
to set up the database. - Gives the site an SSL certificate using
valet secure
- Opens the local site URL in the browser.
- Opens the site root in your editor ready for editing. (Customisable in
ssscripts.conf
)
Local requirements:
- Laravel Valet
- Database server (e.g. DBngin)
composer
If you used newsite
to quickly spin up a new Silverstripe site to test/try something, you can quickly delete it by running:
deletesite NAMEOFSITE
This will then instantly:
- Unlink the site directory from Valet.
- Delete the site's directory.
- Delete the site's database.
Requirements:
- Laravel Valet
- Database server (e.g. DBngin)
If you have an existing Silverstripe site that you'd like to get up and running in Valet, this script will take care of that by: adding the site to Valet, setting up the .env
and downloading the assets and database from the live site.
- Start in the root of a Silverstripe site, .e.g freshly checked out from a remote repository.
- Add details for the remote site to a new
ssdownload.conf
file:REMOTEHOST=example.com
USERNAME=example
REMOTESITEROOT=www
- Run
setupsite
from the site root.
The script will ask:
- For a name for the site, e.g.
myexamplesite
(Will default to the provided SSH username) - Which version of Silverstripe the site is (e.g. 3 or 4)
- Which PHP version the site requires. (Defaults to version set in
ssscripts.conf
)
Then it automatically:
- Links this directory as a Laravel Valet site. (
valet link SITENAME
) - Sets Valet to use the desired PHP version.
- Runs
composer install
to download required packages. - Creates a new database for the site in your local database server.
- Creates a
.env
file prefilled with the local database details. (Or a_ss_environment.php
for a Silverstripe 3 site.) - Runs
ssdownload
to get the site database and assets from the live site. - Gives the site an SSL cert using
valet secure
- Opens the local site URL in the browser.
- Opens the site root in your editor ready for editing. (Customisable in
ssscripts.conf
)
Local requirements:
- Laravel Valet
- Database server (e.g. DBngin)
composer
Also works with Silverstripe 3 sites, just make sure you have PHP 7.3 installed.