Add new comment

Jak nainstalovat NGINX + PHP-FPM na Raspberry Pi

Připravili jsme pro vás další jednoduchý návod jak nainstalovat webový server Nginx s PHP-FPM v Raspbian. Trvá to jen několik minut připravit Raspberry Pi ke spuštění vašich webových stránek.

1. Proveďte Update/upgrade a poté je dobrým zvykem nainstalovat synchronizaci času a postfix

root@raspberrypi:~# apt-get update && apt-get -y upgrade
root@raspberrypi:~# apt-get install postfix ntp ntpdate

2. Nainstalujte NGINX, PHP-FPM a APC cache

root@raspberrypi:~# apt-get install nginx php5-fpm php-apc

3. Nainstalute MySQL server a PHPMyAdmin jestli je potřeba

root@raspberrypi:~# apt-get install mysql-client mysql-server php5-mysql phpmyadmin

4. Přidejte skupinu a uživatele pro vaši doménu. První uid a gid je 10000 další +1, adresář pro umístění vašich stránek bude v /home/. V tomto příkladu mydomain.com

root@raspberrypi:~# addgroup --gid 10000 group001
root@raspberrypi:~# adduser --home /home/mydomain.com --shell /dev/null --uid 10000 --gid 10000 --disabled-password --disabled-login --gecos '' user001

5. Vytvořte strukturu adresářů

root@raspberrypi:~# mkdir /home/mydomain.com/logs       # pro Nginx logy
root@raspberrypi:~# mkdir /home/mydomain.com/logs/php/  # pro PHP logy
root@raspberrypi:~# mkdir /home/mydomain.com/www        # pro vaše www stránky
root@raspberrypi:~# mkdir /home/mydomain.com/tmp        # pro tempy
root@raspberrypi:~# mkdir /home/mydomain.com/sessions   # pro sessions
root@raspberrypi:~# chown -R user001:group001 /home/mydomain.com/

6. Zkopírujte www.conf do mydomain.com.conf a upravte konfiguraci dle návodu

root@raspberrypi:~# cp /etc/php5/fpm/pool.d/www.conf  /etc/php5/fpm/pool.d/mydomain.com.conf
root@raspberrypi:~# nano /etc/php5/fpm/pool.d/mydomain.com.conf
; pool name ('www' here)
[mydomain.com]
...
; Unix user/group of processes
user = user001
group = group001
...
; The address on which to accept FastCGI requests.
listen = /var/run/php5-fpm-mydomain.com.sock
...
; Set permissions for unix socket, if one is used. In Linux, read/write
listen.owner = user001
listen.group = group001
listen.mode = 0666
...
; Default Value: nothing is defined by default except the values in php.ini ...
; add php.ini admin values
php_admin_value[sendmail_path] = /usr/sbin/sendmail -t -i -f noreply@mydomain.com
php_flag[display_errors] = off
php_admin_value[error_log] = /home/mydomain.com/logs/php/fpm-php.www.log
php_admin_flag[log_errors] = on
php_admin_value[upload_tmp_dir] = /home/mydomain.com/tmp
php_admin_value[session.save_path] = /home/mydomain.com/sessions
php_admin_value[open_basedir] = /home/mydomain.com/www:/home/mydomain.com/tmp:/home/mydomain.com/sessions
php_admin_value[mail.log] = /home/mydomain.com/logs/mail.log
php_admin_value[memory_limit] = 64M
php_admin_value[post_max_size] = 18M
php_admin_value[max_execution_time] = 60
php_admin_value[allow_url_fopen] = Off
php_admin_value[upload_max_filesize] = 18M
php_admin_value[date.timezone] = Europe/Prague

Advertisement:

Do you need more power than RPi?

7. Zastate NGINX a PHP-FPM službu. Smažte symbolický odkaz na výchozí vhost.

root@raspberrypi:~# service nginx stop && service php5-fpm stop
root@raspberrypi:~# unlink /etc/nginx/sites-enabled/default

8. Vytvořte nový NGINX configuraci pro svou doménu dle návodu.

root@raspberrypi:~# nano /etc/nginx/sites-available/mydomain.com.conf
# redirect www
server {
        listen 80;
        server_name www.mydomain.com;
        return 301 $scheme://mydomain.com$request_uri;
}
server {
        listen   80; ## listen for ipv4
 
        # root dir of your pages
        root /home/mydomain.com/www/;
 
        index index.php index.html index.htm;
 
        server_name mydomain.com;
 
        location / {
                try_files $uri $uri/ /index.html;
        }
 
        # pass the PHP scripts to FastCGI
        location ~ \.php$ {
                try_files $uri = 404;
                fastcgi_split_path_info ^(.+\.php)(/.+)$;
                # php5-fpm :
                fastcgi_pass unix:/var/run/php5-fpm-mydomain.com.sock;
                fastcgi_index index.php;
                include fastcgi_params;
        }
 
        # deny access to .htaccess files, if Apache's document root concurs with nginx's one
        location ~ /\.ht {
                deny all;
        }
 
        # error and access logs
        error_log /home/mydomain.com/logs/nginx-error.log crit;
        access_log /home/mydomain.com/logs/nginx-access.log;
 
        # other converting rewrite rules search on:
        # http://nginx.org/en/docs/http/converting_rewrite_rules.html
        #
 
}

9. Vytvořte soubor index.php ve Vašem webovém domovském adresáři a vložte funkci phpinfo dle návodu.

root@raspberrypi:~# nano /home/mydomain.com/www/index.php
<?php phpinfo(); ?>

10. Vytvořte symbolický odkaz a restartujte Nginx a php5-fpm

root@raspberrypi:~# ln -s /etc/nginx/sites-available/mydomain.com /etc/nginx/sites-enabled/
root@raspberrypi:~# service nginx restart && service php5-fpm restart
Restarting nginx: nginx.
[ ok ] Restarting PHP5 FastCGI Process Manager: php5-fpm.

11. Hotovo!

Rasberry Pi Raspbian NGINX PHP5-FPM