September, 10 2023

Deploying Staticus To Vercel

I just finished rebuilding my website using Staticus. Even though Staticus is a static site generator, it requires PHP for Vercel deployment. This is because Staticus executes php vendor/bin/staticus build command when npm run prod command runs.

After a lot of tries, I found an article by Statamic and I just had to make a few modification to the deployment script.

Here is the modified bash script for Staticus deployment:

#!/bin/sh

# Install PHP & WGET
yum install -y amazon-linux-extras
amazon-linux-extras enable php8.1
yum clean metadata
yum install php php-{common,curl,mbstring,gd,gettext,bcmath,json,xml,fpm,intl,zip,imap}
yum install wget

# INSTALL COMPOSER
EXPECTED_CHECKSUM="$(wget -q -O - https://composer.github.io/installer.sig)"
php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
ACTUAL_CHECKSUM="$(php -r "echo hash_file('sha384', 'composer-setup.php');")"

if [ "$EXPECTED_CHECKSUM" != "$ACTUAL_CHECKSUM" ]
then
    >&2 echo 'ERROR: Invalid installer checksum'
    rm composer-setup.php
    exit 1
fi

php composer-setup.php --quiet
rm composer-setup.php

# INSTALL COMPOSER DEPENDENCIES
php composer.phar install

# BUILD STATIC SITE
npm install && npm run prod
  • Create a new file called ./deploy.sh and paste the code snippet above.

  • Import a new site in your Vercel account.

  • Link the site to your desired GitHub repository

  • Add build command ./deploy.sh

  • Set output directory to dist

Vercel build settings

With the settings above your Staticus site will be successfully deployed on vercel.

Staticus was created last year, It's super slim and it comes with powerful features of SSG like Jigsaw by Tighten. I am shouting out to Gilbert, creator of Staticus whom I modeled my new blog from his own. 🙌

Join my inner circle newsletter

Be the first to hear about anything I publish, launch, or think is helpful for you. Subscribe here

Hey, have you tried Litehost lately ?

Litehost is a web hosting platform for PHP & Laravel developers with Composer, Git, PHP & CLI pre-installed. Try it now