Reputation: 6749
I am facing the following issue to start a Rails application with Apache - Passenger in Azure platform (CentOS):
App 18106 stdout:
App 18106 stderr: Rails Error:
Unable to access log file. Please ensure that /path/to/production.log exists and is writable (ie, make it writable for user and group: chmod 0664 /path/to/production.log).
The log level has been raised to WARN and the output directed to STDERR until the problem is fixed.
App 18106 stdout:
[ 2017-06-19 11:37:13.5635 18014/7f7826db7700 age/Cor/App/Implementation.cpp:304 ]: Could not spawn process for application /var/www/my_rails_app: An error occurred while starting up the preloader.
Error ID: f684beca
Error details saved to: /tmp/passenger-error-JB9Dio.html
Message from application: could not connect to server: Permission denied
Is the server running on host "localhost" (::1) and accepting
TCP/IP connections on port 5432?
could not connect to server: Permission denied
Is the server running on host "localhost" (127.0.0.1) and accepting
TCP/IP connections on port 5432?
(PG::ConnectionBad)
/usr/local/rvm/gems/ruby-2.3.1/gems/activerecord-4.2.7.1/lib/active_record/connection_adapters/postgresql_adapter.rb:654:in `initialize'
/usr/local/rvm/gems/ruby-2.3.1/gems/activerecord-4.2.7.1/lib/active_record/connection_adapters/postgresql_adapter.rb:654:in `new'
/usr/local/rvm/gems/ruby-2.3.1/gems/activerecord-4.2.7.1/lib/active_record/connection_adapters/postgresql_adapter.rb:654:in `connect'
/usr/local/rvm/gems/ruby-2.3.1/gems/activerecord-4.2.7.1/lib/active_record/connection_adapters/postgresql_adapter.rb:242:in `initialize'
I have tried chmod 0664 /path/to/production.log
but nothing changed in the error as specified above.
The same setup is working fine in AWS.
Apache conf.d
files:
/etc/httpd/conf.d/my_app.conf:
<VirtualHost *:80>
ServerName localhost
DocumentRoot /var/www
ErrorLog logs/rails_app_error_log
<Directory "/var/www/">
Allow from all
Options -MultiViews
</Directory>
Alias /my_rails_app /var/www/my_rails_app/public/
<Location /my_rails_app>
PassengerBaseURI /my_rails_app
PassengerAppRoot /var/www/my_rails_app
</Location>
<Directory /var/www/my_rails_app/public/ >
Options Indexes ExecCGI FollowSymLinks MultiViews
Order allow,deny
Allow from all
AllowOverride all
</Directory>
<IfModule mod_passenger.c>
PassengerUser apache
PassengerGroup apache
</IfModule>
</VirtualHost>
/etc/httpd/conf.d/passenger.conf:
LoadModule passenger_module /usr/lib64/httpd/modules/mod_passenger.so
<IfModule mod_passenger.c>
PassengerRoot /usr/local/rvm/gems/ruby-2.3.1/gems/passenger-5.1.2
PassengerDefaultRuby /usr/local/rvm/gems/ruby-2.3.1/wrappers/ruby
</IfModule>
I have also set chown -R apache:apache my_rails_app
.
Note: If I run Passenger in standalone mode without using Apache, then everything works just fine.
I have searched all other relevant posts and tried to avoid the could not connect to server: Permission denied
in the log, but nothing seems to be working.
I think the issue was with SElinux and issue got resolved after running the following command:
/usr/sbin/setsebool -P httpd_can_network_connect 1
Upvotes: 4
Views: 4728
Reputation: 24138
Accoring to the Passenger offical troubleshooting The Rails application reports that it's unable to start because of a permission error
for Passenger + Apache and Ruby
, I think the issue was caused by the permissions of your Rails application's directory.
So please first check the owner of your apache process via ps -ef|grep apache
, then to check the owner & group ownership of your Rails application's directory via ls -l <path of rails>
, as below.
$ ps -ef |grep apache
root 7226 1 0 16:10 ? 00:00:00 /usr/sbin/apache2 -k start
www-data 7229 7226 0 16:10 ? 00:00:00 /usr/sbin/apache2 -k start
www-data 7230 7226 0 16:10 ? 00:00:00 /usr/sbin/apache2 -k start
<user> 7756 30915 0 16:12 pts/2 00:00:00 grep --color=auto apache
$ ls -l
total 4
drwxrwxr-x 13 <user> <group> 4096 Jun 20 16:22 myrails
Then try to change the owner & group ownership of your Rails application's directory with root
or www-data
via chown -R <OWNER>:<GROUP> myrails
with root
or www-data
.
And as reference, there is a similar SO thread What permissions are needed for apache Passenger which you can refer to.
Hope it helps.
Upvotes: 1
Reputation: 3002
Run
chmod 777 <directory_with_logs>
This will give you execute/read/write privileges for whole dir. It possible that problem is with directory, not the file.
You can play with the numbers further to finely tune app.
Upvotes: 0