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?
It'd be simpler to just point to webroot using
root /var/www/lithium/app/webroot
.Or you can do the following.
then use
try_files
instead of uglyif
's:Don't forget to protect the other directories.
You aren't passing the URI through to Lithium -- you're appending the query string, which is empty. You probably want the following:
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.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.
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: