Passenger 403 error - ruby-on-rails

I am trying to install passenger for my rails app, but I dont know where is the problem.
Fallow the files:
httpd.conf
LoadModule passenger_module /usr/local/lib/ruby/gems/2.1.0/gems/passenger-4.0.53/buildout/apache2/mod_passenger.so
<IfModule mod_passenger.c>
PassengerRoot /usr/local/lib/ruby/gems/2.1.0/gems/passenger-4.0.53
PassengerDefaultRuby /usr/local/bin/ruby
</IfModule>
<VirtualHost *:80>
ServerName www.yourhost.com
# !!! Be sure to point DocumentRoot to 'public'!
DocumentRoot /home/vagrant/shitatta/public
<Directory /home/vagrant/shitatta/public>
# This relaxes Apache security settings.
AllowOverride all
# MultiViews must be turned off.
Options -MultiViews
# Uncomment this if you're on Apache >= 2.4:
Require all granted
</Directory>
</VirtualHost>
error_log:
[Sun Feb 22 09:49:20 2015] [error] [client 192.168.33.1] (13)Permission denied: access to / denied
[Sun Feb 22 09:49:20 2015] [error] [client 192.168.33.1] (13)Permission denied: access to /favicon.ico denied

The user that execute passenger and the web server doesn't have access to
/home/vagrant/shitatta/public
You should in my opinion make some changes:
Login with your user (vagrant)
Create a directory /opt/web/
Copy your project in /opt/web/shitatta
Go to /opt/web
Change auth access like : chmod 755 shitatta/*
Change owner : chown -R vagrant:vagrant shitatta
Change your apache conf with new paths
Add your user to www-data adduser vagrant www-data or any other user that will use Apache
If you have a permission denied when you run command, add sudo before each command. In my opinion it's a mistake to store your website in your home folder.
You should read about rails :
What permissions are needed for apache Passenger

Related

Laradock virtual host not working on mac monterey apache2

I have read many posts on the subject but none refers to exactly the same environment I have (Mac OS Monterey). So what I have done so far...
I have successfully installed the latest versions of Docker & LaraDock with apache2. I have phpMyAdmin working fine at localhost:8081. Then I followed the docs and some tutorial to set up laradock for multiproject.
I successfuly created a laravel9 project (ProjectA) inside the workspace container. I can view the website in the browser at localhost/ProjectA/public.
I want to create a virtual host for ProjectA to be able to type projectA.test in the browser and point to localhost/ProjectA/public.
So again, I followed the instructions on Laradock and edited the laradock/apache2/sites/default.apache.conf
<VirtualHost *:80>
ServerName laradock.test
DocumentRoot /var/www/
Options Indexes FollowSymLinks
<Directory "/Users/Sites">
AllowOverride All
<IfVersion < 2.4>
Allow from all
</IfVersion>
<IfVersion >= 2.4>
Require all granted
</IfVersion>
</Directory>
ErrorLog /var/log/apache2/error.log
CustomLog /var/log/apache2/access.log combined
</VirtualHost>
and created a laradock/sites/projectA.conf
<VirtualHost *:80>
ServerName projectA.test
DocumentRoot /var/www/projectA/public
Options Indexes FollowSymLinks
<Directory "/var/www/projectA/public">
AllowOverride All
<IfVersion < 2.4>
Allow from all
</IfVersion>
<IfVersion >= 2.4>
Require all granted
</IfVersion>
</Directory>
</VirtualHost>
Even after restarting apache2 in Docker, projectA.test does not display the correct website but point to the root.
In the folder apache2 there is a file called vhost.conf with Include /etc/apache2/sites-available/*.conf. When I copied the 2 conf files above into that folder (which was not there before), I get a Forbidden error : You don't have permission to access this resource. Apache/2.4.29 (Ubuntu) Server at utopia.test Port 80.
After reading an article on apache error 403, I change the permission on the public folder to be:
sudo chmod -R 775 public
sudo chown -R _www:_www public
drwxrwxr-x# 15 _www _www 480 Mar 19 18:11 public
I would really appreciate if someone could help please.
I was so tired with this issue that I forgot to restart Apache after changing permission... that was the trick!
I hope this will help others as I did not find this solution in any of the tutorials or posts on the subject!

Unable to access log file. Please ensure that path/to/production.log exists and is writable

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.
Solution:
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
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.
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.

Deploy ruby on rails app with passenger and apache

I want to deploy my ruby on rails application on Red Hat Enterprise Linux Server release 6.5 server
I have done the following:
Server version: Apache/2.2.15 (Unix)
rvm install ruby
gem install rails
gem install passenger
passenger-install-apache2-module
then I added the following line on my httpd.conf file
LoadModule passenger_module /home/myname/.rvm/gems/ruby-2.1.2/gems/passenger-4.0.50/buildout/apache2/mod_passenger.so
<IfModule mod_passenger.c>
PassengerRoot /home/myname/.rvm/gems/ruby-2.1.2/gems/passenger-4.0.50
PassengerDefaultRuby /home/myname/.rvm/gems/ruby-2.1.2/wrappers/ruby
</IfModule>
alos I added the following to my httpd.conf
<VirtualHost *:80>
ServerName www.whatever.com
# !!! Be sure to point DocumentRoot to 'public'!
DocumentRoot /var/www/whatever/public
<Directory /var/www/whatever/public>
# This relaxes Apache security settings.
AllowOverride all
# MultiViews must be turned off.
Options -MultiViews
# Uncomment this if you're on Apache >= 2.4:
#Require all granted
</Directory>
Additional info
rvm 1.25.31
I restarted the httpd and I cannot see my app running on whatever.com
I have bought the domain and redirected it to the IP of my machine.
What is wrong?
There's a number of reasons why this can happen, #user1876128 had some internal network issues and it wasn't acutally apache at fault.
For this apache setup to work, your network needs to allow http traffic to port 80 of your server box.
It's also advisable to allow traffic on port 3000, so you can run up a rails dev server on the same address (plus :3000) to check any changes before they're up.
You can log in to most domestic routers by pointing your browser at 192.168.0.1 or 192.168.1.1, then using the password (which is either written on your router, or the default password you can find online, or you've already changed it). And setting up a service for port 80 and your server box.
You need to uncomment the line indicated below and restart your apache service (sudo service apache2 restart or similar sudo /etc/init.d/apache2 restart)
<VirtualHost *:80>
ServerName www.whatever.com
# !!! Be sure to point DocumentRoot to 'public'!
DocumentRoot /var/www/whatever/public
<Directory /var/www/whatever/public>
# This relaxes Apache security settings.
AllowOverride all
# MultiViews must be turned off.
Options -MultiViews
# Uncomment this if you're on Apache >= 2.4:
---> Require all granted
</Directory>
This is a common issue with the default stuff from passenger. Chances are you're on a newer version of apache which means # Uncomment this if you're on Apache >= 2.4: would apply.

Deploying Rails on Apache on Mac OSX - 403 Forbidden Error

I have browsed over 100 links in the past hour, and nothing has helped. What I'm trying to do is simple: deploy a rails app on apache using passenger. The issue I'm getting is a 403 Forbidden error. My setup:
I run these two commands:
sudo gem install passenger
rvmsudo passenger-install-apache2-module
Then in etc/apache2/other I create a file called Passenger.conf with:
LoadModule passenger_module /Users/maq/.rvm/gems/ruby-2.0.0-p247/gems/passenger-4.0.14/buildout/apache2/mod_passenger.so
PassengerRoot /Users/maq/.rvm/gems/ruby-2.0.0-p247/gems/passenger-4.0.14
PassengerDefaultRuby /Users/maq/.rvm/wrappers/ruby-2.0.0-p247/ruby
Then in /etc/apache2/extra/httpd-vhosts.conf, I have:
<VirtualHost *:80>
ServerName rails.local
DocumentRoot /webapps/coolapp/public
<Directory /webapps/coolapp/public/>
AllowOverride all
Allow from all
Options -MultiViews
</Directory>
</VirtualHost>
Then in my /etc/hosts file, I add this entry:
127.0.0.1 rails.local
Then, I change permissions on my webapps directory:
sudo chmod -R 755 /webapps
I then restart Apache:
sudo apachectl restart
NONE OF THIS IS FIXING THE ISSUE. I keep getting the same thing when I access rails.local in my browser:
You don't have permission to access / on this server. Apache/2.2.22
(Unix) DAV/2 Phusion_Passenger/4.0.14 mod_ssl/2.2.22 OpenSSL/0.9.8x
Server at rails.local Port 80
Someone for the love of god tell me what the issue could be.
Apache won't have permission to access /. You should be serving up your websites from /Library/WebServer/Documents/ or—depending on what group Apache is configured to run under (wheel by default in OS X)—you can try sudo chown -R root:wheel /webapps
Edit
My httpd.conf configuration has the following user/group:
User: [my user] # is an admin user
Group: staff

Apache webserver error

i am running my ruby on rails application on a mac os x 10.7 on Apache Web Server with Passenger plugin. My httpd.conf file is as follows.
LoadModule passenger_module /Users/Ahmad/.rvm/gems/ruby-1.9.3-p392/gems/passenger-3.0.19/ext/apache2/mod_passenger.so
PassengerRoot /Users/Ahmad/.rvm/gems/ruby-1.9.3-p392/gems/passenger-3.0.19
PassengerRuby /Users/Ahmad/.rvm/wrappers/ruby-1.9.3-p392/ruby
NameVirtualHost *:80
<VirtualHost *:80>
ServerName qchext.local
# !!! Be sure to point DocumentRoot to 'public'!
DocumentRoot "/Users/Ahmad/Sites/redbytes_projects/qchext/public"
<Directory "/Users/Ahmad/Sites/redbytes_projects/qchext/public">
# This relaxes Apache security settings.
AllowOverride all
# MultiViews must be turned off.
Options -MultiViews
</Directory>
</VirtualHost>
ServerName qchext.local
error_log file
[notice] caught SIGTERM, shutting down
[notice] Digest: generating secret for digest authentication ...
[notice] Digest: done
[warn] mod_bonjour: Skipping user 'Ahmad' - no valid index file.
[notice] Apache/2.2.22 (Unix) Phusion_Passenger/3.0.19 DAV/2 configured -- resuming normal operations
Please guide me what wrong i ve done.
The SIGTERM you see is used to restart Apache, did you install the latest Apache with mod_passenger and not the Apache that comes bundled with OSX (Assuming that this is what you are running RoR on).

Resources