Moss allows you to specify the PHP version that a website will use. Moreover, you're free to upgrade/downgrade the PHP version of your websites at will. Hence you may have multiple sites using different PHP versions, even if they're on the same server.

Moss ensures that the proper version of php and php-fpm is employed to serve your applications and to run your deployment scripts. But what if you need to run something right from your server? How can you make sure the PHP version of your website is being used? Easy, just activate a virtual environment for your site.

Activate your site's environment

We've taken the approach followed by Python's virtualenv to isolate the PHP environment of an application from another one. While you're within the virtual environment of a site, any call to php or php-fpm will use the version you set up in Moss for such website.

  1. Enter virtual environment: source the activation script at /home/<site-user>/sites/<site-name>/bin/activate (prompt changes)
  2. Do stuff
  3. Exit virtual environment: run deactivate command (prompt restores)

The following example with a PHP 5.6 site shows how it works:

user@myserver$ cd sites/mysite

user@myserver$ ls bin/
activate  composer  php  php-fpm

user@myserver$ source bin/activate  # enter virtualenv

(mysite) user@myserver$ php --version
PHP (cli)

(mysite) user@myserver$ php-fpm --version
PHP (fpm-fcgi)

(mysite) user@myserver$ deactivate  # exit virtualenv

Did this answer your question?