Laradock virtual host not working on mac monterey apache2 - docker

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!

Related

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

Deploy 2 Sites on same Apache server

I need to deploy my Rails app to a server that is already serving a PHP site at its root. I can't touch the existing site, and I have to deploy my app at a sub-url or sub-domain, ie xx.xx.xx.xx/rails or rails.xx.xx.xx.xx.
The Apache config I normally use to deploy my app:
<VirtualHost *:80>
ServerName localhost
DocumentRoot "C:/RubyStack-3.2.5-0/projects/app_name/public"
<Directory "C:/RubyStack-3.2.5-0/projects/app_name/public">
Allow from all
Options -MultiViews
</Directory>
RewriteEngine On
RewriteCond %{DOCUMENT_ROOT}/%{REQUEST_FILENAME} !-f
RewriteRule ^/(.*)$ balancer://app_balancers%{REQUEST_URI} [P,QSA,L]
<Proxy balancer://app_balancers>
BalancerMember http://localhost:3001/
BalancerMember http://localhost:3002/
</Proxy>
# Support for far-futures expires header
<LocationMatch "^/assets/.*$">
Header unset ETag
FileETag None
# RFC says only cache for 1 year
ExpiresActive On
ExpiresDefault "access plus 1 year"
</LocationMatch>
</VirtualHost>
How could I change this configuration to serve that folder from a sub-url or subdomain? A RedirectMatch won't work because it would also route people away from the existing PHP site, right?
Easiest way would be to do name-based virtual hosting, using a subdomain as you suggested. So where you write:
<VirtualHost *:80>
ServerName localhost
</VirtualHost>
Simply enter your subdomain instead:
<VirtualHost *:80>
ServerName mysubdomain.mycompany.com
</VirtualHost>
Apache should then separate any requests to that subdomain from the 'main' virtualhost automatically.
edit:
Alternatively it is possible to mount your rails app to a subdirectory as well (assuming you're using Passenger.) Here's an example based on my own local staging environment. I got this working by following the instructions at the Phusion website
<VirtualHost *:80>
ServerName localhost
# We will mount our application under http://localhost/myapp
RailsBaseURI /myapp
# This can be anywhere on the system, I just happened to use /home/www
<Directory /home/www/myapp>
# Here you can add any directives necessary for your app, like for example..
SetEnv GEM_HOME /home/user/.rvm/gems/ree-1.8.7-2012.02
</Directory>
</VirtualHost>
Now you have to do one more thing, and that's make /home/www/myapp a link to the public dir of the actual application. So let's say you have the application in your own homedir you would have to type this:
cd /home/www
ln -s /home/myuser/myapp/public myapp
If you then type ls -l it should show:
lrwxrwxrwx 1 myuser myuser 18 Jun 10 16:41 devb -> /home/myuser/myapp/public
I think that should be it.

Apache: how to config ip address without SeverName?

I want to set my own sever to run my ruby on rails project(with passenger plugin). I use Apache2 on Ubuntu11.04(sever version).
It's my first time to use Apache and I have read some documents.
All the docs ask me to set SeverName,such as Apache doc and ubuntu docs.
Unfortunately, I don't have a domain name, can I just set IP address and use IP address to access this sever?
If it's ok, how should I do?
It's the config sample given by passenger:
<VirtualHost *:80>
ServerName www.yourhost.com
DocumentRoot /somewhere/public
<Directory /somewhere/public>
AllowOverride all
Options -MultiViews
</Directory>
</VirtualHost>
Thanks!
Comment out the line:
# NameVirtualHost *:80
Comment out any <VirtualHost> blocks.
Find the line:
DocumentRoot "/var/www/html" # or whatever your config uses for the overall apache document root.
Change it to your rails application's root.
DocumentRoot "/somewhere/public"
Then add your other config settings to a <Directory> block.
<Directory /somewhere/public>
AllowOverride all
Options -MultiViews
</Directory>
I haven't tested this for sure, but you should be able to get to it by only visiting the IP address. Make sure you have Passenger installed, have run passenger-install-apache2-module, and have added the appropriate module loading lines to your apache config.
/etc/apache2/httpd.conf
<VirtualHost *:80>
ServerName example.com
DocumentRoot /home/urpc-name/RailsApps/anything/public
<Directory /home/webonise/RailsApps/anything/public>
RailsEnv development
AllowOverride all
Options -MultiViews
</Directory>
</VirtualHost>
In server name:select ur virtual name...u can choose anything
In document root and directory,give your rails project path
Select rails environment in RailsEnv
/etc/hosts
127.0.0.1 example.com
Put server name in virtual host-127.0.0.1 is the localhost
Then just go to your browser and type example.com
Hope this helps

Installed Phusion Passenger on Server but apache2 didn't install in /etc/apache2/

I am following instructions on how to deploy rails application on server.
I did the following:
sudo gem install passenger
passenger-install-apache2-module
Everything is successful so far. But next on instruction he uses:
nano /etc/apache2/sites-enabled/000-default
Problem is there is no apache2 directory in etc. Therefore, I have no clue where the file I need to stick this information is:
<VirtualHost *:80>
ServerAdmin webmaster#localhost
ServerName www.mywebsite.com
DocumentRoot /var/www/mywebsite/public
<Directory /var/www/mywebsite/public>
Options Indexes FollowSymLinks -MultiViews
AllowOverride all
Order allow,deny
allow from all
</Directory>
ErrorLog /var/log/apache2/error.log
LogLevel warn
CustomLog /var/log/apache2/access.log combined
</VirtualHost>
Thanks for any response.
Apache is separate and will not be installed with phusion passenger. You need to install it by yourself and it depends on your OS (it seems you are on a linux system), so you may try something like this in the command line:
apt-get install apache2

Resources