0%

Run PHP7.0-FPM on Ubuntu 16.04 in Crouton/Chromebook

I bought an Acer Chromebook 14 (CB3-431) during the black Friday. Then I installed Ubuntu by Crouton on it. I am not going to introduce it because it is easy and doesn’t take much time. Also, chroot is cheap. You can do whatever you want to do. When something unexpected happens, you can easily re-install it.

When I tried to install LNMP (Linux + Nginx + MySQL + PHP7, someone call it LEMP), the last step I installed PHP like this,

1
sudo apt-get install php7.0 php7.0-fpm php-mysql

I saw this error in terminal

1
2
3
4
5
6
7
8
Setting up php7.0-fpm (7.0.22-0ubuntu0.16.04.1) ...
Running in chroot, ignoring request.
invoke-rc.d: initscript php7.0-fpm, action "start" failed.
dpkg: error processing package php7.0-fpm (--configure):
subprocess installed post-installation script returned error exit status 1
Errors were encountered while processing:
php7.0-fpm
E: Sub-process /usr/bin/dpkg returned an error code (1)

It indicated that the php-fpm failed to start, so when I opened the a .php in the site, it gave me a 503 error. I found that I cannot started the php7.0-fpm. In the nginx config file,

1
2
3
4
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/run/php/php7.0-fpm.sock;
}

But there was no folder named /run/php.. I supposed in the sentence “Running in chroot, ignoring request” meaned ignoring the request to mkdir /run/php. So I build a folder named /run/php manually, changed its owner to www-data and gave it 777(it’s not safe, maybe 755?), and the problem fixed.

However, when I restarted my Ubuntu, the problem appeared again. I had to wrote a shell script to start up the php development environment. When I want to run php, I just run the script.(Of course, there is better way to avoid doing this manually, but the source of Chromebook is limited, so I decide to only run it when I need it.)

1
2
3
4
5
6
7
8
#!/bin/sh

sudo service nginx start
sudo mkdir /run/php
sudo chown -R www-data /run/php
sudo chmod -R 777 /run/php
sudo /usr/sbin/php-fpm7.0 -D
sudo service php7.0-fpm status