Openresty use LUA and PHP together

2,223 views
Skip to first unread message

Abdul Rahman Madeni

unread,
Jul 31, 2014, 9:05:13 PM7/31/14
to openre...@googlegroups.com
Hi

I am developing an application that requires two languages running together, LUA and PHP. The config for nginx.conf is given below:

  #lua
  location / {
     root app;
     try_files $uri $uri/ @api;
  }

  #php
        location ~ \.php$ {
                try_files $uri =404;
                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 did installation php-fpm before and i follow every step accordingly. I run LUA (curl localhost) but failed to run PHP (curl localhost/php) which should display any output.

Need your help.

Yichun Zhang (agentzh)

unread,
Aug 1, 2014, 4:37:24 PM8/1/14
to openresty-en
Hello!

On Thu, Jul 31, 2014 at 6:05 PM, Abdul Rahman Madeni wrote:
>
> I did installation php-fpm before and i follow every step accordingly. I run
> LUA (curl localhost) but failed to run PHP (curl localhost/php) which should
> display any output.
>

This looks like a configuration mistake in your ngx_fastcgi or php-fpm
configurations, which is more related to the standard nginx modules
and your php-fpm configurations (or installations). Try providing more
details here. (And yes, in my experiences, php-fpm + ngx_fastcgi has
always been painful to set up properly on my side.)

Regards,
-agentzh

Abdul Rahman Madeni

unread,
Aug 4, 2014, 2:29:16 AM8/4/14
to openre...@googlegroups.com
Hi agentzh

Luckily the config below was success to tun both LUA and PHP together using OpenResty. But need your a little help especially when URL directs to http://xxxx.com/php that keeps browser looking for the index.php or index.html. However, http://xxxx.com/php/index.php or http://xxxx.com/php/index.html was OK. Putting another files also OK such as http://xxxx.com/php/getDate.php.




worker_processes 2;
error_log logs/error.log info;
events {
  worker_connections  256;
}
worker_rlimit_nofile 8192;

http {
  default_type  application/octet-stream;
  types {
    text/html html;
    text/css css;
    image/jpeg jpeg jpg;
    image/gif gif;
    application/javascript js;
  }
  access_log off;

  lua_package_path "$prefix/api/?.lua;;";
  init_by_lua_file "api/core/init.lua";
  lua_shared_dict templates 10m;

  server {
    listen 80;
    lua_code_cache off;
    client_max_body_size    100m;
    client_body_buffer_size 1m; 
    root /home/project/Dev;
    index index.php index.html;

    location / {
      root /home/project/Dev/app;
      try_files $uri $uri/ @api;
    }   

    location @api {
      default_type "application/json; charset=UTF-8";
      content_by_lua 'app.run()';
    }

   //for php
    location ~ \.php$ {
    fastcgi_split_path_info ^(.+\.php)(/.+)$;
    fastcgi_pass 127.0.0.1:9000;
        fastcgi_index index.php;
    include /opt/openresty/nginx/conf/fastcgi_params;
    fastcgi_param    SCRIPT_FILENAME    $document_root$fastcgi_script_name;
    }
  }
}





--
You received this message because you are subscribed to a topic in the Google Groups "openresty-en" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/openresty-en/jUfJIWdtxns/unsubscribe.
To unsubscribe from this group and all its topics, send an email to openresty-en...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages