{"id":221,"date":"2018-03-23T00:28:15","date_gmt":"2018-03-22T23:28:15","guid":{"rendered":"http:\/\/xpam.pl\/blog\/?p=221"},"modified":"2024-04-03T00:28:44","modified_gmt":"2024-04-02T22:28:44","slug":"running-multiple-php-versions-and-compiling-from-source","status":"publish","type":"post","link":"https:\/\/xpam.pl\/blog\/?p=221","title":{"rendered":"Running multiple PHP versions and compiling from source"},"content":{"rendered":"<p>We had a peculiar situation where both PHP5 and PHP7 were needed at the same time on a FreeBSD server. It was also prohibitive to get root or sudo access on the managing account. The solution was to compile PHP from source with fpm, run fpm on a UNIX socket and wire the specific domain which needed PHP7 through Nginx.<\/p>\n<h2>Compiling from source<\/h2>\n<p>Compiling PHP is pretty straightforward but you can easily forget crucial configure flags. First get the source archive. After trial and error, this appears to be \"good enough\" for Laravel 5.6 requirements.<\/p>\n<pre><code class=\"language-bash\">.\/configure -prefix=\/home\/foo\/php7 --with-openssl --enable-mbstring --with-pdo-mysql --enable-fpm --with-config-file-path=\/home\/foo\/php7 --with-config-file-scan-dir=\/home\/foo\/php7 --with-iconv --with-gmp --with-gd<\/code><\/pre>\n<p>Followed by<br \/>\n<code>make &amp;&amp; make install<\/code><br \/>\ncopy <span style=\"text-decoration: underline;\">php.ini-development<\/span> file from source to the <em>&#8211;with-config-file-path<\/em> directory and call it <span style=\"text-decoration: underline;\">php.ini<\/span>. In <em>PREFIX\/bin<\/em> confirm that php binary is loading your ini file by running<br \/>\n<code>.\/php --ini<\/code><br \/>\nIf you made a mistake in your configure run, you have to <strong>make clean<\/strong> first or the changed options won't be picked up.<\/p>\n<h2>Configuring fpm<\/h2>\n<p>In your <em>PREFIX\/etc<\/em> folder, check <em>php-fpm.conf<\/em>. The only lines I bothered to verify and edit were <em>pid<\/em>, <em>error_log<\/em> and <em>include<\/em>, the rest can be left as is.<\/p>\n<p>Inside folder <strong>php-fpm.d<\/strong> create a config file like <em>my.subdomain.conf <\/em>and add something like<\/p>\n<pre><code class=\"language-plaintext\">listen = \/location\/of\/php-fpm.sock\nuser = foo\ngroup = foo\npm = dynamic\npm.max_children = 5\npm.start_servers = 1\npm.min_spare_servers = 1\npm.max_spare_servers = 1\npm.max_requests = 200\nlisten.backlog = -1\npm.status_path = \/status\nrequest_terminate_timeout = 30s\nrlimit_files = 131072\nrlimit_core = unlimited\ncatch_workers_output = yes\nenv[HOSTNAME] = $HOSTNAME\nenv[TMP] = \/tmp\nenv[TMPDIR] = \/tmp\nenv[TEMP] = \/tmp<\/code><\/pre>\n<p>You can study fpm config in great details but this is enough to get you going.<\/p>\n<p>Now you can run your PHP7 fpm process in <em>PREFIX\/sbin<\/em> with<br \/>\n<code>.\/php-fpm --fpm-config \/prefix\/etc\/php-fpm.conf<\/code><br \/>\nSince we don't have any init scripts in this case, we must be able to kill it also. Find it with<br \/>\n<code>ps aux | grep fpm<\/code><br \/>\nand kill with<br \/>\n<code>kill -QUIT pid<\/code><br \/>\nMake sure it says <strong>php-fpm: master process<\/strong> in the ps output, killing children doesn't do anything, just respawns them.<\/p>\n<p>Now you just need to wire up your Nginx to use this fpm instead of the PHP5 system one by specifying<br \/>\n<code>fastcgi_pass unix:\/location\/of\/php-fpm.sock;<\/code><br \/>\nWe now have PHP dualstack with some web apps running on system provided PHP5 and some on our own built PHP7. We did not need root for this process, except possibly for configuring Nginx.<\/p>\n<p>One obvious downside is that you now have to take care of updating your PHP version on your own but that is one view we had to sacrifice. Updates should be relatively easy and fast since <em>make install<\/em> won't remove your config files in existing installation and compiling PHP takes just a few minutes.<\/p>\n<p>&nbsp;<\/p>\n<div class=\"wp-post-signature\">\r\n<br \/>\r\n<br \/>\r\n<img src='https:\/\/xpam.pl\/aaaaff.png' title='Moonie' \/> Cen<br \/>\r\n<a href='https:\/\/github.com\/cen1'>GitHub<\/a><br \/>\r\n<a href='https:\/\/eurobattle.net'>Eurobattle.net<\/a><br \/>\r\n<a href='https:\/\/lagabuse.com'>Lagabuse.com<\/a><br \/>\r\n<a href='https:\/\/bnetdocs.org'>Bnetdocs<\/a><br \/>\r\n<\/div>\r\n","protected":false},"excerpt":{"rendered":"<p>We had a peculiar situation where both PHP5 and PHP7 were needed at the same time on a FreeBSD server. It was also prohibitive to get root or sudo access on the managing account. The solution was to compile PHP from source with fpm, run fpm on a UNIX socket and wire the specific domain [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[20,18],"tags":[],"class_list":["post-221","post","type-post","status-publish","format-standard","hentry","category-linux","category-script-magic"],"_links":{"self":[{"href":"https:\/\/xpam.pl\/blog\/index.php?rest_route=\/wp\/v2\/posts\/221","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/xpam.pl\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/xpam.pl\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/xpam.pl\/blog\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/xpam.pl\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=221"}],"version-history":[{"count":6,"href":"https:\/\/xpam.pl\/blog\/index.php?rest_route=\/wp\/v2\/posts\/221\/revisions"}],"predecessor-version":[{"id":535,"href":"https:\/\/xpam.pl\/blog\/index.php?rest_route=\/wp\/v2\/posts\/221\/revisions\/535"}],"wp:attachment":[{"href":"https:\/\/xpam.pl\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=221"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/xpam.pl\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=221"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/xpam.pl\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=221"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}