I'm currently trying to get a couple of small Rails apps running on a server, normally I've used Heroku but I decided to DIY it this time for practise, and everything that is suggested on the Internet doesn't work.
I've tried pretty much all of the resources I can find on both SO and the full Phusion guide, the closest I can come is "The page you were looking for doesn't exist." The app itself runs fine when I run it with script/rails server, initalizing a new rails app to a different sub_dir runs fine, but it'll only let me use index.html, nothing else. So it looks like some kind of routing issue, but when I tried the "scope do" it falls over on "scope".
What's the actual recommended and suggested way to have multiple rails sites on sub uris?
Apache2 Configuration File
NameVirtualHost *:80
<VirtualHost *:80>
ServerName www.cybershrike.co.uk/
DocumentRoot /web/rails
<Directory /web/rails>
Allow from all
</Directory>
RailsBaseURI /test
<Directory /web/rails/test>
Options -MultiViews
</Directory>
</VirtualHost>
NameVirtualHost *:80
<VirtualHost *:80>
ServerName www.cybershrike.co.uk/
DocumentRoot /web/rails
<Directory /web/rails>
Allow from all
</Directory>
RailsBaseURI /kinu
RailsEnv development
SetEnv RAILS_RELATIVE_URL_ROOT "/kinu"
PassengerAppRoot /web/rails/kinu
<Directory /web/rails/kinu/public>
Options MultiViews Indexes FollowSymLinks
</Directory>
</VirtualHost>
Have you tried the proposed default passenger option?
RailsBaseURI /kinu
RailsEnv development
<Directory /web/rails/kinu/public>
Options -MultiViews
</Directory>
</VirtualHost>
Also you have to ensure, that file-permission allow the apache-server (ususally wwwuser) to access all files recursively including /web ?
And, just to cover all bases here: did you restart apache?
Related
I want to use Laravel projects at the same time. How you can do it? For example one project at
http://example.xom/laravel_proj1
and another on
http://example.xom/laravel_proj2
Configuration: Laravel 7 / 8 and Apache
Update: This is 2 different Projects. But are there some problems if I use this 2 equals Projects. Upsides of MySQL Datables of course.
File: /opt/bitnami/apache2/conf/vhosts/APPNAME-vhost.conf
<VirtualHost 127.0.0.1:80 _default_:80>
ServerAlias *
DocumentRoot /opt/bitnami/projects/APPNAME/public
<Directory "/opt/bitnami/projects/APPNAME/public">
Options -Indexes +FollowSymLinks -MultiViews
AllowOverride All
Require all granted
</Directory>
</VirtualHost>
Usually you work with subdomains to have multiple laravel projects running at the same time. This means that one instance runs at first.example.com and the other at second.example.com. In my opinion what you are trying is more a workaround if you only have one vhost running.
So I would have two vhost files like you have now. One like:
<VirtualHost 127.0.0.1:80 _default_:80>
ServerAlias first.example.com
DocumentRoot /opt/bitnami/projects/first/public
<Directory "/opt/bitnami/projects/first/public">
...
</Directory>
</VirtualHost>
and
<VirtualHost 127.0.0.1:80 _default_:80>
ServerAlias second.example.com
DocumentRoot /opt/bitnami/projects/second/public
<Directory "/opt/bitnami/projects/second/public">
...
</Directory>
</VirtualHost>
Then you would add both subdomains to your hosts file. I don't know where that one is located but in there you would have to add:
127.0.0.1 first.example.com
127.0.0.1 second.example.com
This is not exactly how I do it now, but I think it could be a good starting point. You also need to activate your vhosts and restart apache.
My current project urls look like this:
localhost/mydomain/public/collection/resource.
I have several PHP projects running out of localhost at the moment. I would like the url for this project to be as it would in production so I'm not coding around the url. Is there a way to get this to be mydomain/collection/resource?
The solution was to implement apache vHosts:
<VirtualHost 127.0.0.1>
ServerName mydomain.com
DocumentRoot "C:/Bitnami/wampstack-5.6.21-2/apache2/htdocs/mydomain/public"
</VirtualHost>
<Directory "C:/Bitnami/wampstack-5.6.21-2/apache2/htdocs/mydomain/public">
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
I've set up wamp and laravel with composer, and virtualhosts too. Whenever I go to my project folder 'localhost/project/', or my vhost 'project.dev', I only see the file directory of the laravel project. Yet if I go to 'project.dev/public' or 'project.dev/server.php' it works. What am I doing wrong?
You need to set your DocumentRoot (in your vhosts file) to C:\location\of\laravel\public instead of C:\location\of\laravel\
Here is an example, dont forget to also tell Apache from where it is allowed to accespt connections as well.
<VirtualHost *:80>
DocumentRoot "D:/wamp/www/laravel/public"
ServerName laravel.dev
Options Indexes FollowSymLinks
<Directory "D:/wamp/www/laravel/public">
AllowOverride all
Require local
Require ip 192.168.1
</Directory>
</VirtualHost>
I'm trying to get my wordpress site as well as my reviewboard site working under the same domain name.
Ex:
www.mysite.com (this is where i host my wordpress site)
www.mysite.com/reviewboard (this is where I want to host my reviewboard site)
I can get one or the other to work depending on my httpd-vhosts.conf file. However, I cannot get both to work(this is where I need your help!).
This is how I host my wordpress site:
<VirtualHost *:80>
ServerAdmin myemail#gmail.com
DocumentRoot "/opt/local/apache2/htdocs/mysite"
ServerName www.mysite.com
ErrorLog "/opt/local/apache2/logs/mysite.com-error_log"
CustomLog "/opt/local/apache2/logs/mysite.com-access_log" common
</VirtualHost>
This is how I host my reviewboard site(which then breaks my wordpress site):
<VirtualHost *:80>
ServerName www.mysite.com
DocumentRoot "/opt/local/apache2/htdocs/mysite/reviewboard/htdocs"
# Error handlers
ErrorDocument 500 /errordocs/500.html
WSGIPassAuthorization On
WSGIScriptAlias "/reviewboard" "/opt/local/apache2/htdocs/mysite/reviewboard/htdocs/reviewboard.wsgi/reviewboard"
<Directory "/opt/local/apache2/htdocs/mysite/reviewboard/htdocs">
AllowOverride All
Options -Indexes +FollowSymLinks
Allow from all
</Directory>
# Alias static media requests to filesystem
Alias /reviewboard/media "/opt/local/apache2/htdocs/mysite/reviewboard/htdocs/media"
Alias /reviewboard/static "/opt/local/apache2/htdocs/mysite/reviewboard/htdocs/static"
Alias /reviewboard/errordocs "/opt/local/apache2/htdocs/mysite/reviewboard/htdocs/errordocs"
Alias /reviewboard/favicon.ico "/opt/local/apache2/htdocs/mysite/reviewboard/htdocs/static/rb/images/favicon.png"
</VirtualHost>
So, now I want to be able to figure out how to combine these somehow so I can have reviewboard hosted at the path specified above without breaking my wordpress site. I tried using the Alias command as mentioned here: http://stackoverflow.com/questions/1553165/multiple-django-sites-with-apache-mod-wsgi
and here
https://code.google.com/p/modwsgi/wiki/ConfigurationGuidelines
However I can't get it to work. Here's my WIP. If you can be very specific as what I need to do in order to change this so it works that would be great since I'm new to this kind of stuff. Thanks!
<VirtualHost *:80>
ServerName www.mysite.com
DocumentRoot "/opt/local/apache2/htdocs/mysite"
# Error handlers
#hmm not sure where to put this since my document root is different??????
#ErrorDocument 500 /errordocs/500.html
WSGIPassAuthorization On
Alias /reviewboard/ /opt/local/apache2/htdocs/mysite/reviewboard/htdocs/
<Directory "/opt/local/apache2/htdocs/mysite/reviewboard/htdocs">
Options ExecCGI
SetHandler wsgi-script
AllowOverride All
Options -Indexes +FollowSymLinks
Allow from all
</Directory>
# Alias static media requests to filesystem
# Since I added the alias command above these are complaining about
#overlapping an earlier alias when I restart my apache server????
Alias /reviewboard/media "/opt/local/apache2/htdocs/mysite/reviewboard/htdocs/media"
Alias /reviewboard/static "/opt/local/apache2/htdocs/mysite/reviewboard/htdocs/static"
Alias /reviewboard/errordocs "/opt/local/apache2/htdocs/mysite/reviewboard/htdocs/errordocs"
Alias /reviewboard/favicon.ico "/opt/local/apache2/htdocs/mysite/reviewboard/htdocs/static/rb/images/favicon.png"
</VirtualHost>
If you're using the same domain for both, you can't use different VirtualHost sections for both. So first off, you have to merge both configurations into a single VirtualHost section. I'd start with the WordPress config, then add a few bits for ReviewBoard:
<VirtualHost *:80>
ServerAdmin myemail#gmail.com
DocumentRoot "/opt/local/apache2/htdocs/mysite"
ServerName www.mysite.com
ErrorLog "/opt/local/apache2/logs/mysite.com-error_log"
CustomLog "/opt/local/apache2/logs/mysite.com-access_log" common
WSGIPassAuthorization On
WSGIScriptAlias /reviewboard /opt/local/apache2/htdocs/mysite/reviewboard/rb.wsgi
<Directory /opt/local/apache2/htdocs/mysite/reviewboard>
Order deny,allow
Allow from all
</Directory>
Alias /reviewboard/media "/opt/local/apache2/htdocs/mysite/reviewboard/htdocs/media"
Alias /reviewboard/static "/opt/local/apache2/htdocs/mysite/reviewboard/htdocs/static"
Alias /reviewboard/errordocs "/opt/local/apache2/htdocs/mysite/reviewboard/htdocs/errordocs"
Alias /reviewboard/favicon.ico "/opt/local/apache2/htdocs/mysite/reviewboard/htdocs/static/rb/images/favicon.png"
</VirtualHost>
You need to create a WSGI script (but you should already have that). You might want to put it in a different path than what I put in the config here, so your permissions are more secure.
Using a combination of what djc wrote and some of my tinkering here's the working version so that:
www.mysite.com (wordpress site loads correctly)(mod_php)
www.mysite.com/reviewboard (reviewboard site loads correctly)(mod_wsgi)
Important make sure you clear your browser cache every time you restart your apache server as I kept falling into the trap of it showing incorrect data since I forgot to do that.
Important2 Make sure the "/reviewboard" follows the "reviewboard.wsgi" to become "reviewboard.wsgi/reviewboard" otherwise it will not work and gives a 404 error!
Here's the working version:
<VirtualHost *:80>
ServerAdmin myemail#gmail.com
ServerName www.mysite.com
DocumentRoot "/opt/local/apache2/htdocs/mysite"
ErrorLog "/opt/local/apache2/logs/mysite-error_log"
CustomLog "/opt/local/apache2/logs/mysite-access_log" common
WSGIPassAuthorization On
WSGIScriptAlias /reviewboard /opt/local/apache2/htdocs/mysite/reviewboard/htdocs/reviewboard.wsgi/reviewboard
<Directory /opt/local/apache2/htdocs/mysite/reviewboard>
Allow from all
Options -Indexes +FollowSymLinks
AllowOverride All
</Directory>
# Alias static media requests to filesystem
Alias /reviewboard/media "/opt/local/apache2/htdocs/mysite/reviewboard/htdocs/media"
Alias /reviewboard/static "/opt/local/apache2/htdocs/mysite/reviewboard/htdocs/static"
Alias /reviewboard/errordocs "/opt/local/apache2/htdocs/mysite/reviewboard/htdocs/errordocs"
Alias /reviewboard/favicon.ico "/opt/local/apache2/htdocs/mysite/reviewboard/htdocs/static/rb/images/favicon.png"
</VirtualHost>
I have a basic virtual host setup enabled on my machine, and it works fine when I just type in the server name. However, when I include "RewriteEngine On" it kills it. Yes, I do have the rewrite module installed, and yes, I have restarted apache. I'm not actually attempting any rewrite rules yet, because just the act of turning the thing on is enough to make it stop working. Any clue as to what's going on? Seems like if the module is included, this ought to work. What am I forgetting? Here's what I've got in my virtual host file
NameVirtualHost *:80
<VirtualHost *:80>
ServerAdmin webmaster#localhost
DocumentRoot "C:/www/mysite/public/"
ServerName mysite
RewriteEngine on
<Directory "C:/www/mysite/public/"
Options Indexes FollowSymLinks
AllowOverride all
Order Deny,Allow
Allow from all
</Directory>
</VirtualHost>
When I remove the "RewriteEngine on" line, everything works. When I put it back in, it breaks. I could understand if I had some weird rule in there, but simply turning it on shouldn't break anything.
Perhaps mod_rewrite isn't enabled in your setup? You can try to put the RewriteEngine On line inside an test like so
<IfModule mod_rewrite.c>
RewriteEngine On
</IfModule>
I assume you an Ubuntu-like system.
Go to /etc/apache2/sites-available/your_site.conf
Open your_site.conf using your favorite text editor.
Add/Update the Directory section as below
<Directory /var/www/>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
Save it and restart apache.