1 *Example virtual host configurations for popular web servers*
8 - Shaarli is installed in a directory readable/writeable by the user
9 - the correct read/write permissions have been granted to the web server _user and/or group_
11 - a key pair (public, private) and a certificate have been generated
12 - the appropriate server SSL extension is installed and active
14 ### HTTPS, TLS and self-signed certificates
17 - [How to Create Self-Signed SSL Certificates with OpenSSL](http://www.xenocafe.com/tutorials/linux/centos/openssl/self_signed_certificates/index.php)
18 - [How do I create my own Certificate Authority?](https://workaround.org/certificate-authority)
19 - Generate a self-signed certificate (will trigger browser warnings) with apache2:
20 `make-ssl-cert generate-default-snakeoil --force-overwrite` will create `/etc/ssl/certs/ssl-cert-snakeoil.pem` and `/etc/ssl/private/ssl-cert-snakeoil.key`
23 If Shaarli is served behind a proxy (i.e. there is a proxy server between clients and the web server hosting Shaarli), please refer to the proxy server documentation for proper configuration. In particular, you have to ensure that the following server variables are properly set:
29 See also [proxy-related](https://github.com/shaarli/Shaarli/issues?utf8=%E2%9C%93&q=label%3Aproxy+) issues.
35 ServerName shaarli.my-domain.org
36 DocumentRoot /absolute/path/to/shaarli/
39 ### Debug - Log all the things!
40 This configuration will log both Apache and PHP errors, which may prove useful to identify server configuration errors.
44 - [Apache/PHP - error log per VirtualHost](http://stackoverflow.com/q/176) (StackOverflow)
45 - [PHP: php_value vs php_admin_value and the use of php_flag explained](https://ma.ttias.be/php-php_value-vs-php_admin_value-and-the-use-of-php_flag-explained/)
49 ServerName shaarli.my-domain.org
50 DocumentRoot /absolute/path/to/shaarli/
53 ErrorLog /var/log/apache2/shaarli-error.log
54 CustomLog /var/log/apache2/shaarli-access.log combined
56 php_flag log_errors on
57 php_flag display_errors on
58 php_value error_reporting 2147483647
59 php_value error_log /var/log/apache2/shaarli-php-error.log
63 ### Standard - Keep access and error logs
66 ServerName shaarli.my-domain.org
67 DocumentRoot /absolute/path/to/shaarli/
70 ErrorLog /var/log/apache2/shaarli-error.log
71 CustomLog /var/log/apache2/shaarli-access.log combined
75 ### Paranoid - Redirect HTTP (:80) to HTTPS (:443)
76 See [Server-side TLS](https://wiki.mozilla.org/Security/Server_Side_TLS#Apache) (Mozilla).
80 ServerName shaarli.my-domain.org
81 DocumentRoot /absolute/path/to/shaarli/
84 SSLCertificateFile /absolute/path/to/the/website/certificate.pem
85 SSLCertificateKeyFile /absolute/path/to/the/website/key.key
87 <Directory /absolute/path/to/shaarli/>
89 Options Indexes FollowSymLinks MultiViews
95 ErrorLog /var/log/apache2/shaarli-error.log
96 CustomLog /var/log/apache2/shaarli-access.log combined
99 ServerName shaarli.my-domain.org
100 Redirect 301 / https://shaarli.my-domain.org
103 ErrorLog /var/log/apache2/shaarli-error.log
104 CustomLog /var/log/apache2/shaarli-access.log combined
110 Shaarli use `.htaccess` Apache files to deny access to files that shouldn't be directly accessed (datastore, config, etc.). You need the directive `AllowOverride All` in your virtual host configuration for them to work.
112 **Warning**: If you use Apache 2.2 or lower, you need [mod_version](https://httpd.apache.org/docs/current/mod/mod_version.html) to be installed and enabled.
114 Apache module `mod_rewrite` **must** be enabled to use the REST API. URL rewriting rules for the Slim microframework are stated in the root `.htaccess` file.
120 Nginx does not natively interpret PHP scripts; to this effect, we will run a [FastCGI](https://en.wikipedia.org/wiki/FastCGI) service, to which Nginx's FastCGI module will proxy all requests to PHP resources.
124 - [nginx](http://nginx.org)
125 - [php-fpm](http://php-fpm.org) - PHP FastCGI Process Manager
127 Official documentation:
129 - [Beginner's guide](http://nginx.org/en/docs/beginners_guide.html)
130 - [ngx_http_fastcgi_module](http://nginx.org/en/docs/http/ngx_http_fastcgi_module.html)
131 - [Pitfalls](http://wiki.nginx.org/Pitfalls)
135 - [Server-side TLS (Nginx)](https://wiki.mozilla.org/Security/Server_Side_TLS#Nginx) (Mozilla)
136 - [PHP configuration examples](http://kbeezie.com/nginx-configuration-examples/) (Karl Blessing)
139 Once Nginx and PHP-FPM are installed, we need to ensure:
141 - Nginx and PHP-FPM are running using the _same user and group_
142 - both these user and group have
143 - `read` permissions for Shaarli resources
144 - `execute` permissions for Shaarli directories _AND_ their parent directories
146 On a production server:
148 - `user:group` will likely be `http:http`, `www:www` or `www-data:www-data`
149 - files will be located under `/var/www`, `/var/http` or `/usr/share/nginx`
151 On a development server:
153 - files may be located in a user's home directory
154 - in this case, make sure both Nginx and PHP-FPM are running as the local user/group!
156 For all following configuration examples, this user/group pair will be used:
158 - `user:group = john:users`,
160 which corresponds to the following service configuration:
163 ; /etc/php/php-fpm.conf
173 # /etc/nginx/nginx.conf
181 ### (Optional) Increase the maximum file upload size
182 Some bookmark dumps generated by web browsers can be _huge_ due to the presence of Base64-encoded images and favicons, as well as extra verbosity when nesting links in (sub-)folders.
184 To increase upload size, you will need to modify both nginx and PHP configuration:
187 # /etc/nginx/nginx.conf
192 client_max_body_size 10m;
199 # /etc/php5/fpm/php.ini
204 upload_max_filesize = 10M
208 _WARNING: Use for development only!_
214 worker_connections 1024;
219 default_type application/octet-stream;
220 keepalive_timeout 20;
222 index index.html index.php;
226 server_name localhost;
229 access_log /var/log/nginx/access.log;
230 error_log /var/log/nginx/error.log;
233 try_files $uri /shaarli/index.php$is_args$args;
234 access_log /var/log/nginx/shaarli.access.log;
235 error_log /var/log/nginx/shaarli.error.log;
238 location ~ (index)\.php$ {
240 fastcgi_split_path_info ^(.+\.php)(/.+)$;
241 fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock;
242 fastcgi_index index.php;
243 include fastcgi.conf;
250 The previous setup is sufficient for development purposes, but has several major caveats:
252 - every content that does not match the PHP rule will be sent to client browsers:
253 - dotfiles - in our case, `.htaccess`
254 - temporary files, e.g. Vim or Emacs files: `index.php~`
255 - asset / static resource caching is not optimized
256 - if serving several PHP sites, there will be a lot of duplication: `location /shaarli/`, `location /mysite/`, etc.
258 To solve this, we will split Nginx configuration in several parts, that will be included when needed:
261 # /etc/nginx/deny.conf
263 # deny access to dotfiles
270 # deny access to temp editor files, e.g. "script.php~"
278 # /etc/nginx/php.conf
279 location ~ (index)\.php$ {
280 # Slim - split URL path into (script_filename, path_info)
282 fastcgi_split_path_info ^(.+\.php)(/.+)$;
284 # filter and proxy PHP requests to PHP-FPM
285 fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock;
286 fastcgi_index index.php;
287 include fastcgi.conf;
291 # deny access to all other PHP scripts
297 # /etc/nginx/static_assets.conf
298 location ~* \.(?:ico|css|js|gif|jpe?g|png)$ {
300 add_header Pragma public;
301 add_header Cache-Control "public, must-revalidate, proxy-revalidate";
306 # /etc/nginx/nginx.conf
313 access_log /var/log/nginx/access.log;
314 error_log /var/log/nginx/error.log;
317 # virtual host for a first domain
319 server_name my.first.domain.org;
322 # Slim - rewrite URLs
323 try_files $uri /shaarli/index.php$is_args$args;
325 access_log /var/log/nginx/shaarli.access.log;
326 error_log /var/log/nginx/shaarli.error.log;
329 location = /shaarli/favicon.ico {
330 # serve the Shaarli favicon from its custom location
331 alias /var/www/shaarli/images/favicon.ico;
335 include static_assets.conf;
340 # virtual host for a second domain
342 server_name second.domain.com;
345 access_log /var/log/nginx/minigal.access.log;
346 error_log /var/log/nginx/minigal.error.log;
350 include static_assets.conf;
356 ### Redirect HTTP to HTTPS
357 Assuming you have generated a (self-signed) key and certificate, and they are
358 located under `/home/john/ssl/localhost.{key,crt}`, it is pretty straightforward
359 to set an HTTP (:80) to HTTPS (:443) redirection to force SSL/TLS usage.
362 # /etc/nginx/nginx.conf
368 index index.html index.php;
371 access_log /var/log/nginx/access.log;
372 error_log /var/log/nginx/error.log;
376 server_name localhost;
378 return 301 https://localhost$request_uri;
383 server_name localhost;
385 ssl_certificate /home/john/ssl/localhost.crt;
386 ssl_certificate_key /home/john/ssl/localhost.key;
389 # Slim - rewrite URLs
390 try_files $uri /index.php$is_args$args;
392 access_log /var/log/nginx/shaarli.access.log;
393 error_log /var/log/nginx/shaarli.error.log;
396 location = /shaarli/favicon.ico {
397 # serve the Shaarli favicon from its custom location
398 alias /var/www/shaarli/images/favicon.ico;
402 include static_assets.conf;