skip to Main Content
Custom PHP Settings In Trellis

Often when you set up a Trellis server you find out your PHP settings are not good enough for the WordPress app you are building. Simply because you run a plugin like WooCommerce that needs more than the default 96MB PHP memory. Or because you are a fan of a slider like Revolution Slider that needs a larger upload max. file size or larger max. post size than the standard 25M. So how do you deal with custom PHP settings in Trellis?

Default PHP Values Trellis

The default values for PHP in Trellis are currently:

disable_default_pool: true
 memcached_sessions: false

php_error_reporting: 'E_ALL & ~E_DEPRECATED & ~E_STRICT'
 php_display_errors: 'Off'
 php_display_startup_errors: 'Off'
 php_max_execution_time: 120
 php_max_input_time: 300
 php_max_input_vars: 1000
 php_memory_limit: 96M
 php_mysqlnd_collect_memory_statistics: 'Off'
 php_post_max_size: 25M
 php_sendmail_path: /usr/sbin/ssmtp -t
 php_session_save_path: /tmp
 php_upload_max_filesize: 25M
 php_track_errors: 'Off'
 php_default_timezone: '{{ default_timezone }}'

php_opcache_enable: 1
 php_opcache_enable_cli: 1
 php_opcache_fast_shutdown: 1
 php_opcache_interned_strings_buffer: 8
 php_opcache_max_accelerated_files: 4000
 php_opcache_memory_consumption: 128
 php_opcache_revalidate_freq: 60

php_xdebug_remote_enable: "false"
 php_xdebug_remote_connect_back: "false"
 php_xdebug_remote_host: localhost
 php_xdebug_remote_port: "9000"
 php_xdebug_remote_log: /tmp/xdebug.log
 php_xdebug_idekey: XDEBUG
 php_max_nesting_level: 200

NB You can always check the latest setup for it here at the Trellis repository

This main.yml file is located at roles /php/defaults/main.yml . Based upon it Trellis sets up your PHP.ini values for you.

Setting Custom PHP Settings in Trellis

So what I normally do is that I change three options to have the following values:

php_memory_limit: 256M
php_post_max_size: 32M
php_upload_max_filesize: 32M

This to run WooCommerce well and allow Revolution Slider to work well with larger files and PHP post_max_size. Sometimes I also change the maximum execution time:

php_max_execution_time: 120

to a value double the size. This if I need more time for the execution of certain scripts.

Updating Trellis

Now that you have set your own new values you will also have to re-provision your Trellis server. To do this on production use:

ansible-playbook server.yml -e env=production

To do it locally on your Vagrant box you just have to run

vagrant provision

WordPress FYI

WooCommerce requires at least 256M memory. To obtain this it also states the following code snippet:

define('WP_MEMORY_LIMIT', '256M');

needs to be added to wp-config.php. This besides making sure your server allows this via php.ini or a .htaccess for example. Why? Because you need to tell WordPress to actually use the 256M of RAM. WordPress allocates 40MB for single setups by default only.

Read more about this in the WordPress Codex here.

Jasper Frumau

Jasper has been working with web frameworks and applications such as Laravel, Magento and his favorite CMS WordPress including Roots Trellis and Sage for more than a decade. He helps customers with web design and online marketing. Services provided are web design, ecommerce, SEO, content marketing. When Jasper is not coding, marketing a website, reading about the web or dreaming the internet of things he plays with his son, travels or run a few blocks.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Back To Top