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.

I have been trying to get lithium running with Nginx with no success. The directory structure of lithium is like this

lithium
  |-> app libraries .htaccess
      |-> webroot .htacess --other directories
           |-> index.php .htaccess --other files

I copied the lithium folder into my /var/www/. The path of lithium is /var/www/lithium/

Now I set up the rewrite rules this way in my nginx.conf

server {
        listen       80;
        server_name  localhost;
        root /var/www/;

    location /lithium {
       rewrite ^/$ /app/webroot/ break;
       rewrite ^(.*)$ /app/webroot/$1 break;
    }

    location /lithium/app {
       rewrite ^/$ /webroot/ break;
       rewrite ^(.*)$ /webroot/$1 break;
     }

    location /lithium/app/webroot {
       if (!-e $request_filename){
        rewrite ^(.*)$ /index.php?url=$1 break;
        }
     }
 ...then my php and other configurations

But nginx always throws a 404 error. Why is that happening?

I also tried this

server {
            listen       80;
            server_name  localhost;
            root /var/www/;

location /lithium {
        if (!-e $request_filename) {
            rewrite ^/lithium/(.+)$ /lithium/app/webroot/$1 last;
            break;
            }
        }

        location /lithium/app/webroot {
        if (!-e $request_filename) {
            rewrite ^/lithium/app/webroot/(.+)$ /lithium/app/webroot/index.php?url=$1 last;
            break;
        }
    }
...then my php and other configurations

But again there is a 404 error.

Edit

As suggested i changed my server's root to /var/www/lithium/app/webroot so my nginx conf looks like this

server {
        listen   80;
        server_name localhost;

        root   /var/www/lithium/app/webroot;
        access_log /var/log/lithium/access.log;
        error_log /var/log/lithium/error.log warn;

        index  index.php index.html;

        try_files $uri $uri/ /index.php?$args;

        location ~ \.php$
        {
          .. ...
           ......

}

now i can see lithium's home but when i go to lithium's test dashboard which is http://localhost/test it again shows lithium's home instead of the test dashboard.When i use apache and go to url http://localhost/test it shows me the test dashboard. So the nginx rewrite rules are still not completely correct.More if i point root to lithium's webroot i cannot access other directories in my /var/www/

EDITED AGIAN

This is my complete server block

server { 
    server_name  lithium;
    root   /var/www/lithium/app/webroot;
    access_log  /var/log/nginx/lith.access.log;
    error_log   /var/log/nginx/lith.error.log;

    listen       127.0.0.2:80;
    rewrite_log on;

    # rewrite rules for lithium
    location / {
            index  index.php index.html;

            try_files $uri $uri/ /index.php?url=$uri&$args;
    }


    location ~ \.php$ {
            fastcgi_pass 127.0.0.1:9000;
            fastcgi_index index.php;
            fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
            #include /etc/nginx/fastcgi_params;
            fastcgi_param SERVER_NAME $host;
    }

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

I am using php 5.4.3. as php-fpm. I tried doing whats mentioned at lithium's official site here but i dont get this line

cp -f sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm

which location is sapi referring to? Any ideas?

share|improve this question

migrated from stackoverflow.com May 16 '12 at 17:23

This question came from our site for professional and enthusiast programmers.

    
Can you paste the PHP configuration block (and any files included in there)? –  mgorven May 18 '12 at 23:54

4 Answers 4

It'd be simpler to just point to webroot using root /var/www/lithium/app/webroot.

Or you can do the following.

root /var/www

then use try_files instead of ugly if's:

index  index.php index.html;

location ~ \.php$ {
    ...
}

location lithium/app/webroot/ {
    try_files $uri $uri/ /lithium/app/webroot/index.php?$args;
}

location /lithium/app/ {
    rewrite ^/lithium/app/(.*)$ /lithium/app/webroot/$1;
}

location /lithium/ {
    rewrite ^/lithium/(.*)$ /lithium/app/webroot/$1;
}

location / {
    rewrite ^(.*)$ /lithium/app/webroot/$1;
}

Don't forget to protect the other directories.

share|improve this answer
    
I did as above and now i can see lithium's home but when i go to lithium's test dashboard which is http://localhost/test it again shows lithium's home instead of the test dashboard.When i use apache and go to url http://localhost/test it shows me the test dashboard So the rewrite rules are still not comletely correct.More if i point root to lithium's webroot i cannot access other directories in my /var/www/ –  lovesh May 16 '12 at 13:05
    
I've edited it, can you try? –  greut May 16 '12 at 20:15
    
I tried as you suggested but now the url http://localhost/test gives a 404 error –  lovesh May 16 '12 at 21:25
    
I changed it, and mostly removed the break which prevent it from going into try_files I guess. –  greut May 17 '12 at 9:45
    
changing to the above rewrite rules gives 500 error –  lovesh May 17 '12 at 10:00
try_files $uri $uri/ /index.php?$args;

You aren't passing the URI through to Lithium -- you're appending the query string, which is empty. You probably want the following:

try_files $uri $uri/ /index.php?url=$uri&$args;

Assuming that Lithium expects to be called with index.php?uri=/test (which is what your original configuration implies).

Edit: The Lithium wiki does suggest the top try_files line, which implies that it inspects the FastCGI variables to determine the URL to serve.

share|improve this answer

I think you are not setting the path correct. Try running just a basic nginx config: http://lithify.me/docs/manual/configuration/servers/nginx.wiki

Turning on php errors can also be helpful. Configuration errors like setting the path to the lithium libraries are not obvious unless you have php errors turn on.

share|improve this answer
    
How do i get it running under localhost? –  lovesh May 16 '12 at 8:01
    
@lovesh: nginx needs fastcgi to run php files, look at the location ~ \.php$ part in the lithium manual example that cgarvis linked to. –  Oerd May 16 '12 at 9:26
    
here is the nginx wiki page for configuring fastcgi with nginx wiki.nginx.org/PHPFcgiExample –  Oerd May 16 '12 at 9:47
    
@Oerd my problem is not running php with nginx. I am able to do that. The problem is with rewrite rules –  lovesh May 16 '12 at 10:36
#include /etc/nginx/fastcgi_params;

You're not including the configuration file which sets most of the FastCGI variables passed to PHP, so Lithium is probably not able to determine which URL is being requested. Uncomment this line and move it above the SCRIPT_FILENAME line so that your block looks like this:

location ~ \.php$ {
        fastcgi_pass 127.0.0.1:9000;
        fastcgi_index index.php;
        include /etc/nginx/fastcgi_params;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_param SERVER_NAME $host;
}
share|improve this answer
    
i uncommented that line but same 404 error. Also in the url bar it show the url http://lithium/lithium/test for the test dashboard. I manually changed the url to http://lithium/test but still the 404 error –  lovesh May 19 '12 at 0:07

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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