Frontend pages giving 404 with symfony and apostrophe - symfony1

I thinks this question might be on the edge of having to go on serverfault. However, as I'm not sure about the cause of the problem, I'll ask the question here.
I Have a Symfony installation with 2 apps: frontend and backend
On the frontend I run apostrophe cms and in the backend I have some modules from the doctrine admin generator.
Everything works fine local. However, on my production server, every frontend page after http://mydomain.com/ gives a 404 error. The weird thing is that http://mydomain.com/backend/ works fine. I'm not sure if its my apache config (seeing as /backend/ does work) but I'll paste it here, just to be sure. This is what I have in sites-available/default:
<VirtualHost *:80>
DocumentRoot "/mysfproject/web"
DirectoryIndex index.php
<Directory "/mysfproject/web">
AllowOverride All
Options Indexes FollowSymLinks MultiViews
Allow from All
</Directory>
ErrorLog /var/log/apache2/error.log
Alias /sf /mysfproject/lib/vendor/symfony/data/web/sf
<Directory "/mysfproject/lib/vendor/symfony/data/web/sf">
AllowOverride All
Allow from All
</Directory>
</VirtualHost>
Any help would be greatly appreciated!

Turns out mod_rewrite was disabled. Fixed it by doing sudo a2enmod rewrite

Related

Rails application isn't restarting after system reboot

I have a Rails 4 application deployed with Apache and Passenger.
The configuration was provided by this thread and everything worked perfectly.
I created a whenever job that runs when the machine restarts, and I rebooted the machine to check if it works, and it does.
BUT, from some reason my web address is no longer reachable. It seems like the machine doesn't route the requests to the application (I get "this webpage isn't available" message from the browser).
I've double checked the /etc/httpd/conf/httpd.conf file to make sure the configuration still exists and it does.
I also tried to push again the application to the machine using cap production deploy, and didn't get any errors while doing that.
My configuration in the /etc/httpd/conf/httpd.conf file is the following:
<VirtualHost *:80>
ServerName csi-eng-perf.com
# !!! Be sure to point DocumentRoot to 'public'!
DocumentRoot /var/www/eng_performance/current/public/
<Directory /var/www/eng_performance/current/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>
ScriptAlias /cgi-bin/ /usr/lib/cgi-bin
<Directory "/usr/lib/cgi-bin">
AllowOverride None
Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
I have no idea what have gone wrong.
Well, as it turns out #Substantial suggestion was correct.
I wasn't able to issue the apachectl status command (needed the installation of another package called links) but the restart command did the trick- apachectl -k restart.

Phusion Passenger + Apache 2 + Rails 3. Works on local network, not when accessed externally

The problem:
I have created a Rails project skeleton using rails new TestApp in the /var/www/ directory of my server. The Rails default index.html displays and works properly (i.e., you see the rails logo and when you click on "About your application's environment" you get a correct listing of the environment specifications used on the server) when I access the site from the same network on which the server is running. However, if I access the site from a machine on a different network than the server's, the page displays but I do not get the rails logo image, and clicking on "About your application's environment" results in the following error display on the page:
Not Found
The requested URL /TestApp/rails/info/properties was not found on this server
And that URL shouldn't be found, because it doesn't exist. However, TestApp/public/rails/info/properties does exist.
Configuration:
The site resides in /var/www/TestApp and I access it from a Sub-URI. I have created a symbolic link in /var/www/ called rails as follows: rails -> /var/www/TestApp/public, such that the project can be accessed from www.mydomain.com/rails. My Apache configuration is the following, note that I've omitted,changed, or shortened some parts within the <VirtualHost> tag for brevity:
LoadModule passenger_module /usr/local/rvm/gems/ruby-1.9.3-p194/gems/passenger-3.0.12/ex$
PassengerRoot /usr/local/rvm/gems/ruby-1.9.3-p194/gems/passenger-3.0.12
PassengerRuby /usr/local/rvm/wrappers/ruby-1.9.3-p194/ruby
<VirtualHost *:80>
ServerAdmin webmaster#localhost
ServerName www.mydomain.com
DocumentRoot /var/www
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
<Directory /var/www/>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all
</Directory>
.
.
.
#Rails Configuration
RailsBaseURI /rails
RailsEnv development
PassengerUserSwitching off
PassengerDefaultUser www-data
<Directory /TestApp/public>
Options FollowSymLinks -MultiViews
AllowOverride All
Allow from all
</Directory>
#End Rails Configuration
.
.
.
</VirtualHost>
A couple of things: the appropriate folders are owned by www-data with the appropriate permissions as defined by the Passenger documentation. When setting up the symlink and RailsBaseURI settings I followed the Passenger documentation.
I guess I'm at a loss here since everything seems to be working when accessing the website from the same network on which the server resides. I'm not sure why things aren't working out when accessing the site from a different network, but I feel like paths to certain resources/assets (like the rails logo) aren't resolving properly. Perhaps my symlink is configured inappropriately, or something is wrong with my Apache configuration?
Any help would be appreciated.
The issue of a somewhat broken default Rails page is not totally abnormal, it turns out.
I removed the default Rails page and replaced with another page that included some Rails code and everything worked like a charm.

