Skip to content
Somnio Technology Solutions Call Us
Banner 1

September 22nd, 2023

Envoyer Tips

In the past year, I migrated all my servers to Forge and began utilizing Envoyer for all my deployments. Here are some of the lessons I've learned.

  • Ensure the correct PHP version is called when using Composer.

Since I have multiple PHP versions installed on my Forge servers, deploying a project that doesn't use the default PHP version often results in a composer installation error. To resolve this, make sure to provide the full path to the specific PHP version. For example, if you are using PHP 8.1, the composer path should be: /usr/local/bin/php8.1 /usr/local/bin/composer

  • Deployment Hooks

I discovered that I can incorporate deployment hooks before or after specific tasks by utilizing the accordion feature, which allows me to easily drag them to the desired location.

I typically create an "Optimize" hook that I run before activating a new release, as well as a PHP-FPM webhook that I execute after purging old releases.

Don't forget to specify the Run as user if you have isolated users on your server.

This is an example of the Optimize for a Statamic website but this applies to a regular Laravel site.

cd {{ release }}
{{ php }} artisan optimize:clear
{{ php }} please static:clear
{{ php }} please glide:clear

{{ php }} please assets:generate-presets
{{ php }} please assets:meta

{{ php }} please stache:refresh

The next webhook is for Php-fpm on the same site. This webhook reloads php-fpm, flushes the Cloudflare cache, and then requests a new run from OhDear. OhDear notifies me after a few minutes if there are any broken links detected. Additionally, I reset Horizon, which is a crucial step when using OpCache. Since the PHP code gets compiled, any new changes won't be recognized by the queue until it is reset.

cd {{ release }}
echo "" | sudo -S service php8.1-fpm reload
{{ php }} please static:warm
{{ php }} artisan horizon:terminate

OHDEAR_TOKEN="your_token"

curl -X POST "https://ohdear.app/api/checks/XXXX/request-run" \
    -H "Authorization: Bearer $OHDEAR_TOKEN" \
    -H "Accept: application/json" \
    -H "Content-Type: application/json"

curl -X POST "https://api.cloudflare.com/client/v4/zones/zoneXXXXXX/purge_cache" -H "Authorization: Bearer token" -H "Content-Type:application/json" --data '{"purge_everything":true}'

Paying attention to these two factors has been crucial for achieving successful deployments.


Posted on: September 22nd, 2023

Envoyer   Laravel   Forge  

Meet the author

Blog Author

Camilo Martinez

Software Developer

Camilo, has 15+ years as a full-stack software developer. His extensive expertise spans cloud solutions across industries like communication, transportation, education, healthcare, and e-commerce.

Subscribe to new posts

Want to work with us?

OUR PREVIOUS CLIENTS

Customer
Customer
Customer
Customer