Report this

What is the reason for this report?

Running Rails & PHP on same Ubuntu 20.04

Posted on January 12, 2021

I have a droplet which I have Ubuntu 20.04 (LTS) x64, Nginx, and passenger. Currently, I’m running a Rails app in it. I was wondering how and if I’m able to run Rails alongside PHP script on the same server.

What I’m looking for is to have Rails app in domain.com and the PHP as domain.com/php-here

Thanks in advance



This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Hi @rubioli,

You’ll need to configure this in your domain’s Nginx configuration file. You can add something like the following to make your configuration work:

  location /php-folder {

    try_files $uri $uri/ /index.php;

    # process PHP here
    location ~* ^/(.*\.php)$ {
      # directives to process PHP
    }
  }

If you just want to proccess .php files in your main folder, you can just add the following

    # process PHP here
    location ~* ^/(.*\.php)$ {
      # directives to process PHP
    }

In your main location block.

Regards, KFSys

Thanks a lot @KFSys do I need to add this is the same ngnix config file I have for my rails? and what do I need to add in the directives to process PHP?

Thanks in advance!

With my user I did sudo vim /etc/nginx/sites-enabled/domainname

and I have:

server {
  listen 80;
  listen [::]:80;

  server_name domain.com;
  root /home/deploy/domain/current/public;

  passenger_enabled on;
  passenger_app_env production;

  location /cable {
    passenger_app_group_name lustsnaps_websocket;
    passenger_force_max_concurrent_requests_per_process 0;
  }

  # Allow uploads up to 100MB in size
  client_max_body_size 200m;

  location ~ ^/(assets|packs) {
    expires max;
    gzip_static on;
  }
    # process PHP here
   location /php {

    try_files $uri $uri/ /index.php;

    # process PHP here
    location ~* ^/(.*\.php)$ {
      # directives to process PHP
    }
  }
}

Is this what you mean?

The developer cloud

Scale up as you grow — whether you're running one virtual machine or ten thousand.

Get started for free

Sign up and get $200 in credit for your first 60 days with DigitalOcean.*

*This promotional offer applies to new accounts only.