{"id":735,"date":"2016-08-09T22:18:07","date_gmt":"2016-08-10T02:18:07","guid":{"rendered":"https:\/\/www.devolve.net\/blog\/?p=735"},"modified":"2018-07-13T11:28:52","modified_gmt":"2018-07-13T15:28:52","slug":"apache-fastcgi-php-7-debian-wheezy-ubuntu-14-04","status":"publish","type":"post","link":"https:\/\/www.devolve.local\/apache-fastcgi-php-7-debian-wheezy-ubuntu-14-04\/","title":{"rendered":"Apache, Fastcgi, PHP 7 on Debian Wheezy & Ubuntu 14.04"},"content":{"rendered":"

Intro: The Tyranny of Prefork<\/h2>\n

There are a lot<\/strong> of tutorials out there that go through the rote instructions on upgrading your Debian or Ubuntu system to use PHP 7. While I’m sure most of them are fine, they assume you’d want to use the prefork process model or event\/threaded via CGI (via proxy and fcgi modules). While prefork is certainly battle-tested, it uses a ton more memory than it needs to, so I’m going to document how to upgrade an existing Fastcgi install to PHP 7.<\/p>\n

The problem is that I’ve already set up my system with mod_fastcgi paired with the php5-fpm package, and I don’t want to fundamentally change that setup. There’s a good looking tutorial on PHP 5 + fastcgi on Linode<\/a> if you aren’t already using it.<\/p>\n

Enter PHP 7<\/h2>\n

Now, the upgrade portion. Before making any changes, it’s a good idea to keep notes about which PHP-based packages you currently have installed. <\/p>\n

dpkg -l | grep -i php > php-pkgs.txt<\/pre>\n

Tension \/ Conflict<\/h2>\n

Now add the 3rd-party repository.<\/p>\n

sudo add-apt-repository ppa:ondrej\/php<\/pre>\n

If your locale isn’t set to UTF-8, there may be an error adding the repo. In that case, you’ll need to:<\/p>\n

\r\nsudo apt-get install -y language-pack-en-base\r\nsudo LC_ALL=en_US.UTF-8 add-apt-repository ppa:ondrej\/php<\/pre>\n

then<\/p>\n

sudo apt-get update<\/pre>\n

Many other tutorials at this point will say to install php7.0<\/code>, but don’t. It assumes you’ll want to run Apache in prefork mode by installing libapache2-mod-php7.0<\/code>.<\/p>\n

sudo apt-get install php7.0-fpm<\/pre>\n

When installing, you’ll see messages instructing you to enable php7.0-fpm.conf<\/code> as well as mod_proxy<\/code> and mod_proxy_fcgi<\/code>. Ignore these messages. If you are running PHP apps that connect to MySQL, also install php7.0-mysql<\/code> and the 7.0 equivalents of whatever other PHP 5 packages were installed.<\/p>\n

Climax<\/h2>\n

Next go to the \/etc\/apache2\/conf-available directory. Either here or in an individual virtual host file, you should have an existing set of instructions telling Apache how to deal with PHP files using the Fastcgi method. It would look something like this:<\/p>\n

\r\n\r\n   AddHandler php.fcgi .php\r\n   Action php.fcgi \/php.fcgi\r\n   Alias \/php.fcgi \/usr\/lib\/cgi-bin\/php.fcgi\r\n   FastCgiExternalServer \/usr\/lib\/cgi-bin\/php.fcgi -socket \/var\/run\/php5-fpm.sock -pass-header Authorization\r\n   \r\n       Require all granted\r\n   <\/directory>\r\n<\/ifmodule>\r\n<\/pre>\n

Some of the values used here may not be what you have set up, and that’s fine, as long as your values are consistently used from one line to the next. Change it to look like this:<\/p>\n

\r\n   AddHandler php.fcgi .php\r\n   Action php.fcgi \/php.fcgi\r\n   Alias \/php.fcgi \/usr\/lib\/cgi-bin\/php.fcgi\r\n   FastCgiExternalServer \/usr\/lib\/cgi-bin\/php.fcgi -socket \/run\/php\/php7.0-fpm.sock -pass-header Authorization -idle-timeout 3600\r\n   \r\n       Require all granted\r\n   <\/directory>\r\n   \r\n       # Deny access to raw php sources by default\r\n       # To re-enable it's recommended to enable access to the files\r\n       # only in specific virtual host or directory\r\n       Require all denied\r\n   <\/filesmatch>\r\n   # Deny access to files without filename (e.g. '.php')\r\n   \r\n       Require all denied\r\n   <\/filesmatch>\r\n<\/ifmodule><\/pre>\n

If everything was working fine before, the only real change you’d need to make is to fix the path to the socket and add the idle timeout option. If this is a new Fastcgi install for you, save the above as \/etc\/apache2\/conf-available\/php-fpm.conf<\/code> and enable it with <\/p>\n

sudo a2enmod php-fpm<\/pre>\n

Denouement<\/h2>\n

At this point, you just have to do some housekeeping. In case the php5-fpm<\/code> package is still installed, disable or remove it. If only disabled, be sure to tell Apache not to load it with <\/p>\n

sudo a2dismod php5-fpm<\/pre>\n

Take a look at the files under \/etc\/php5\/<\/code> to see if you need to copy any files or settings over to the new PHP configuration directory, \/etc\/php\/7.0\/<\/code>.<\/p>\n

Exeunt<\/h2>\n

PHP 7 is fast. Fastcgi is fast. Fast is good.<\/p>\n","protected":false},"excerpt":{"rendered":"

Intro: The Tyranny of Prefork There are a lot of tutorials out there that go through the rote instructions on upgrading your Debian or Ubuntu system to use PHP 7. While I’m sure most of them are fine, they assume you’d want to use the prefork process model or event\/threaded via CGI (via proxy and […]<\/p>\n","protected":false},"author":3,"featured_media":748,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[6],"tags":[34,25,26],"_links":{"self":[{"href":"https:\/\/www.devolve.local\/wp-json\/wp\/v2\/posts\/735"}],"collection":[{"href":"https:\/\/www.devolve.local\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.devolve.local\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.devolve.local\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/www.devolve.local\/wp-json\/wp\/v2\/comments?post=735"}],"version-history":[{"count":13,"href":"https:\/\/www.devolve.local\/wp-json\/wp\/v2\/posts\/735\/revisions"}],"predecessor-version":[{"id":749,"href":"https:\/\/www.devolve.local\/wp-json\/wp\/v2\/posts\/735\/revisions\/749"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.devolve.local\/wp-json\/wp\/v2\/media\/748"}],"wp:attachment":[{"href":"https:\/\/www.devolve.local\/wp-json\/wp\/v2\/media?parent=735"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.devolve.local\/wp-json\/wp\/v2\/categories?post=735"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.devolve.local\/wp-json\/wp\/v2\/tags?post=735"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}