PHP and Nginx RPM repo for RedSleeve Linux on Raspberry Pi

You may have already noticed from a previous post that I’m a big fan of CentOS. So, I’ve spent the past few days trying to recompile some SRPMs for the Raspberry Pi. I don’t have a cross compile too chain, so compiling this stuff natively on the 700Mhz ARM device took a little longer than normal, to put it mildly. I wanted a bit of a challenge and I’m sure that Nginx and PHP-FPM would suit the raspi’s modest hardware better than a standard Apache HTTPd install.

Getting Started

I’ll assume that you’ve read the instructions on how to get RedSleeve Linux on your Raspberry Pi. As with most of the other Raspi distros, it’s very straight forward. I may do a post on using GParted┬áto claim back the free space on your SD card if enough people ask. Once you’ve got your Pi up and running, let’s SSH in and get cracking. Keep in mind that by default, SSHing in as “root” on redsleeve is explicitly not allowed.

Create the following yum repo:

[root@raspberrypi /]# cat > /etc/yum.repos.d/adrianhardy.repo
[adrianhardy]
baseurl=http://rpms.adrianhardy.co.uk/
enabled=0
name=adrianhardy
gpgcheck=0

(Now hit control+d)

You’ll note that I’ve disabled gpgchecks – I’ve never made my RPM builds public before so you’ll have to excuse my hacks. I’ll tidy up as I go along.

Installing the RPMs

You should be able to install the RPMs fairly easily. I’ve left mine disabled by default because I usually like to opt-in to non-standard repos:

[root@raspberrypi /]# yum --enablerepo=adrianhardy install php-fpm nginx

That’s it! If you’ve not installed HTTPd then you’ll see some errors when installing Nginx about user “apache” not existing. I’ll fix that in a bit. When it takes about 25 hours in total for FireBird, Nginx and all of PHP to compile I thought I could deal with that particular issue later. I might also namespace the RPMs so they’re distinguished from the stock ones.

Setting up your web environment

Add this section of text to /etc/nginx/conf.d/default.conf

location ~ \.php$ {
root /usr/share/nginx/html/;
fastcgi_index index.php;
fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param SCRIPT_NAME $fastcgi_script_name;
}

And /etc/php-fpm/php-fpm.d/www.conf needs a few simple changes too:

listen = /var/run/php-fpm/php-fpm.sock
...
listen.owner = nginx
listen.group = users
listen.mode = 0660
...
user=nginx
group=nginx
...
pm=static
pm.max_children=2 ; season to taste
...
catch_workers_output=yes
....
php_admin_value[error_log] = /var/log/php_errors.log
php_admin_value[memory_limit] = 8M ; again, change to suit your needs

You should be able to restart php-fpm and nginx and get some PHP code going on on your raspi.

Credit where it’s due

Firstly, thanks to the RedSleeve guys for getting my favourite flavour of Linux onto the Raspberry Pi. Secondly, thanks should go out to the tireless Remi Collet who made the PHP-5.4.4 SPEC file I used to compile PHP.

One last thing

There’s only one PHP module that comes as standard that I didn’t compile; FreeTDS/MSSQL support. If there’s enough demand for it I may consider it but I personally didn’t see a real use for it.

Posted in Development, Linux, PHP, RasberryPi

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">