andreknieriem / photobooth

A photobooth Web-Application for raspberry pi with gphoto2
https://photobooth.andrerinas.de/
MIT License
295 stars 163 forks source link

Prefer nginx over Apache httpd / nginx instructions #177

Closed rawbertp closed 4 years ago

rawbertp commented 4 years ago

Is your feature request related to a problem? Please describe. No problem but I suggest to replace Apache httpd installation instructions/requirements by nginx. Nginx has a smaller memory footprint and typically better performance, which is especially important on the Raspberry Pis.

Describe the solution you'd like

  1. Move the installation instructions from the Wiki to the README.md. This would allow others to contribute.
  2. Describe how to install/configure nginx and php-fpm. This is quite straight-forward and a task of 2-5 minutes. :)

Describe alternatives you've considered

One could also provide a howto for both httpd and nginx but I would suggest to make nginx default for reasons mentioned above.

Additional context

andi34 commented 4 years ago

I'd suggest keeping the instructions in the wiki. We moved everything out of the README for a better documentation. If you like you can tell the instructions here and we can add it to the wiki if a decision is made.

Thanks for your contributions 🙂

Edit: You could also clone the wiki and push the changes to your GitHub and link them here, so we can cherry-pick your changes.

andi34 commented 4 years ago

Could look like this in the wiki, based on the instructions here: https://www.raspberrypi.org/documentation/remote-access/web-server/nginx.md.

Install a Webserver

Currently Apache and NGINX Webserver are supported. NGINX has a smaller memory footprint and typically better performance, which is especially important on the Raspberry Pis, but it needs some additional steps until you're good to go.

Install Apache & PHP

sudo apt install -y libapache2-mod-php

or Install NGINX & PHP

sudo apt install -y nginx php-fpm
Additional needed steps for NGINX Now we need to start the server with: ``` sudo /etc/init.d/nginx start ``` Once NGINX is installed we need to enable PHP in NGINX: ``` sudo nano /etc/nginx/sites-enabled/default ``` Find the line `index index.html index.htm;` and add `index.php` after `index` (the line now should look like this: `index index.php index.html index.htm;`). Now scroll down until you find a section with the following content: ``` # pass the PHP scripts to FastCGI server # # location ~ \.php$ { ``` Edit by removing the `#` characters on the following lines: ``` location ~ \.php$ { include snippets/fastcgi-php.conf; fastcgi_pass unix:/run/php/php7.3-fpm.sock; } ``` It should look like this: ``` location ~ \.php$ { include snippets/fastcgi-php.conf; # # # With php-fpm (or other unix sockets): fastcgi_pass unix:/run/php/php7.3-fpm.sock; # # With php-cgi (or other tcp sockets): # fastcgi_pass 127.0.0.1:9000; } ``` Now we need to restart the server with: ``` sudo /etc/init.d/nginx restart ```

Install dependencies

sudo apt install -y git php-gd gphoto2
andi34 commented 4 years ago

Quick tested with nginx on a fresh Raspbian Buster image, followed the instructions above. Works fine so far.

andi34 commented 4 years ago

Added to the instruction: https://github.com/andreknieriem/photobooth/wiki/Installation-on-Debian/_compare/6accec5fe65e654b229c75e421f6d5a88149789c...be6f075ae317836a31b671755b55ee136822b1ec

Any idea for the installation script to use NGINX by default?

rawbertp commented 4 years ago

The following sed commands will uncomment the corresponding lines:

sed -i 's/^\(\s*\)index index\.html\(.*\)/\1index index\.php index\.html\2/g' /etc/nginx/sites-available/default
sed -i '/location ~ \\.php$ {/s/^\(\s*\)#/\1/g' /etc/nginx/sites-available/default
sed -i '/include snippets\/fastcgi-php.conf/s/^\(\s*\)#/\1/g' /etc/nginx/sites-available/default
sed -i '/fastcgi_pass unix:\/run\/php\//s/^\(\s*\)#/\1/g' /etc/nginx/sites-available/default
sed -i '/.*fastcgi_pass unix:\/run\/php\//,// { /}/s/^\(\s*\)#/\1/g; }' /etc/nginx/sites-available/default

BTW this is how I tested it: https://github.com/rawbertp/photobooth-nginx-script-test

andi34 commented 4 years ago

Thanks :) I'll see if I find time in the evening to test it too

rawbertp commented 4 years ago

One thing probably worth mentioning - this has only been tested on the happy path, i.e. a vanilla nginx installation (on Debian Buster). It may not work/cause issues if the user already did manual changes himself or for other distributions which ship with another config (structure).