Setting up Rails app on Apache with passenger - Rails doesn't seem to load

I am trying to set up Rails on a Ubuntu instance by following along with documentation such as https://help.ubuntu.com/community/RubyOnRails. I am trying to set up the app from the Rails Getting Started page here: http://guides.rubyonrails.org/getting_started.html.
What I have done so far:
Installation of Ruby/RubyGems/Rails through RVM and GEM (this installed Ruby 1.9.2 and Rails 3.0.7)
Installation of the mysql and mysql2 module (latter which didn't work)
Creation of rails app (blog app as tutorial is instructing)
Sym linking of /home/me/www/blog/public/ from /var/www/blog/
Creation of DB through rake
Installation of passenger module for Rails execution in Apache
Running of passenger-install-apache2-module to configure Apache
Deletion of public.html file from public/ rails app folder so that my controller/view can fire
Configuration of sites-available files for virtual hosts
Configuration of Rails routing
I believe it is the last two steps that are tripping me up, partly due to lack of familiarity with Apache and Rails (I am new to both).
In my virtual host file I am trying to point to the blog public dir in /var/www/blog. For my Rails route I have root :to => "home#index" as instructed.
When I browse to the http:// url I should normally be seeing my "Hello, Rails!" page per section 4.3 of the Getting Started guide, however all I see is the directory listing from Apache. Static pages work but not Rails processing.
At this point I am unclear if the passenger module is even doing anything or where to look for any evidence of what is happening. I tried various things like running the Rails app off a different virtual host called "blog" at http:///blog and the routing worked (static pages and all) but no Rails as above.
Update: after playing around some more, I now get a new error message (404):
Not Found
The requested URL /dispatch.cgi was
not found on this server.
I have since determined that this cgi 404 was caused by a rewrite rule I had added to .htaccess from guidance from the help.ubuntu.com page I pointed out above. Looks like it wasn't necessary or applied to an older version of Rails. The inconsistencies in instructions when looking up help online is disorienting! Removing the file leaves me with the previous problem though.
Here's the entry in the Apache log that I believe correlates with the first error. Although I am no longer getting this error it seems, may be related to something else I was trying before...
[Fri May 27 22:49:41 2011] [notice] Apache/2.2.16 (Ubuntu) PHP/5.3.3-1ubuntu9 with Suhosin-Patch Phusion_Passenger/3.0.7 configured -- resuming normal operations
[Fri May 27 22:51:18 2011] [error] [client 192.168.1.141] File does not exist: /var/www/blog/rails, referer: http://192.168.1.138/blog/
Here's the most recent entry with the 404 on the cgi thing:
[Sat May 28 08:01:18 2011] [error] [client 192.168.1.141] File does not exist: /var/www/blog/dispatch.cgi
What could I be missing? Thanks!
Additional details as requested. Apache sites file:
<VirtualHost *:80>
ServerAdmin webmaster#localhost
DocumentRoot /var/www/blog/
RailsEnv development
# <Directory />
# Options FollowSymLinks
# AllowOverride None
# </Directory>
<Directory "/var/www/blog/">
Options Indexes FollowSymLinks -MultiViews +ExecCGI
AllowOverride All
Order allow,deny
allow from all
# AddHandler cgi-script .cgi
</Directory>
ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
<Directory "/usr/lib/cgi-bin">
AllowOverride None
Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
Order allow,deny
Allow from all
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn
CustomLog ${APACHE_LOG_DIR}/access.log combined
Alias /doc/ "/usr/share/doc/"
<Directory "/usr/share/doc/">
Options Indexes MultiViews FollowSymLinks
AllowOverride None
Order deny,allow
Deny from all
Allow from 127.0.0.0/255.0.0.0 ::1/128
</Directory>
</VirtualHost>
Another update: I was able to get it working, finally, by using a top level DocumentRoot (/var/www) and basing my Rails app off that using RailsBaseURI. This maps to the "Deploying to a sub URI" section of the Phusion Passenger instructions. It is used as http:///blog which is not really what I wanted to get, but it's kind of irrelevant as I am using this just to learn Rails in a virtual. I will need to go and work on getting it working as a top level app again sometime later. Here's my current (final) VirtualHost file for reference:
<VirtualHost *:80>
ServerAdmin webmaster#localhost
DocumentRoot /var/www/
RailsEnv development
<Directory /var/www/>
Options FollowSymLinks
AllowOverride None
</Directory>
RailsBaseURI /blog
<Directory /var/www/blog/>
Options Indexes FollowSymLinks -MultiViews +ExecCGI
AllowOverride All
Order allow,deny
allow from all
# AddHandler cgi-script .cgi
</Directory>
ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
<Directory "/usr/lib/cgi-bin">
AllowOverride None
Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
Order allow,deny
Allow from all
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn
CustomLog ${APACHE_LOG_DIR}/access.log combined
Alias /doc/ "/usr/share/doc/"
<Directory "/usr/share/doc/">
Options Indexes MultiViews FollowSymLinks
AllowOverride None
Order deny,allow
Deny from all
Allow from 127.0.0.0/255.0.0.0 ::1/128
</Directory>
</VirtualHost>
Deploying a Ruby on Rails application
Suppose you have a Ruby on Rails
application in /webapps/mycook, and
you own the domain www.mycook.com. You
can either deploy your application to
the virtual host’s root (i.e. the
application will be accessible from
the root URL, http://www.mycook.com/),
or in a sub URI (i.e. the application
will be accessible from a sub URL,
such as
http://www.mycook.com/railsapplication).
Deploying to a virtual host’s root
Add a virtual host entry to your
Apache configuration file. Make sure
that the following conditions are met:
The virtual host’s document root must
point to your Ruby on Rails
application’s public folder.
The Apache per-directory permissions
must allow access to this folder.
MultiViews must be disabled for this
folder.
For example:
<VirtualHost *:80>
ServerName www.mycook.com
DocumentRoot /webapps/mycook/public
<Directory /webapps/mycook/public>
Allow from all
Options -MultiViews
</Directory>
</VirtualHost>
You may also need to tweak your
file/folder permissions. Make sure
that the following folders are
readable and executable by Apache:
this public folder.
the application’s config folder.
all parent folders. That is, /webapps/mycook and /webapps must also
be readable and executable by Apache.
Then restart Apache. The application
has now been deployed.
Read the whole docs here
Double check to make sure passenger is loading your application by typing
sudo passenger-status
This will show you an error if passenger isn't loaded or the below if it is. Note the part where it shows you which application or applications it has loaded and what the current uptime is:
----------- General information -----------
max = 6
count = 1
active = 0
inactive = 1
Waiting on global queue: 0
----------- Application groups -----------
/home/rourkem/public_html/evecord.com/current:
App root: /home/rourkem/public_html/evecord.com/current
* PID: 18976 Sessions: 0 Processed: 5 Uptime: 23m 55s
Be sure to delete the file index.html from the public directory of your application.

Having trouble setting up Apache for SSL with mongrel and rails 3 in development on ubuntu

I'm trying to setup apache2 so that I can try ssl in development on my rails 3 app on ubuntu.
The rails app works, except for https where in Fire Fox i get:
The connection was interrupted
The connection to localhost:3000 was interrupted while the page was loading.
In the console i get:
Thu Oct 14 15:56:28 +1100 2010: HTTP parse error, malformed request (127.0.0.1):
#<Mongrel::HttpParserError: Invalid HTTP format, parsing fails.>
Thu Oct 14 15:56:28 +1100 2010: REQUEST DATA: "\200U\001\003\000\000<\000\000\000\020\000\000\210\000\000\207\000\0008\000\000\204\000\0005\000\0009\000\000E\000\000D\000\0003\000\0002\000\000\226\000\000A\000\000\004\000\000\005\000\000/\000\000\026\000\000\023\000\376\377\000\000\n\000\000\377[������-V\214�e\277P-"
---
PARAMS: {}
---
I get the above console error whether Apache is running or not when using https. Which makes me think https localhost:3000 requests are never passing through Apache and instead going straight to mongrel which can't handle ssl.
Apache is working because if I go to http://localhost I get the default 'It Works' web page. I'm pretty sure the self signed certificates I created are also fine because going to https://localhost brings up the page in firefox asking if you trust the site and also lets me see the details of the certificate.
I've done a heap of googling and I've read through and tried a bunch of guides but many of them are a few years old and possibly out of date.
I ended up uninstalling apache2 and then reinstalling following this ubuntu guide https://help.ubuntu.com/10.04/serverguide/C/httpd.html It has a section on https configuration which I did and it creates this file -> /etc/apache2/site-available/default-ssl. It looks like this
<IfModule mod_ssl.c>
<VirtualHost *:443>
ServerAdmin webmaster#localhost
DocumentRoot /var/www
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
<Directory /var/www/>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all
</Directory>
ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
<Directory "/usr/lib/cgi-bin">
AllowOverride None
Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
Order allow,deny
Allow from all
</Directory>
ErrorLog /var/log/apache2/error.log
LogLevel warn
CustomLog /var/log/apache2/ssl_access.log combined
Alias /doc/ "/usr/share/doc/"
<Directory "/usr/share/doc/">
Options Indexes MultiViews FollowSymLinks
AllowOverride None
Order deny,allow
Deny from all
Allow from 127.0.0.0/255.0.0.0 ::1/128
</Directory>
SSLEngine on
SSLCertificateFile /etc/ssl/certs/server.crt
SSLCertificateKeyFile /etc/ssl/private/server.key
<FilesMatch "\.(cgi|shtml|phtml|php)$">
SSLOptions +StdEnvVars
</FilesMatch>
<Directory /usr/lib/cgi-bin>
SSLOptions +StdEnvVars
</Directory>
BrowserMatch "MSIE [2-6]" \
nokeepalive ssl-unclean-shutdown \
downgrade-1.0 force-response-1.0
# MSIE 7 and newer should be able to use keepalive
BrowserMatch "MSIE [17-9]" ssl-unclean-shutdown
# Used by Rails. Mentioned in all the Rails SSL tutorials.
RequestHeader set X_FORWARDED_PROTO "https"
</VirtualHost>
</IfModule>
All I modified in there is the certificate and key locations, made it
<VirtualHost *:443>
instead of
<VirtualHost _default_:443>
and added the RequestHeader set X_FORWARDED_PROTO "https" line at the end as all the guides said to do. I'm not sure what else needs to be changed. At one point I did try setting the DocumentRoot to the public folder of my rails app but it didn't make a difference.
Apache restarts fine and there are no errors in the log.
I'm sure I must be really close to having it working but I've spent many hours over many days and just can't figure it out. My best guess is that I have something wrong or missing in the apache config file above.
My Questions are:
How do I know if the requests are actually going through apache?
If its not why is the https ssl request going through to mongrel and not being handled by apache?
What do I need to do to get it working?
I stuffed around for ages and still couldn't get it working with just apache so ended up following parts of this ubuntu rails guide and installing Passenger. Passenger was nice and quick to install and best of all https works now in development.
I guess I should put virtualHost *.80 in default and virtualHost *.443 in default-ssl but anyway this is what my sites-available/default-ssl file now looks like(store = rails app name):
<VirtualHost *:80>
ServerName localhost
DocumentRoot /home/daniel/www/store/public
<Directory /home/daniel/www/store/public>
AllowOverride all
Options -MultiViews
</Directory>
</VirtualHost>
<VirtualHost *:443>
ServerName localhost
SSLEngine on
SSLCipherSuite ALL:!ADH:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv2:+EXP:+eNULL
SSLCertificateFile /etc/ssl/certs/server.crt
SSLCertificateKeyFile /etc/ssl/private/server.key
RequestHeader set X_FORWARDED_PROTO 'https'
DocumentRoot /home/daniel/www/store/public
<Directory /home/daniel/www/store/public>
AllowOverride all
Options -MultiViews
</Directory>
</VirtualHost>
my httpd.conf file looks like this with settings for passenger and running rails in development mode using development database:
ServerName localhost
LoadModule passenger_module /usr/lib/ruby/gems/1.8/gems/passenger-3.0.0/ext/apache2/mod_passenger.so
PassengerRoot /usr/lib/ruby/gems/1.8/gems/passenger-3.0.0
PassengerRuby /usr/bin/ruby1.8
RailsEnv development
RackEnv development
I'm still not 100% sure on how all the ports work but I'm guessing by using http://localhost:3000 the 3000 bit makes it go direct to mongrel and not through apache and therefore why the ssl never worked before. With apache and passenger setup as above I now go to http://localhost or https://localhost and it goes through apache and now works.

Passenger: RailsBaseURI case sensitive?

I used Passenger to deploy a RoR app to a sub URI on my domain. The problem I'm facing is that the sub URI seems to be case sensitive. Navigating to http://mydomain.com/RailsApp resolves fine. However, if I go to http://mydomain.com/railsapp, http://mydomain.com/railsApp, or any other variation, I get a 404 error. How can these requests using different casings get resolved correctly?
Here is my Apache configuration file:
<VirtualHost *:80>
ServerName mydomain.com
ServerAlias www.mydomain.com
DocumentRoot /www/mydomain/public
<Directory "/www/mydomain/public">
RailsEnv "production"
Order allow,deny
Allow from all
</Directory>
RailsBaseURI /RailsApp
<Directory "/www/RailsApp/public">
RailsEnv "development"
Options -MultiViews
</Directory>
</VirtualHost>
Any help is much appreciated. Thanks!
You could look into using mod_rewrite and matching it case insensitive there.
Some links to get you started :)
http://httpd.apache.org/docs/2.2/mod/mod_rewrite.html
http://httpd.apache.org/docs/2.2/misc/rewriteguide.html
Thanks ba for pointing me in the right direction.
I did some research and found the mod_speling module. This not only makes the URL case-insensitive but also checks for spelling errors.
To enable mod_speling:
sudo /usr/sbin/a2enmod speling
sudo /etc/init.d/apache2 force-reload
sudo /etc/init.d/apache2 restart
To use mod_speling, include the directive CheckSpelling on in your virtual host section:
<VirtualHost *:80>
CheckSpelling on
...
</VirtualHost>

Resources