Contents that posted a long time ago may be obsolete and may not reflect my current opinion.

百度来的教程都是源码编译安装,对于我这种强迫症人群来说简直是不得已才会采用的方案,于是果断自己尝试使用 apt-get 安装 Nginx + PHP 运行环境。


Update apt.

sudo apt-get update
sudo apt-get upgrade


Install Nginx, PHP7.0, and PHP-FPM.

sudo apt-get install nginx
sudo apt-get install php7.0 php7.0-fpm

Alternatively, you may also install PHP-CGI.

sudo apt-get install php7.0-cgi


Configure Nginx.

sudo nano /etc/nginx/sites-available/default

Note: /etc/nginx/nginx.conf has already included all files in sites-enabled folder, so create another config file if you wanna setup a new vhost.

Here we use PHP-FPM, so uncomment those lines:

location ~ \.php$ {
include snippets/fastcgi-php.conf;
# With php-fpm (or other unix sockets):
fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;
# With php-cgi (or other tcp sockets):

And do NOT forget to reload Nginx.

sudo nginx -s reload


Write some PHP codes to /var/www/html

echo "<?php phpinfo(); ?>" > /var/www/html/phpinfo.php

And test it. Open your browser and type: http://<YOUR_PI_IP>/phpinfo.php

It should return a response like this:

Enjoy PHP in your Raspberry Pi!


Here are some PHP projects that I found useful for your Pi. Hope you like it.


Pi Dashboard