I would also recommend to take a backup of the original file before applying any changes.

And finally (before reloading nginx) I would suggest to test the config:

/usr/sbin/nginx -t -c /etc/nginx/nginx.conf &>/dev/null && echo 'config test ok' || echo 'config test failed'
root@81b37c6626c9:/# /usr/sbin/nginx -t -c /etc/nginx/nginx.conf
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
root@81b37c6626c9:/# echo $?
0
root@81b37c6626c9:/#
root@81b37c6626c9:/# echo nonsense >> /etc/nginx/nginx.conf
root@81b37c6626c9:/# /usr/sbin/nginx -t -c /etc/nginx/nginx.conf
nginx: [emerg] unexpected end of file, expecting ";" or "}" in /etc/nginx/nginx.conf:87
nginx: configuration file /etc/nginx/nginx.conf test failed
root@81b37c6626c9:/# echo $?
1
andi34 commented 4 years ago

Raspberry Pi4, 4GB

NGINX

Applied Antique Filter

{success: "image", file: "cb9517914ba5c9f5737994ca610b9881.jpg", time: 2.4943900108337402}
core.js:257 picture processed 
{file: "cb9517914ba5c9f5737994ca610b9881.jpg", time: {…}}
file: "cb9517914ba5c9f5737994ca610b9881.jpg"
time:
chroma: 0.7251811027526855
filter: 2.015481948852539a
image: 0.46349191665649414
polaroid: 0.0000059604644775390625
thumb: 0.23497796058654785****

2nd one with NGINX, Applied Antique Filter

{success: "image", file: "e45680c5f28cf6b59478768fe228c673.jpg", time: 1.8362641334533691}
core.js:257 picture processed 
{file: "e45680c5f28cf6b59478768fe228c673.jpg", time: {…}}
file: "e45680c5f28cf6b59478768fe228c673.jpg"
time:
chroma: 0.6933839321136475
filter: 1.9205820560455322
image: 0.45045018196105957
polaroid: 0.0000030994415283203125
thumb: 0.23052406311035156

No filter applied

{success: "image", file: "4bf784216520484b17be9f73677e3693.jpg", time: 1.7270090579986572}
core.js:257 picture processed 
{file: "4bf784216520484b17be9f73677e3693.jpg", time: {…}}
file: "4bf784216520484b17be9f73677e3693.jpg"
time:
chroma: 0.7118780612945557
filter: 0.000010013580322265625
image: 0.4691948890686035
polaroid: 0.0000019073486328125
thumb: 0.2908461093902588

Apache2

Applied Antique Filter

{success: "image", file: "9ef622bf8677db9d683d4af4856f3497.jpg", time: 2.3593690395355225}
core.js:257 picture processed 
{file: "9ef622bf8677db9d683d4af4856f3497.jpg", time: {…}}
file: "9ef622bf8677db9d683d4af4856f3497.jpg"
time:
chroma: 0.6960411071777344
filter: 1.914086103439331
image: 0.4502990245819092
polaroid: 0.0000050067901611328125
thumb: 0.229841947555542

2nd with apache2, Applied Antique Filter

{success: "image", file: "a97e757e6e213382ebfdf9503a7d4df1.jpg", time: 2.051651954650879}
core.js:257 picture processed 
{file: "a97e757e6e213382ebfdf9503a7d4df1.jpg", time: {…}}
file: "a97e757e6e213382ebfdf9503a7d4df1.jpg"
time:
chroma: 0.6931698322296143
filter: 1.905850887298584
image: 0.44994401931762695
polaroid: 0.00000286102294921875
thumb: 0.23006701469421387

No filter applied

{success: "image", file: "03f43af8af78c07a1bceb80b8fc96c1c.jpg", time: 1.8909170627593994}
core.js:257 picture processed 
{file: "03f43af8af78c07a1bceb80b8fc96c1c.jpg", time: {…}}
file: "03f43af8af78c07a1bceb80b8fc96c1c.jpg"
time:
chroma: 0.7397301197052002
filter: 0.000012159347534179688
image: 0.507641077041626
polaroid: 0.0000019073486328125
thumb: 0.26639294624328613
andi34 commented 4 years ago

there's a small difference, even if it is not that big. on both the first picture takes some more time, while every picture after that is a little faster done.

rawbertp commented 4 years ago

Thanks for performing these tests. What would be also/especially interesting are memory (RAM) and CPU utilization.

andi34 commented 4 years ago

Ordered 2 more MicroSD cards so I don't have to format the same card many times a day ;)

Can tell more next days.