Skip to content

Instantly share code, notes, and snippets.

@GrantSmithDoddle
Last active December 18, 2022 20:37
Show Gist options
  • Save GrantSmithDoddle/a96a574a440f2138e262d29be3e51358 to your computer and use it in GitHub Desktop.
Save GrantSmithDoddle/a96a574a440f2138e262d29be3e51358 to your computer and use it in GitHub Desktop.

Statamic 3 Notes

These notes are for my hosting environment which is a Linux server running cPanel and Apache.

Deployment to webserver

This is what worked for me and if anyone suggests a better method I'll update accordingly.

Assuming files are committed to GitHub, a deploy key is setup and you are logged into the web server via SSH.

  1. Add your SSH key to the GitHub repository, be sure to enable Allow write access.
  2. Back on the server git pull the repository to the root of the server
  3. cd into the newly created folder, for example NEW_GIT_FOLDER
  4. Run composer install within NEW_GIT_FOLDER
  5. Create new .env file, adjusting settings for production
  6. The last action is to create a symlink pointing public_html to the public within NEW_GIT_FOLDER
$ ln -sfn NEW_GIT_FOLDER/public public_html
  1. Generate a new APP_KEY by running the following command
$ php artisan key:generate

Note: If you want to be able to run updates from the Dashboard of Statamic, you may need to add an additional line to the .htaccess file. See Running updates from Statamic dashboard fail below.

GitHub Integration

When adding a public deploy key to GitHub, be sure to enable Allow write access. This will allow the site to push changes back to GitHub.

Integration can be controlled by the within the Production Server .env file. Below is an example of options.

APP_ENV=production
STATAMIC_GIT_USER_NAME=your_github_username
STATAMIC_GIT_USER_EMAIL=your_github_email_address
STATAMIC_GIT_ENABLED=true
STATAMIC_GIT_AUTOMATIC=true
STATAMIC_GIT_PUSH=true
STATAMIC_GIT_DISPATCH_DELAY=120

By default Statamic does not track assets, this can be changed by adding public_path('assets') to the array in /config/statamic/git.php.

'paths' => [
    base_path('content'),
    base_path('users'),
    resource_path('blueprints'),
    resource_path('fieldsets'),
    resource_path('forms'),
    resource_path('users'),
    storage_path('forms'),
    public_path('assets')
],

Errors

PHP memory exceeded error.

This error can be overcome by temporarily turning off the composer memory limit and then running the command you wish to preform. Example below.

$ COMPOSER_MEMORY_LIMIT=-1 composer remove statamic/migrator

You may wish to change the memory limit on your local machine. To do this, first we need to find the php.ini file by running the following command.

$ php -i | grep php.ini

It's then a case of searching for memory_limit and changing the value.

Running updates from Statamic dashboard fail

In Factory.php line 648:

The HOME or COMPOSER_HOME environment variable must be set for composer to   
run correctly 

This error occurs when Statamic can not find Composer and hence we need to set an environment varible. This can be sorted via the .htaccess file for servers running Apache.

Simply add the following to the .htaccess file of public

$ SetEnv COMPOSER_HOME '/opt/cpanel/composer/bin'

Larevel

Logs

To read the Laravel Log, you run this command.

$ cat ~/PATH-TO-FILE/storage/logs/laravel.log

Although incredible helpful, the ~/storage/logs/laravel.log can become very large. To clear the log you can run this command.

$ truncate -s 0 ~/PATH-TO-FILE/storage/logs/laravel.log
@jacksonzumdish
Copy link

Legend... Thank you.

@GrantSmithDoddle
Copy link
Author

Legend... Thank you.

Glad it was useful. Good luck

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment