Pomoc - Szukaj - Użytkownicy - Kalendarz
Pełna wersja: PHP5 + Nginx pobiera pliki .php zamiast ich odtwarzać.
Forum PHP.pl > Forum > Serwery WWW
Gruchol
Witam,
Mam taki problem ponieważ mam VPS na ubuntu i zainstalowałem tam MYSQL + Nginx + PHP5.
Strona wszystko ładnie śmiga tylko zamiast odtwarzać pliki .php ten je pobiera.
Wiecie może jak to rozwiązać ?
by_ikar
Pokaż konfigurację vhostów.
ohm
Cytat(Gruchol @ 28.11.2014, 17:44:21 ) *
Wiecie może jak to rozwiązać ?

Tak smile.gif
Gruchol
Cytat(by_ikar @ 28.11.2014, 18:50:30 ) *
Pokaż konfigurację vhostów.

Możesz powiedzieć dokładnie który plik ? W ubuntu siedzę od wczoraj.
by_ikar
Kod
ls -l /etc/nginx/sites-enabled/


wylistuje ci listę wszystkich symlinków które będą wskazywały na "vhsoty" które masz włączone.
Gruchol
Wpisałem to do konsoli i wyskoczyło takie coś :
lrwxrwxrwx 1 root root 34 Nov 28 13:31 default -> /etc/nginx/sites-available/default
@Edit
Takie coś mam jak wpiszę top : http://wklej.org/id/1541605/
by_ikar
Więc twój default w katalogu sites-available jest twoim vhostem, przeklej jego zawartość. top to jest taki odpowiednik menadżera zadań z windowsa, więc nie musisz pokazywać co tam jest wink.gif
Gruchol
Cytat
# You may add here your
# server {
# ...
# }
# statements for each of your virtual hosts to this file

##
# 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.
##

server {
listen 80 default_server;
listen [::]:80 default_server ipv6only=on;

root /usr/share/nginx/html;
index index.html index.htm;

# Make site accessible from http://localhost/
server_name localhost;

location / {
# First attempt to serve request as file, then
# as directory, then fall back to displaying a 404.
try_files $uri $uri/ /index.html;
# Uncomment to enable naxsi on this location
# include /etc/nginx/naxsi.rules
}

location /doc/ {
alias /usr/share/doc/;
autoindex on;
allow 127.0.0.1;
allow ::1;
deny all;
}

# Only for nginx-naxsi used with nginx-naxsi-ui : process denied requests
#location /RequestDenied {
# proxy_pass http://127.0.0.1:8080;
#}

#error_page 404 /404.html;

# redirect server error pages to the static page /50x.html
#
#error_page 500 502 503 504 /50x.html;
#location = /50x.html {
# root /usr/share/nginx/html;
#}

# 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;
#}

# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}
}


# another virtual host using mix of IP-, name-, and port-based configuration
#
#server {
# listen 8000;
# listen somename:8080;
# server_name somename alias another.alias;
# root html;
# index index.html index.htm;
#
# location / {
# try_files $uri $uri/ =404;
# }
#}


# HTTPS server
#
#server {
# listen 443;
# server_name localhost;
#
# root html;
# index index.html index.htm;
#
# ssl on;
# ssl_certificate cert.pem;
# ssl_certificate_key cert.key;
#
# ssl_session_timeout 5m;
#
# ssl_protocols SSLv3 TLSv1;
# ssl_ciphers ALL:!ADH:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv3:+EXP;
# ssl_prefer_server_ciphers on;
#
# location / {
# try_files $uri $uri/ =404;
# }
#}
by_ikar
Odkomentuj ten kawałek:

Kod
# 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;
#}


Czyli powinno wyglądać to tak:

Kod
# 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;
}


I zresetuj nginxa:

Kod
sudo service nginx restart
Gruchol
Nadal pobiera plik .php :/
http://185.38.249.37/test.php
by_ikar
To jeszcze przeklej plik z tej lokalizacji:
Kod
/etc/nginx/fastcgi_params
Gruchol
Cytat
fastcgi_param QUERY_STRING $query_string;
fastcgi_param REQUEST_METHOD $request_method;
fastcgi_param CONTENT_TYPE $content_type;
fastcgi_param CONTENT_LENGTH $content_length;

fastcgi_param SCRIPT_FILENAME $request_filename;
fastcgi_param SCRIPT_NAME $fastcgi_script_name;
fastcgi_param REQUEST_URI $request_uri;
fastcgi_param DOCUMENT_URI $document_uri;
fastcgi_param DOCUMENT_ROOT $document_root;
fastcgi_param SERVER_PROTOCOL $server_protocol;

fastcgi_param GATEWAY_INTERFACE CGI/1.1;
fastcgi_param SERVER_SOFTWARE nginx/$nginx_version;

fastcgi_param REMOTE_ADDR $remote_addr;
fastcgi_param REMOTE_PORT $remote_port;
fastcgi_param SERVER_ADDR $server_addr;
fastcgi_param SERVER_PORT $server_port;
fastcgi_param SERVER_NAME $server_name;

fastcgi_param HTTPS $https;

# PHP only, required if PHP was built with --enable-force-cgi-redirect
fastcgi_param REDIRECT_STATUS 200;
by_ikar
Ahh sry mój błąd, tamten kawałek co odkomentowałeś, to odkomentowana jest o jedna linijka za dużo:

Kod
# 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;
}


EDIT: dobra, teraz widzę dlaczego tak to działa, spróbuj tego:

Kod
location ~* \.php$ {
    fastcgi_index  index.php;
    fastcgi_pass  127.0.0.1:9000;
    include  fastcgi_params;
    fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
    fastcgi_param  SCRIPT_NAME  $fastcgi_script_name;
}


Tzn podmień tamto wcześniejsze co odkomentowałeś i ofc zrestartuj jeszcze raz nginx'a.
Gruchol
Teraz mój vhost wygląda tak :
Cytat
# You may add here your
# server {
# ...
# }
# statements for each of your virtual hosts to this file

##
# 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.
##

server {
listen 80 default_server;
listen [::]:80 default_server ipv6only=on;

root /usr/share/nginx/html;
index index.html index.htm;

# Make site accessible from http://localhost/
server_name localhost;

location / {
# First attempt to serve request as file, then
# as directory, then fall back to displaying a 404.
try_files $uri $uri/ /index.html;
# Uncomment to enable naxsi on this location
# include /etc/nginx/naxsi.rules
}

location /doc/ {
alias /usr/share/doc/;
autoindex on;
allow 127.0.0.1;
allow ::1;
deny all;
}

# Only for nginx-naxsi used with nginx-naxsi-ui : process denied requests
#location /RequestDenied {
# proxy_pass http://127.0.0.1:8080;
#}

#error_page 404 /404.html;

# redirect server error pages to the static page /50x.html
#
#error_page 500 502 503 504 /50x.html;
#location = /50x.html {
# root /usr/share/nginx/html;
#}

location ~* \.php$ {
fastcgi_index index.php;
fastcgi_pass 127.0.0.1:9000;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param SCRIPT_NAME $fastcgi_script_name;
}

# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}
}


# another virtual host using mix of IP-, name-, and port-based configuration
#
#server {
# listen 8000;
# listen somename:8080;
# server_name somename alias another.alias;
# root html;
# index index.html index.htm;
#
# location / {
# try_files $uri $uri/ =404;
# }
#}


# HTTPS server
#
#server {
# listen 443;
# server_name localhost;
#
# root html;
# index index.html index.htm;
#
# ssl on;
# ssl_certificate cert.pem;
# ssl_certificate_key cert.key;
#
# ssl_session_timeout 5m;
#
# ssl_protocols SSLv3 TLSv1;
# ssl_ciphers ALL:!ADH:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv3:+EXP;
# ssl_prefer_server_ciphers on;
#
# location / {
# try_files $uri $uri/ =404;
# }
#}


I teraz wyświetla się takie coś :
http://185.38.249.37/test.php
Bad Gateway
A zawartość test.php to :
Cytat
<?php
phpinfo();
?>
by_ikar
Ok więc polećmy po kolei, edytuj ten plik:

Kod
/etc/php5/fpm/pool.d/www.conf


I upewnij się że
Kod
listen
ma taką wartość:

Kod
listen = /var/run/php5-fpm.sock


Jeżeli nie ma to podmień na tą i jeżeli podmieniasz to zrestartuj fpm'a:

Kod
sudo service php5-fpm restart


Następnie ten plik: /etc/nginx/sites-avaliable/default podmień jego zawartość na:

Kod
server {
    listen  80;

    root /usr/share/nginx/www;
    index index.php index.html index.htm;

    server_name  localhost;

    location / {
        try_files  $uri $uri/ /index.html;
    }

    location ~ \.php$ {
        try_files  $uri =404;
        fastcgi_pass  unix:/var/run/php5-fpm.sock;
        fastcgi_index  index.php;
        fastcgi_param  SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include  fastcgi_params;
    }

    location ~ /\.ht {
        deny all;
    }
}


Potem zrestartuj nginxa.
Gruchol
Czyli mam usunąć cały plik default i wkleić to co dałeś tak?
by_ikar
Tak. To jest w zasadzie prawie to samo, z tą różnicą że nie ma komentarzy.
Gruchol
W /etc/php5/fpm/pool.d/www.conf było ok.
Podmieniłem default i teraz jest takie coś :
Cytat
404 Not Found
nginx/1.4.1 (Ubuntu)
by_ikar
Document root jest niepoprawny, wydawało mi się że tam było www, a jednak u ciebie jest html.. wink.gif więc w tym pliku default: odnajdź:

Kod
root /usr/share/nginx/www;


podmień na:

Kod
root /usr/share/nginx/html;


i zrestartuj nginxa.
Gruchol
Wielkie dzięki działa super !
Tylko mam jeszcze jeden problemik tyle że teraz z czymś innym :X
Po instalacji phpmyadmina wyskakuje cały czas Welcome to nginx.
http://185.38.249.37/phpmyadmin
@Edit
Aha i jak instalowałem phpmyadmin i się pytało o apache czy lighttpd to kliknąłem ESC
by_ikar
Nie musisz instalować przecież phpmyadmina z pakietów, możesz go pobrać i wypakować do odpowiedniego katalogu. Generalnie, w sieci jest masa jakichś tutoriali, czy innych howto jak postawić i skonfigurować sobie cały serwer, więc IMO najpierw tam powinieneś szukać, bo możesz szybciej odpowiedź znaleźć.
Gruchol
Instalowałem już wcześniej phpmyadmina i było to samo.
Google pod hasłem ngnix php lub phpmyadmin jest już praktycznie cała fioletowa.
Poradniki do Nginx na prawdę bardzo ciężko znaleźć.
@Edit
Zainstalowałem phpmyadmin wrzucając go poprostu do katalogu z nginexem i wszystko jest ok tylko mam 2 błędy.
Plik konfiguracyjny wymaga teraz tajnej frazy kodującej (blowfish_secret).
Zmieniałem w config.sample.inc.php ciąg znaków w linijce z blowfish jednak nic to nie dało.
Poradzisz coś ?
by_ikar
Jeżeli szukasz czegoś w języku polskim, to fakt, możesz mieć problem, nie wiem osobiście jak to wygląda w języku polskim, bo od bardzo dawna nie szukam niczego odnośnie programowania poza językiem angielskim. I tobie też to osobiście radzę. Co do tego błędu, możesz przekopiować błąd ?
ohm
Konfiguracja do podpięcia phpmyadmina dystrybucyjnego jest dość banalna, bo wystarczy go zaliasować pod którąś wirtualką
Kod
        location /phpmyadmin {
                root /usr/share/;
                index index.php index.html index.htm;
                location ~ ^/phpmyadmin/(.+\.php)$ {
                        try_files $uri =404;
                        fastcgi_pass   unix:/var/run/php5-fpm.sock
                        include fastcgi_params;
                }
        }
Gruchol
Błąd wygląda tak :
http://screenshooter.net/100278775/jngglmo
Gruchol
A do jakiego pliku to wsadzić ?
Bo w głównym folderze mam tylko sample.config.inc.php a z tego co widzę trzeba do config.inc.php wsadzić :/
@Edit
Podmieniłem w sample.config.inc.php ale nic to nie dało nadal jest ten bład.
ohm
skopiuj sobie sample.config.inc.php na config.inc.php
Gruchol
Dzięki wielkie naprawiło się.
Tylko teraz mam jeszcze takie coś :
http://screenshooter.net/100278775/jxiwjjo
ohm
Prawdopodobnie musisz dorzucić bazę phpmyadmina oraz uprawnienia dla niego.
https://wiki.phpmyadmin.net/pma/Configuration_storage
Pyton_000
Kurna masz obok komunikatu link do dokumentacji. Czy Ty na prawdę masz jakieś problemy z czytaniem?
To jest wersja lo-fi głównej zawartości. Aby zobaczyć pełną wersję z większą zawartością, obrazkami i formatowaniem proszę kliknij tutaj.
Invision Power Board © 2001-2025 Invision Power Services, Inc.