0

I'm trying to setup rails 3.0.10 on a Ubuntu VPS server. I'm using postgres 9.0.4, Apache and passenger. When I run my server I get this error:

PGError could not connect to server: No such file or directory Is the server running locally and accepting connections on Unix domain socket "/var/run/postgresql/.s.PGSQL.5432"?

Naturally, the postgres server is runing and if I do 'rails server' the app works great with webbrick.

During installation I installed Postgres and Apache as root, while I installed ruby and rails using rvm as another user. Could that be it?

What is the proper way to install a production server, in terms of linux users? Install everything as root or creating a deployer account and installing postgres, apache and passenger with sudo or maybe even without sudo?

Any suggestions? Not too many good tutorials on production server setup/conf. Know one?

BR

  • Is the production server chroot'ed ? Or the production apache? Please provide the relevant parts of the configuration files. – Thomas Berger Aug 20 '11 at 03:01

3 Answers3

1

Check your config/database.yml, the development and production environment might have different DB settings.

Remember to create the database in production env(RailsEnv), or just copy the credentials under development section to production section in config/database.yml

Installing PG & Apache as root is nothing wrong, that's the right way to protect these programs.

RoR and rvm can be installed as non-root users, create another user for Apache and passenger, use 'sudo' to start Apache.

Make sure the user you setup for Apache has access to logs and uploading directory.

inntran
  • 171
  • 3
  • My .yml is correct, my DB is created, tables migrated. Apache as well as postgres are started as root (not sudo) during boot (I havent changed any startup config). I'm not a linux admin, what is the "right" way to install as, what is the "right" way to start post gres and apache? and with what users? – Rutger Karlsson Aug 19 '11 at 23:52
  • can you provide the output of ` netstat -an|grep LISTEN ps -Af|grep postgres ps -Af|grep httpd ` Apache would get itself a lower privilege after startup. POSTGRES should be able to run as non-root users. The default configuration in Ubuntu works, I think. – inntran Aug 20 '11 at 04:32
0

I set the postgres log to log on info and I see nothing when I browse the page. WHen playing around in PGAdmin I see stuff in the log. I realize httpd is run as root but postgres as user postgres. Rails is installed as user rutger who only belongs to group rutger.

netstat -an|grep LISTEN

tcp        0      0 0.0.0.0:80              0.0.0.0:*               LISTEN
tcp        0      0 0.0.0.0:10000           0.0.0.0:*               LISTEN
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN
tcp        0      0 0.0.0.0:5432            0.0.0.0:*               LISTEN
tcp        0      0 127.0.0.1:34533         0.0.0.0:*               LISTEN
tcp6       0      0 :::22                   :::*                    LISTEN
tcp6       0      0 :::5432                 :::*                    LISTEN
unix  2      [ ACC ]     STREAM     LISTENING     239555   /tmp/.s.PGSQL.5432
unix  2      [ ACC ]     STREAM     LISTENING     6067     /tmp/passenger.1.0.863/generation-0/spawn-server/socket.876.74943570
unix  2      [ ACC ]     STREAM     LISTENING     6079     /tmp/passenger.1.0.863/generation-0/backends/ruby.<Rutger edited: long key>
unix  2      [ ACC ]     STREAM     LISTENING     6002     /tmp/passenger.1.0.863/generation-0/socket
unix  2      [ ACC ]     STREAM     LISTENING     6006     /tmp/passenger.1.0.863/generation-0/spawn-server/socket.874.163492224
unix  2      [ ACC ]     STREAM     LISTENING     6034     /tmp/passenger.1.0.863/generation-0/logging.socket
unix  2      [ ACC ]     STREAM     LISTENING     5164     /var/run/dbus/system_bus_socket
unix  2      [ ACC ]     STREAM     LISTENING     5934     /var/run/apache2/cgisock.863
unix  2      [ ACC ]     STREAM     LISTENING     3960     @/com/ubuntu/upstart

>ps -Af|grep postgres
postgres  4946     1  0 16:11 pts/0    00:00:00 /opt/postgres/9.0/bin/postgres -D /opt/postgres/9.0/data
postgres  4947  4946  0 16:11 ?        00:00:00 postgres: logger process        
postgres  4949  4946  0 16:11 ?        00:00:00 postgres: writer process        
postgres  4950  4946  0 16:11 ?        00:00:00 postgres: wal writer process    
postgres  4951  4946  0 16:11 ?        00:00:00 postgres: autovacuum launcher process
postgres  4952  4946  0 16:11 ?        00:00:00 postgres: stats collector process
postgres  5012  4946  0 16:13 ?        00:00:00 postgres: postgres postgres 127.0.0.1(58641) idle
postgres  5013  4946  0 16:14 ?        00:00:00 postgres: postgres rktest_production 127.0.0.1(58642) idle
postgres  5023  4946  0 16:14 ?        00:00:00 postgres: postgres rktest_production 127.0.0.1(58643) idle
postgres  5038  4946  0 16:15 ?        00:00:00 postgres: postgres rktest_production 127.0.0.1(58644) idle
root      5274 31100  0 16:22 pts/0    00:00:00 grep --color=auto postgres

>ps -Af|grep httpd
root      5423 31100  0 16:27 pts/0    00:00:00 grep --color=auto httpd
0

Thats it!!!

The "http://www.openscg.org/se/postgresql/packages.jsp" installation of Postgresql 9.0.4 will put the .s.PGSQL.5432 file in /tmp instead of /var/run/postgresql on ubuntu and probably debian as well.

Quick and dirty solution is:

ln -s /tmp postgresql

Anybody know how it should really be fixed?