Raspberry nginx + php5

1. update

1
sudo apt-get update

2. nginx

1
sudo apt-get install nginx

3. php

1
2
3
4
5
sudo apt-get install php5-fpm
sudo apt-get install php-apc
sudo apt-get install php5-gd
sudo apt-get php-apc php5-common
sudo apt-get install php5-cli php5-cgi

php5-mysql when mysql need
php5-mcrypt when phpMyAdmin need

4. Nginx

  • Static type file no log, one day expired

    1
    2
    3
    4
    location ~* ^.+.(jpg|jpeg|gif|css|png|js|ico|xml)$ {
    access_log off;
    expires 1d;
    }
  • The data type root directory could request

    1
    2
    3
    4
    5
    6
    location / {
    # First attempt to serve request as file, then
    # as directory, then fall back to displaying a 404.
    #try_files $uri $uri/ =404;
    index index.html index.htm index.php default.html default.htm default.php;
    }
  • Php type files’ deal process config

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    location ~ \.php$ {
    fastcgi_split_path_info ^(.+\.php)(/.+)$;
    # # NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini
    #
    # # With php5-cgi alone:
    # fastcgi_pass 127.0.0.1:9000;
    # # With php5-fpm:
    fastcgi_pass unix:/var/run/php5-fpm.sock;
    fastcgi_index index.php;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    include fastcgi_params;
    }

If php no this config, script may not work.
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;

5. Restart & Test

1
2
3
4
sudo /etc/init.d/nginx restart
sudo /etc/init.d/php5-fpm restart
sudo nginx restart
sudo php5-fpm restart

try request this script in browser
<?php phpinfo(); ?>