CakePHP pretty URL's not working on production server - apache

I have developed a CakePHP application that I have now deployed to my production server, however pretty URLs do not work.
Here is my Apache vhost for the site:
<VirtualHost *:80>
ServerName site.com
ServerAdmin support#site.com
DocumentRoot /home/whitey/sites/site.com/htdocs/app/webroot/
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
<Directory /home/whitey/sites/site.com/htdocs/app/webroot/>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
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 /home/whitey/sites/site.com/logs/error.log
# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn
CustomLog /home/whitey/sites/site.com/logs/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>
As you can see, the document root is set to the webroot directory in my app. Inside that directory, there is this .htaccess file:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^$ app/webroot/ [L]
RewriteRule (.*) app/webroot/$1 [L]
</IfModule>
This entire setup works perfectly with my local machine running XAMPP, so I'm not sure what's wrong. The only thing I can think of is the rewrite rules aren't taking effect because of a setting in my vhost. But I haven't got enough knowledge of the Apache config files to know how to fix it.
Thanks.

Nevermind, I'm an idiot. I forgot to enable the mod_rewrite module for Apache when I set it up last night. Here's the fix:
sudo a2enmod rewrite
sudo service apache2 restart

Related

Sub-domain not working

I'm pretty new to apache, so probably the solution will be obvious to you... I'm running on Debian wheezy
Here are my two file in /etc/apache2/sites-availables:
amelineandraphael
<VirtualHost *:80>
ServerAdmin webmaster#localhost
ServerName amelineandraphael.raphaelnussbaumer.com
DocumentRoot /var/www/amelineandraphael
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
<Directory /var/www/amelineandraphael>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
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 ${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
</VirtualHost>
zoziology
<VirtualHost *:80>
ServerAdmin webmaster#localhost
ServerName zoziologie.raphaelnussbaumer.com
DocumentRoot /var/www/zoziologie
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
<Directory /var/www/zoziologie>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
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 ${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
I have added a symbolic link to /etc/apache2/sites-enables
I've run sudo a2ensite amelineandraphael and sudo a2ensite zoziologie
and restart the apache server.
The sub-domain zoziologie.raphaelnussbaumer.com is working but amelineandraphael.raphaelnussbaumer.com redirect me to the default index.html at /var/www/.
Here are the .htaccess of /var/www/amelineandraphael:
SetEnv PHP_VER 5_4
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
Any idea ?
I think I found the solution. Although I'm not sure that's the only part of the solution:
sudo a2dissite 000-default
Unfortunately I can't comment yet as I don't have the rep, so sorry about this being an "answer".
I'm wondering if you have a DNS "A" record for that subdomain? You may have a wildcard DNS record though, which would make this a moot point

ProxyPass not overriding .htaccess mod_rewrite

We have an angular app with an apache server which uses .htaccess to rewrite requests to /index.html using
RewriteRule . /index.html [L]
But for a few paths, we want to use /whatever to route to a different domain. However, adding
ProxyPass /whatever whatever.site.com
to sites-enabled doesn't seem to override the .htaccess.
That full file looks like
<VirtualHost *:80>
ServerAdmin webmaster#localhost
DocumentRoot /var/www
ProxyPass /whatever https://whatever.com
ProxyPassReverse /whatever https://whatever.com
<Directory />
Options FollowSymLinks
AllowOverride All
</Directory>
<Directory /var/www/>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
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 ${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
Any suggestions?
Also, I know for sure that the sites-enabled file above is being used because if I put garbage-text into it the site crashes ;)
Your quoted virtualhost is probably not used for your test request, because proxy would always bypass mod_rewrite rules specified in .htaccess.
Maybe apachectl -S would give you a hint about which vhosts are present / being used. I see this vhost has no ServerName, so unless it's the first or only *:80 it will probably never be used.

Subdomains Always Redirect To Main Domain - Apache2 VirtualHosts & Debain

I want to set up a main site, and a sub-domain for development, using apache2 VirtualHosts. This is what my site.conf virtual host file looks like:
<VirtualHost *:80>
ServerName dev.mysite.com
DocumentRoot /var/www/site/subdomain
<Directory /var/www/site/subdomain >
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>
# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel debug
CustomLog ${APACHE_LOG_DIR}/sub.log combined
</VirtualHost>
<VirtualHost *:80>
ServerName www.mysite.com
ServerAlias mysite.com
DocumentRoot /var/www/site/main
<Directory /var/www/site/main >
Options Indexes FollowSymLinks MultiViews
AllowOverride All
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>
# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
The problem is that every time I visit dev.mysite.com, I just get mysite.com.
There's no htaccess for the main site, and the .htaccess for the sub-domain looks like this:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
I've tried all the other solutions I could find (using literal IPs, re-ordering things, using ports instead of named hosts)... I'm totally stuck now. The site is enabled of course. Anyone got any ideas?
Wordpress Was The Problem
Or rather, me not knowing that I had to configure the Wordpress site url to be the subdomain, otherwise it would just redirect to the domain given...
So the solution: open the wp_options table and edit the site_url to include the subdomain.

Zend Framework application served via ip address

I am trying to setup my linode account to serve a zend framework web application from the IP address of the server. Everything works if I serve it from a resolved domain name like www.somesite.com/controller/action, but not from 182.324.34.2/controller/action. I think this has something to do with how zend framework handles routes? My question is what is the best way to run the application until a domain name is linked to the servers ip. Is this something I can handle with a .htaccess or apache config or something that needs to be handled via zend framework.
Edit:
I am not using hostname routes.
my .htaccess is
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule .* index.php
my vhost
<VirtualHost *:80>
ServerAdmin webmaster#localhost
DocumentRoot /var/www/core/public
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
<Directory /var/www/core/public>
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 ${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>
my zend framework config is pretty standard, let me know what parts would help.
Assuming you are on an Ubuntu server, you may need to simply disable the default virtual host:
sudo a2dissite default
sudo /etc/init.d/apache2 reload

Apache2 DirectoryIndex Issue

I am a little stuck and am sure that this is a trivial problem, but just can't seem to find the right solution.
I have a local development server running apache2 w/mod_ssl & mod_rewrite.
I created a self-signed cert and added the respective virtual host directive for *:443.
The issue I seem to be having is that now that I have the SSL side of things working properly. And when I say properly, I mean that I can go to the https url of my site (e.g. https://dev.mysite/) without adding index.php and it pulls up the index.php just fine.
But when I go to the regular http url of the site, I have to type in the index.php to see the site. (e.g. http://dev.mysite/index.php)
I tried adding a DirectoryIndex directive to the *:80 block, but this still doesn't appear to work.
Below is the virtual host file contents if that helps at all;
ServerName dev.mysite
<VirtualHost *:80>
ServerAdmin webmaster#localhost
DocumentRoot /var/www/vhosts/bsah_dev/mysite
<Directory />
DirectoryIndex index.php
Options Indexes FollowSymLinks
AllowOverride None
</Directory>
<Directory /var/www/vhosts/bsah_dev/mysite/>
DirectoryIndex index.html index.htm index.php
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 ${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>
<VirtualHost *:443>
ServerAdmin webmaster#localhost
DocumentRoot /var/www/vhosts/bsah_dev/mysite
SSLEngine On
<Directory /var/www/vhosts/bsah_dev/mysite>
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{HTTPS} !^on$ [NC]
RewriteRule . https://%{HTTP_HOST}%{REQUEST_URI} [L]
</IfModule>
</Directory>
SSLOptions +StrictRequire
SSLCertificateFile /etc/apache2/ssl.crt/server.crt
SSLCertificateKeyFile /etc/apache2/ssl.key/server.key
</VirtualHost>
A few comments on your configuration, which may help you fix this problem:
<Directory />
DirectoryIndex index.php
Options Indexes FollowSymLinks
AllowOverride None
</Directory>
That's quite unusual: normally, you wouldn't grant access to anything for the root directory (of your machine, not your document root). See the Directory documentation, which suggests using this:
<Directory />
Order Deny,Allow
Deny from All
</Directory>
This should work as expected in your configuration:
<Directory /var/www/vhosts/bsah_dev/mysite/>
DirectoryIndex index.html index.htm index.php
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all
</Directory>
(This being said, index.php will only be used if there's no index.html or index.htm found first.)
The DirectoryIndex documentation says it can be placed in "server config, virtual host, directory, .htaccess" (see "Context"). It also works within the Directory directive (and such values will override the values you'd find at the VirtualHost or server level).
This rule, in the HTTPS section doesn't make sense:
<Directory /var/www/vhosts/bsah_dev/mysite>
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{HTTPS} !^on$ [NC]
RewriteRule . https://%{HTTP_HOST}%{REQUEST_URI} [L]
</IfModule>
</Directory>
You're using a rewrite rule to redirect to the equivalent https:// URL. However, this rule is in the section where SSL is enabled, so you're redirecting from https:// to https://, not from http://.