Question

Running Rails & PHP on same Ubuntu 20.04

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


Submit an answer

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!

Sign In or Sign Up to Answer

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.

Want to learn more? Join the DigitalOcean Community!

Join our DigitalOcean community of over a million developers for free! Get help and share knowledge in Q&A, subscribe to topics of interest, and get courses and tools that will help you grow as a developer and scale your project or business.

Hi @rubioli,

Let’s edit that conf a little bit. In the locatio /php/ you should add the following line

try_files $uri $uri/ /index.php;

Additionally, you need to add the .php location where you are processing your files added to the above location block.

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

  server_name mydomain.com;

  location / {
    root /home/deploy/mydomain/current/public;

    passenger_enabled on;
    passenger_app_env production;
  }
  location /cable {
    passenger_app_group_name mydomain_websocket;
    passenger_force_max_concurrent_requests_per_process 0;
  }

  location ~ ^/(assets|packs) {
    expires max;
    gzip_static on;
  }

  location /php/ {
    root /var/www/html/php;
    # Tested with this as well
    #root /home/deploy/php;

    index index.php;
    passenger_enabled off;
    location ~ \.php$ {
       try_files $uri =404;
       fastcgi_split_path_info ^(.+\.php)(/.+)$;
       fastcgi_pass unix:/var/run/php5-fpm.sock;
       fastcgi_index index.php;
       fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
       include fastcgi_params;
    }

  }

}

I appreciate your help @KFSys.

I added only

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

and in my public folder in rails I added a info.php file, and when I visit that, it just downloads the file and doesn’t show anything :/

I also did the following:

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

  server_name mydomain.com;

location / {
 root /home/deploy/mydomain/current/public;

  passenger_enabled on;
  passenger_app_env production;
}
  location /cable {
    passenger_app_group_name mydomain_websocket;
    passenger_force_max_concurrent_requests_per_process 0;
  }

  location ~ ^/(assets|packs) {
    expires max;
    gzip_static on;
  }

location /php/ {
 root /var/www/html/php;
  # Tested with this as well
  #root /home/deploy/php;

index index.php;
 passenger_enabled off;
}

location ~ \.php$ {
       try_files $uri =404;
       fastcgi_split_path_info ^(.+\.php)(/.+)$;
       fastcgi_pass unix:/var/run/php5-fpm.sock;
       fastcgi_index index.php;
       fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
       include fastcgi_params;
}

And when I visit HTTP://mydomain.com/php/index.php I get a 404 page

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?