{"id":790,"date":"2021-11-01T13:25:20","date_gmt":"2021-11-01T13:25:20","guid":{"rendered":"https:\/\/mklasen.com\/?p=790"},"modified":"2021-11-01T13:25:21","modified_gmt":"2021-11-01T13:25:21","slug":"setting-php-versions-in-deployer-deployments","status":"publish","type":"post","link":"https:\/\/mklasen.com\/setting-php-versions-in-deployer-deployments\/","title":{"rendered":"Setting PHP versions in Deployer deployments"},"content":{"rendered":"\n
Sometimes your terminal environment (where you SSH into) uses a different PHP version then that you need. Most hosting companies do have several PHP versions available. But how do you use them, and more importantly, how do you set the right one when deploying new versions with Deployer?<\/p>\n\n\n\n
In this case, composer required a higher PHP version for some packages. You’re presented with errors like:<\/p>\n\n\n\n
Loading composer repositories with package information\nInstalling dependencies (including require-dev) from lock file\nYour requirements could not be resolved to an installable set of packages.\n Problem 1\n - Installation request for ramsey\/collection 1.2.2 -> satisfiable by ramsey\/collection[1.2.2].\n - ramsey\/collection 1.2.2 requires php ^7.3 || ^8 -> your PHP version (7.2.33) does not satisfy that requirement.\n Problem 2\n - ramsey\/collection 1.2.2 requires php ^7.3 || ^8 -> your PHP version (7.2.33) does not satisfy that requirement.\n - ramsey\/uuid 4.2.3 requires ramsey\/collection ^1.0 -> satisfiable by ramsey\/collection[1.2.2].\n - Installation request for ramsey\/uuid 4.2.3 -> satisfiable by ramsey\/uuid[4.2.3].<\/code><\/pre>\n\n\n\nWhich version do you currently run?<\/h2>\n\n\n\n
Use php -v <\/code>to get the current version.<\/p>\n\n\n\nWhere’s your current version located? <\/h2>\n\n\n\n
Use which php<\/code> to retrieve the path<\/p>\n\n\n\nWhere’s composer located?<\/h2>\n\n\n\n
Use which composer<\/code> to retrieve the path.<\/p>\n\n\n\nWhat other versions do you have installed?<\/h2>\n\n\n\n
ls -la \/usr\/bin\/<\/code> might give you some more information.<\/p>\n\n\n\nYou can also search for files with php<\/code> in them using:
find \/ -type f -name \"php\"<\/code><\/p>\n\n\n\nYou will probably see a whole lot of permision denied notices, hide them using:<\/p>\n\n\n\n
find \/ -type f -name \"php\" 2>&1 | grep -v \"Permission denied\"<\/code><\/pre>\n\n\n\nFor me, this results in a nice list of PHP versions:<\/p>\n\n\n\n
\/opt\/remi\/php56\/root\/usr\/bin\/php\n\/opt\/remi\/php70\/root\/usr\/bin\/php\n\/opt\/remi\/php72\/root\/usr\/bin\/php\n\/opt\/remi\/php74\/root\/usr\/bin\/php\n\/opt\/remi\/php80\/root\/usr\/bin\/php\n\/opt\/remi\/php71\/root\/usr\/bin\/php\n\/opt\/remi\/php73\/root\/usr\/bin\/php<\/code><\/pre>\n\n\n\nI can use any of this paths, to confirm it works we can run:<\/p>\n\n\n\n
\/opt\/remi\/php73\/root\/usr\/bin\/php -v<\/code><\/pre>\n\n\n\nSo, how do I make deployer use this?<\/h2>\n\n\n\n
In my case, I want to set the PHP version composer uses. We can set this by setting the bin\/composer<\/code> parameter in Deployer. Globally, by adding:<\/p>\n\n\n\nset('bin\/composer',\n\tfunction () {\n\t\treturn '\/opt\/remi\/php73\/root\/usr\/bin\/php \/usr\/bin\/composer';\n\t}\n);<\/code><\/pre>\n\n\n\nOr, per host, by adding:<\/p>\n\n\n\n
host( 'prod' )\n\t->set(\n\t\t'bin\/composer',\n\t\tfunction () {\n\t\t\treturn '\/opt\/remi\/php73\/root\/usr\/bin\/php \/usr\/bin\/composer';\n\t\t}\n\t);<\/code><\/pre>\n\n\n\nThat’s it! Happy deploying!<\/strong><\/p>\n","protected":false},"excerpt":{"rendered":"Sometimes your terminal environment (where you SSH into) uses a different PHP version then that you need. Most hosting companies do have several PHP versions available. But how do you use them, and more importantly, how do you set the right one when deploying new versions with Deployer? The errors you can run into In […]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"_genesis_hide_title":false,"_genesis_hide_breadcrumbs":false,"_genesis_hide_singular_image":false,"_genesis_hide_footer_widgets":false,"_genesis_custom_body_class":"","_genesis_custom_post_class":"","_genesis_layout":"","footnotes":""},"categories":[1],"tags":[],"acf":[],"yoast_head":"\n
Setting PHP versions in Deployer deployments - Marinus Klasen<\/title>\n\n\n\n\n\n\n\n\n\n\n\n\n\n\t\n\t\n\t\n\n\n\n\n\n\t\n\t\n\t\n