Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

So I can't remember what I did, but for some reason I cannot get PHP to be parsed anymore. What would be the basic troubleshooting steps to check on this? I have php5 installed and nginx running but when I, for example, create a phpinfo page, the raw php is displayed on the website. I'd like to know how to really 'activate' php and make sure it can make a successful connection with nginx to serve up pages with php content. I am referring to a linux CLI environment, in case that was unclear.

share|improve this question

closed as not a real question by SvW, MadHatter, Michael Hampton, Khaled, mgorven Mar 20 '13 at 16:27

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.If this question can be reworded to fit the rules in the help center, please edit the question.

add comment

3 Answers

nginx doesn't have built in support for PHP, as Apache does via mod_php.

To get PHP scripts running you should research the use of FPM.

share|improve this answer
add comment

You need to check you have all the relevant packages installed. It might be that you accidentally deleted something, or missed something.

Try cleaning up, and starting again.

Check out this link, it has the basic packages and set up required to get you started again

share|improve this answer
add comment

nginx doesn't bundle itself with PHP support. To "enable" PHP, you have to let your webserver know how to handle the packages. This is where PHP-FPM comes in.

Using whatever package manager is appropriate for your OS, install FPM (e.g. apt-get install php5-fpm), give it a configuration file, then reload nginx.

Here's my /etc/nginx/nginx.conf to get you started:

user  nginx;
worker_processes  1;
pid        /var/run/nginx.pid;

events {
    worker_connections  768;
}

http {
    include       /etc/nginx/mime.types;
    default_type  application/octet-stream;

    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';

    access_log  /var/log/nginx/access.log  main;
    access_log  /var/log/nginx/error.log  main;

    sendfile                on;
    tcp_nopush              on;
    tcp_nodelay             on;

    keepalive_timeout  10;
    types_hash_max_size 2048;
    server_tokens off;

    ssl_session_cache       shared:SSL:10m;
    ssl_session_timeout     10m;
    ssl_ciphers     HIGH:!aNULL:!MD5;
    ssl_prefer_server_ciphers on;

        open_file_cache          max=5000  inactive=20s;
        open_file_cache_valid    30s;
        open_file_cache_min_uses 2;
        open_file_cache_errors   on;

    #php cache
    #mkdir /var/cache/nginx; chown nginx:nginx /var/cache/nginx;
    #consider doing a tmpfs if memory allows - VPS disk speed is hardly robust
    fastcgi_cache_path /var/cache/nginx levels=1:2 keys_zone=microcache:10m max_size=1000m inactive=60m;

    #consider turning off if CPU thrashing
    gzip  on;
    gzip_static on;
    gzip_disable "msie6";
    gzip_http_version 1.1;
    gzip_vary on;
    gzip_comp_level 6;
    gzip_proxied any;
    gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript application/javascript text/x-js;
    gzip_buffers 16 8k;

    include /etc/nginx/conf.d/*.conf;
    include /etc/nginx/sites-enabled/*;
}
share|improve this answer
add comment

Not the answer you're looking for? Browse other questions tagged or ask your own question.