• Benvenuti su RaspberryItaly!
Benvenuto ospite! Login Login con Facebook Registrati Login with Facebook


Valutazione discussione:
  • 0 voto(i) - 0 media
  • 1
  • 2
  • 3
  • 4
  • 5

[-]
Tags
installare web php5 con server php supporto nginx

[Tutorial] Installare nginx+php5 (Web Server con supporto PHP)
#1
Di cosa si tratta?

nginx (pronunciato "engine x") è un webserver, un software che, detto in parole povere, permette di creare un sito web sul Raspberry. PHP è un'estensione che permettte ad nginx di elaborare anche le pagine PHP (acronimo (ricorsivo) di PHP: Hypertext PreProcessor, un linguaggio di programmazione web)
Bello... ma abbiamo già Apache!
La peculiarità di nginx che lo rende perfetto al nostro piccolo Raspberry è che è molto più leggero e questo è un gran vantaggio, visto che sia a livello di CPU che di RAM il Raspberry è limitato.
Installazione
L'installazione è divisa in due parti: l'installazione di nginx e l'installazione di PHP.
nginx
Apriamo un terminale e digitiamo i seguenti comandi, controllando sempre l'output e rispondendo ad eventuali richieste dei programmi


Codice:
$ sudo apt-get install nginx $ sudo /etc/init.d/nginx start

Ok, nginx è installato. Potete visualizzare il sito appena creato usando un browser e andando all'indirizzo


Codice:
http://<indirizzo ip del Raspberry>/

[Immagine: nginx-welcome-300x76.png]
N.B.: la cartella in cui sono presenti i file serviti da nginx è /usr/share/nginx/www
Tuttavia per poter modificare i file ivi presenti, dovete prima dare i seguenti comandi


Codice:
$ cd /usr/share/nginx/ $ sudo chown -R pi:pi www $ sudo chmod -R 775 www

php
Come per nginx, installiamo il relativo pacchetto:


Codice:
$ sudo apt-get install php5-fpm

Ora dobbiamo attivare il supporto a PHP dentro nginx, per fare questo dobbiamo per prima cosa modificare un file. Usando l'editor  nano diamo il seguente comando:


Codice:
$ sudo nano /etc/nginx/sites-available/default

Otterrete la seguente schermata
[Immagine: nano-300x234.png]
Scorrete verso il basso (con le frecce o col tasto PagGiu) fino a incontrare la riga che recita


Codice:
index index.html index.htm;


Sostituitela con la riga seguente (occhio al punto e virgola finale):

Codice:
index index.php index.html index.htm;

Ora  scorrete ancora e individuate le seguenti righe:


Codice:
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000 # # location ~ \.php$ { # fastcgi_split_path_info ^(.+\.php)(/.+)$; # # NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini # # # With php5-cgi alone: # fastcgi_pass 127.0.0.1:9000; # # With php5-fpm: # fastcgi_pass unix:/var/run/php5-fpm.sock; # fastcgi_index index.php; # include fastcgi_params; # }


Dovete togliere il simbolo di "#"  iniziale alle righe evidenziate in blu. Il risultato deve essere il seguente:


Codice:
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000 # location ~ \.php$ { fastcgi_split_path_info ^(.+\.php)(/.+)$; # # NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini # # # With php5-cgi alone: # fastcgi_pass 127.0.0.1:9000; # With php5-fpm: fastcgi_pass unix:/var/run/php5-fpm.sock; fastcgi_index index.php; include fastcgi_params; }


Mi raccomando togliete il "#" anche alla parentesi graffa finale!

Ora riavviamo il webserver nginx col comando
Codice:
$ sudo /etc/init.d/nginx restart

Creiamo una pagina PHP di esempio
Codice:
$ echo "<?php phpinfo(); ?>" > /usr/share/nginx/www/informazioni.php

Adesso non ci resta che testare la nostra installazione. Aprite un browser e digitate


Codice:
http://<indirizzo ip del Raspberry>/informazioni.php

Dovreste ottenere una pagina simile alla seguente (ovviamente con contenuto diverso, essendo questa la pagina info di un server Ubuntu con Apache2)
[Immagine: php-282x300.png]
 


bobvann
"Il sapere umano appartiene al mondo"
Founder (CEO) RaspberryItaly.com
Risposta
#2
Bug 
non va, il file è diverso

Codice:
## # You should look at the following URL's in order to grasp a solid understanding # of Nginx configuration files in order to fully unleash the power of Nginx. # http://wiki.nginx.org/Pitfalls # http://wiki.nginx.org/QuickStart # http://wiki.nginx.org/Configuration # # Generally, you will want to move this file somewhere, and start with a clean # file but keep this around for reference. Or just disable in sites-enabled. # # Please see /usr/share/doc/nginx-doc/examples/ for more detailed examples. ## # Default server configuration # server { listen 80 default_server; listen [::]:80 default_server; # SSL configuration # # listen 443 ssl default_server; # listen [::]:443 ssl default_server; # # Self signed certs generated by the ssl-cert package # Don't use them in a production server! # # include snippets/snakeoil.conf; root /var/www/html; # Add index.php to the list if you are using PHP index index.php index.html index.htm index.nginx-debian.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 listening on 127.0.0.1:9000 # location ~ \.php$ { include snippets/fastcgi-php.conf; # # # With php5-cgi alone: @ fastcgi_pass 127.0.0.1:9000; # # With php5-fpm: fastcgi_pass unix:/var/run/php5-fpm.sock; } # deny access to .htaccess files, if Apache's document root # concurs with nginx's one # #location ~ /\.ht { # deny all; #} } # Virtual Host configuration for example.com # # You can move that to a different file under sites-available/ and symlink that # to sites-enabled/ to enable it. # #server { # listen 80; # listen [::]:80; # # server_name example.com; # # root /var/www/example.com; # index index.html; # # location / { # try_files $uri $uri/ =404; # } #}
Heart Libro  | Blog EnricoSartori.it | Idea YouTube
Se un utente ti è stato utile, aumenta la sua reputazione! premi il Pollicione! 
Risposta
  


Vai al forum:


Navigazione: 2 Ospite(i)
Forum con nuovi Post
Forum senza nuovi post
Forum bloccato
Forum Redirect