Php.ini settings

What’s the best way to modify php.ini settings for all containers (dev, staging, prod)?

It kind of depends what you want to change. Also, what have you tried?

I want to add session.cookie_httponly = On and session.cookie_secure = On.

I’ve tried adding: php_session_cookie_httponly: 'On' in the /group_vars/development/php.yml file and tested on my dev container but that didn’t seem to work.

Here’s the config Trellis uses: https://github.com/roots/trellis/blob/5482cf9f9c23b104c8fe8e588b9b181333db9771/roles/php/templates/php.ini.j2

So only variables that are used in that template can be set/changed. php_session_cookie_httponly doesn’t exist.

Both these cookie settings seem useful though. So you could do a PR in Trellis to add them to our default template.

1 Like

I changed the file you referenced /roles/php/templates/php.ini.j2 by adding the following two lines:

session.cookie_httponly = {{php_session_cookie_httponly}}
session.cookie_secure = {{php_session_cookie_secure}}

And added the following two lines to the /roles/php/defaults/main.yml file:

php_session_cookie_httponly: 'On'
php_session_cookie_secure: 'On'

I then did a vagrant reload --provision and ssh’d into the vagrant box to verify the settings had been updated properly in the php.ini file, and they had.

I committed these changes to the master branch and deployed to production. The php.ini file on the production instance did not get updated.

How do I make the change happen on the production instance?

2 Likes

Provisioning (server.yml) will change php configs on your server, whereas deploying will not (deploy.yml). Try this:

ansible-playbook server.yml -e env=production --tags php
4 Likes

thanks - that worked perfectly.

I put in a PR for the change: https://github.com/roots/trellis/pull/770

3 Likes