Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Raspberry Pi PHP7, Nginx 1.9 Installer
if [ "$EUID" -ne 0 ]
then echo "Must be root"
apt-get update -y
apt-get upgrade -y
apt-get dist-upgrade -y
apt-get install -y rpi-update
apt-get install -y php7.0 php7.0-curl php7.0-gd php7.0-fpm php7.0-cli php7.0-opcache php7.0-mbstring php7.0-xml php7.0-zip
apt-get install -y nginx-full
update-rc.d nginx defaults
update-rc.d php7.0-fpm defaults
cat > /etc/nginx/sites-enabled/default << "EOF"
# Default server configuration
server {
listen 80 default_server;
listen [::]:80 default_server;
root /var/www/public;
index index.html index.htm index.php default.html;
server_name _;
location / {
# First attempt to serve request as file, then
# as directory, then fall back to displaying a 404.
try_files $uri $uri/ =404;
# pass the PHP scripts to FastCGI server
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/run/php/php7.0-fpm.sock;
# deny access to .htaccess files, should an Apache document root conflict with nginx
location ~ /\.ht {
deny all;
mkdir -p /var/www/{public,private,logs,backup,vhosts}
echo "<?php phpinfo();" > /var/www/public/index.php
chown -R www-data:www-data /var/www
chmod -R 775 /var/www
usermod -aG www-data pi
service nginx restart
service php7.0-fpm restart
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment