Install Piwigo Gallery On Nginx With Debian Wheezy
This tutorial shows how you can install and run a piwigo gallery site with nginx, configured for vhosts, on a Debian Wheezy system. Piwigo is a gallery-website with many plugins.
In this sample we configure the vhost “gallery.domain.tld”.
Install
Install packages for nginx
apt-get install nginx php5-fpm php5 php5-mysql php5-pgsql php5-imap php-pear php5-sqlite php5-ldap php5-gd php5-imagick php5-curl php-apc
apt-get install php5-mcrypt php5-pspell php5-xmlrpc php5-xsl php5-cgi php-auth php-auth-sasl php-net-smtp
Install MySQL Server
apt-get install mysql-server
Configure Nginx
Delete default site (optional)
rm -f /etc/nginx/sites-enabled/default
Create template-file for vhosts
cd /etc/nginx/sites-available/
touch template-with-ssl
touch template
Vhost with ssl-support
Insert following to file
nano /etc/nginx/sites-available/template-with-ssl
server {
listen 80;
# .domain.com will match both domain.com and anything.domain.com
server_name www.domain.tld domain.tld;
rewrite ^ https://$ server_name$ request_uri? permanent;
# It is best to place the root of the server block at the server level, and not the location level
# any location block path will be relative to this root.
root /var/www/www.domain.tld;
# It's always good to set logs, note however you cannot turn off the error log
# setting error_log off; will simply create a file called 'off'.
access_log /var/log/nginx/example.access.log;
error_log /var/log/nginx/example.error.log;
# This can also go in the http { } level
index index.html index.htm index.php;
location / {
# if you're just using wordpress and don't want extra rewrites
# then replace the word @rewrites with /index.php
try_files $ uri $ uri/ @rewrites;
}
location @rewrites {
# Can put some of your own rewrite rules in here
# for example rewrite ^/~(.*)/(.*)/? /users/$ 1/$ 2 last;
# If nothing matches we'll just send it to /index.php
rewrite ^ /index.php last;
}
# This block will catch static file requests, such as images, css, js
# The ?: prefix is a 'non-capturing' mark, meaning we do not require
# the pattern to be captured into $ 1 which should help improve performance
location ~* \.(?:ico|css|js|gif|jpe?g|png)$ {
# Some basic cache-control for static files to be sent to the browser
expires max;
add_header Pragma public;
add_header Cache-Control "public, must-revalidate, proxy-revalidate";
}
# remove the robots line if you want to use wordpress' virtual robots.txt
location = /robots.txt { access_log off; log_not_found off; }
location = /favicon.ico { access_log off; log_not_found off; }
# this prevents hidden files (beginning with a period) from being served
location ~ /\. { access_log off; log_not_found off; deny all; }
location ~ \.php {
fastcgi_param SCRIPT_NAME $ fastcgi_script_name;
fastcgi_param SCRIPT_FILENAME $ document_root$ fastcgi_script_name;
fastcgi_index index.php;
fastcgi_pass unix:/var/run/php5-fpm.sock;
include fastcgi_params;
}
}
# just, if you want to use ssl-vhost
server {
listen 443 default ssl;
# .domain.com will match both domain.com and anything.domain.com
server_name www.domain.tld domain.tld;
ssl_certificate /etc/nginx/ssl/www.domain.tld.crt;
ssl_certificate_key /etc/nginx/ssl/www.domain.tld.key;
# It is best to place the root of the server block at the server level, and not the location level
# any location block path will be relative to this root.
root /var/www/www.domain.tld;
# It's always good to set logs, note however you cannot turn off the error log
# setting error_log off; will simply create a file called 'off'.
access_log /var/log/nginx/example.access.log;
error_log /var/log/nginx/example.error.log;
# This can also go in the http { } level
index index.html index.htm index.php;
location / {
# if you're just using wordpress and don't want extra rewrites
# then replace the word @rewrites with /index.php
try_files $ uri $ uri/ @rewrites;
}
location @rewrites {
# Can put some of your own rewrite rules in here
# for example rewrite ^/~(.*)/(.*)/? /users/$ 1/$ 2 last;
# If nothing matches we'll just send it to /index.php
rewrite ^ /index.php last;
}
# This block will catch static file requests, such as images, css, js
# The ?: prefix is a 'non-capturing' mark, meaning we do not require
# the pattern to be captured into $ 1 which should help improve performance
location ~* \.(?:ico|css|js|gif|jpe?g|png)$ {
# Some basic cache-control for static files to be sent to the browser
expires max;
add_header Pragma public;
add_header Cache-Control "public, must-revalidate, proxy-revalidate";
}
# remove the robots line if you want to use wordpress' virtual robots.txt
location = /robots.txt { access_log off; log_not_found off; }
location = /favicon.ico { access_log off; log_not_found off; }
# this prevents hidden files (beginning with a period) from being served
location ~ /\. { access_log off; log_not_found off; deny all; }
location ~ \.php {
fastcgi_param SCRIPT_NAME $ fastcgi_script_name;
fastcgi_param SCRIPT_FILENAME $ document_root$ fastcgi_script_name;
fastcgi_index index.php;
fastcgi_pass unix:/var/run/php5-fpm.sock;
include fastcgi_params;
}
}
Vhost for HTTP only
nano /etc/nginx/sites-available/template
server {
listen 80;
# .domain.com will match both domain.com and anything.domain.com
server_name www.domain.tld domain.tld;
rewrite ^ https://$ server_name$ request_uri? permanent;
# It is best to place the root of the server block at the server level, and not the location level
# any location block path will be relative to this root.
root /var/www/www.domain.tld;
# It's always good to set logs, note however you cannot turn off the error log
# setting error_log off; will simply create a file called 'off'.
access_log /var/log/nginx/rugia.access.log;
error_log /var/log/nginx/rugia.error.log;
# This can also go in the http { } level
index index.html index.htm index.php;
location / {
# if you're just using wordpress and don't want extra rewrites
# then replace the word @rewrites with /index.php
try_files $ uri $ uri/ @rewrites;
}
location @rewrites {
# Can put some of your own rewrite rules in here
# for example rewrite ^/~(.*)/(.*)/? /users/$ 1/$ 2 last;
# If nothing matches we'll just send it to /index.php
rewrite ^ /index.php last;
}
# This block will catch static file requests, such as images, css, js
# The ?: prefix is a 'non-capturing' mark, meaning we do not require
# the pattern to be captured into $ 1 which should help improve performance
location ~* \.(?:ico|css|js|gif|jpe?g|png)$ {
# Some basic cache-control for static files to be sent to the browser
expires max;
add_header Pragma public;
add_header Cache-Control "public, must-revalidate, proxy-revalidate";
}
# remove the robots line if you want to use wordpress' virtual robots.txt
location = /robots.txt { access_log off; log_not_found off; }
location = /favicon.ico { access_log off; log_not_found off; }
# this prevents hidden files (beginning with a period) from being served
location ~ /\. { access_log off; log_not_found off; deny all; }
location ~ \.php {
fastcgi_param SCRIPT_NAME $ fastcgi_script_name;
fastcgi_param SCRIPT_FILENAME $ document_root$ fastcgi_script_name;
fastcgi_index index.php;
fastcgi_pass unix:/var/run/php5-fpm.sock;
include fastcgi_params;
}
}
Create first vhost
Use template
cp /etc/nginx/sites-available/template /etc/nginx/sites-available/gallery.domain.tld
Edit path-variables
nano /etc/nginx/sites-available/gallery.domain.tld
server_name gallery.domain.tld;
root /var/www/gallery.domain.tld;
access_log /var/log/nginx/gallery.access.log;
error_log /var/log/nginx/gallery.error.log;
Create your directory-structure
mkdir -p /var/www/gallery.domain.tld
chown -R www-data:www-data /var/www
Enable your vhost
ln -s /etc/nginx/sites-available/gallery.domain.tld /etc/nginx/sites-enabled/gallery.domain.tld
Now restart services:
/etc/init.d/php5-fpm restart
/etc/init.d/nginx restart
Test PHP
Create a test file with phpinfo:
nano /var/www/gallery.domain.tld/test.php
<?php
phpinfo();
?>
For quick test purposes just edit the hosts file with vhost name;
in this sample the IP of the server is 192.168.1.10:
192.168.1.10 gallery.domain.tld
Now open your browser and navigate to:
http://gallery.domain.tld
If you see an informational page about the installed php version, everything is ok
now you can delete your test file:
rm -f nano /var/www/gallery.domain.tld/test.php
Configure Piwigo
Create database & user
username: gallery01
password: PASSWORD
Connect to MySQL:
mysql -u root -p
create database gallery01;
grant all on gallery01.* to ‘gallery’@'localhost’ identified by ‘PASSWORD’;
flush privileges;
\q;
Download netinstall-file for piwigo
cd /var/www/gallery.domain.tld
wget http://piwigo.org/download/dlcounter.php?code=netinstall
mv dlcounter.php\?code\=netinstall netinstall.php
chown www-data:www-data netinstall.php
Configuration tweaks
nano /etc/php5/fpm/php.ini
upload_tmp_dir = /tmp
upload_max_filesize = 20M
max_file_uploads = 20
nano /etc/nginx/nginx.conf
client_max_body_size 20M;
client_body_buffer_size 128k;
Don’t forget to restart services:
/etc/init.d/php5-fpm restart
/etc/init.d/nginx restart
Use webinstaller
Open browser and navigate to:
http://gallery.domain.tld/netinstall.php
Install Piwigo Gallery On Nginx With Debian Wheezy
Install Piwigo Gallery On Nginx With Debian Wheezy