General guidance on setting up web server / php / mysql [LINK]

5 posts
by monpjc » Thu Apr 12, 2012 10:37 am

I've been working on getting a live server working on my Raspi and have been using this page that I have found.

It was written long before the rise of the Pi so is for guidance only, but so far has been very good at helping me get this up and running.
Posts: 24
Joined: Fri Apr 06, 2012 5:13 pm
by shirro » Thu Apr 12, 2012 1:23 pm
nginx and php5-fpm are a nice combo for this. It is often used in production by people I know.

I threw this together to show how to do a quick and nasty php and sql for education purposed or quick hacks. You would never do this in production. I have cut some corners to keep things brief.

You will need to wait until the Foundation is supplying Debian Wheezy for your Pi or build PHP5.4 yourself to get the builtin web server.

Posts: 248
Joined: Tue Jan 24, 2012 4:54 am
by spurious » Fri May 18, 2012 11:00 am
Here are some quick notes on setting up MySQL, nginx and PHP on the R-Pi.
This assumes you are at a command prompt logged in as root.

Code: Select all

make a note of the IP address

Code: Select all
>aptitude install mysql-server mysql-client

when prompted enter the root password

Code: Select all
>aptitude install nginx

Code: Select all
>aptitude install php5-cgi php5-mysql php5-curl php5-gd php5-idn php-pear php5-imagick php5-imap php5-mcrypt php5-memcache php5-mhash php5-ming php5-pspell php5-recode php5-snmp php5-sqlite php5-tidy php5-xmlrpc php5-xsl

Code: Select all
>vi /etc/nginx/sites-available/default

here is an example config file to get you started..

Code: Select all
server {
        listen   80; ## listen for ipv4
        server_name  localhost;
        access_log  /var/log/nginx/localhost.access.log;

        location / {
                root   /var/www;
                index  index.php index.html index.htm;

        ## Images and static content is treated different
        location ~* ^.+.(jpg|jpeg|gif|css|png|js|ico|xml)$ {
                access_log        off;
                expires           30d;
                root /var/www;

        ## Parse all .php file in the /var/www directory
        location ~ .php$ {
                fastcgi_split_path_info ^(.+\.php)(.*)$;
                fastcgi_pass   backend;
                fastcgi_index  index.php;
                fastcgi_param  SCRIPT_FILENAME  /var/www$fastcgi_script_name;
                include fastcgi_params;
                fastcgi_param  QUERY_STRING     $query_string;
                fastcgi_param  REQUEST_METHOD   $request_method;
                fastcgi_param  CONTENT_TYPE     $content_type;
                fastcgi_param  CONTENT_LENGTH   $content_length;
                fastcgi_intercept_errors        on;
                fastcgi_ignore_client_abort     off;
                fastcgi_connect_timeout 60;
                fastcgi_send_timeout 180;
                fastcgi_read_timeout 180;
                fastcgi_buffer_size 128k;
                fastcgi_buffers 4 256k;
                fastcgi_busy_buffers_size 256k;
                fastcgi_temp_file_write_size 256k;

        ## Disable viewing .htaccess & .htpassword
        location ~ /\.ht {
                deny  all;
upstream backend {

Code: Select all
>echo "deb wheezy main" >> /etc/apt/sources.list

Code: Select all
>apt-get update

Code: Select all
>apt-get install php5-cli php5-common php5-suhosin

Code: Select all
>apt-get install php5-fpm php5-cgi

Code: Select all
>vi /etc/php5/fpm/pool.d/www.conf

change the line that sets listen...
Code: Select all
listen = /var/run/php5-fpm.sock

Code: Select all
listen =

Code: Select all
>mkdir /var/www

Code: Select all
>groupadd www-data

Code: Select all
>/etc/init.d/nginx restart

Code: Select all
>/etc/init.d/php5-fpm restart

Code: Select all
>echo "<?php phpinfo(); ?>" >> /var/www/test.php

to test use a browser and go to http://[that IP you made a note of at the beginning]/test.php
Posts: 343
Joined: Mon Nov 21, 2011 9:29 pm
by SvG » Fri Dec 21, 2012 5:31 pm
@Spurious, nice guide!

Found that a root /var/www; line in the location ~ .php$ { section was missing.

Got FastCGI sent in stderr: "Primary script unknown" while reading response header from upstream errors.

With the root line added it works!
Posts: 1
Joined: Fri Dec 21, 2012 5:28 pm
by nagymancs » Mon Jan 28, 2013 1:45 pm
big thanx for the many lines put together!
so far almost every stuff went up without shouting for anything. Only the suhosin patches were not found.

however success is still partial. With a localhost browser test it was able to display the htmls i've put into the www dir. but with phps it just bare says: file not found in the browser. its exactly next to the htmls. i pi chowned,755chmodded, still no luck

any idea what can be the reason/ how i could troubleshoot this? :|
Posts: 1
Joined: Sun Jan 20, 2013 9:26 pm