Getting cakephp site to run on localhost - .htaccess

I downloaded a cakephp site to my computer for local development. I have done the following:
-Enabled Mod Rewrite in httpd.conf
-Have htaccess files in each app directory, including RewriteBase to the directory containing app
-Copied mySQL database and put correct info in database.php
-Restarted Apache
Currently, the site fails to find stylesheets and images, and links don't work because the server isn't translating pretty urls to resources.
Error log has a ton of errors that look like this:
Request URL: /css/normalize.css
Stack Trace:
#0 /home/content/73/11884573/html/tasklion/app/webroot/index.php(111): Dispatcher->dispatch(Object(CakeRequest), Object(CakeResponse))
#1 {main}
2014-02-03 15:23:25 Error: [MissingControllerException] Controller class ImagesController could not be found.
Exception Attributes: array (
'class' => 'ImagesController',
'plugin' => NULL,
)
The site is on localhost/~daniel/tasklion/app/...
All the controller files are in the right places, just like the live site.
The img and css folders are in webroot.
URL I use to access the site is :
http://localhost/~daniel/tasklion/
In htaccess in webroot I have:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /~daniel/tasklion/app/webroot/
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
What am I missing? Thanks.

Check these two things
Open this file
/etc/httpds/conf/httpd.conf
Search for mod_rewrite.so
Check if
LoadModule rewrite_module_modules modules/mod_rewrite.so is commented.
Remove the comment, if it's commented.
In same file
/etc/httpds/conf/httpd.conf
Search for 'Options Indexed FollowSymLinks' and change 'AllowOverride None' to 'AllowOverride All'
< Directory />
Options Indexed FollowSymLinks
AllowOverride All
< /Directory>
Restart apache.

Related

website transfer from folder in public_html to public_html caused errors

I just transferred my website from example.com/newsite to example.com by moving the folder where everything was stored (newsite) into my public_html to make it the root domain. Now I am receiving multiple issues on my error_log and the website is loading very very slowly. The error log is telling me things like:
PHP Warning: current() expects parameter 1 to be array, boolean given in /home3/example/public_html/newsite/wp-content/plugins/lezada-addons/includes/templates/lezada_brands_grid.php on line 79
I was thinking the urls containing example.com/newsite should be rewritten via .htaccess
Will this resolve the problem? If so what would the rewrite code be? I tried:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^example.com\newsite$ [NC]
RewriteRule ^(.*)$ "http://example.com/$1" [R=301,L]
</IfModule>
But this isn't working and the website is down!

Symfony assets in web folder not found by apache

I copied my symfony2 project to shared hosting.
My .htaccess
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /web
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ app.php [QSA,L]
</IfModule>
Now page is loading but no assets(js,css files) are loaded. When I try to open them myhost/assets/css/style.css I receive an error:
ops! An Error Occurred
The server returned a "404 Not Found".
Something is broken. Please let us know what you were doing when this error occurred. We will fix it as soon as possible. Sorry for any inconvenience caused.
All assets located in web/assets folder
Check apache config, or add to .htaccess uncommented last line from this doc:
# By default, Apache does not evaluate symbolic links if you did not enable this
# feature in your server configuration. Uncomment the following line if you
# install assets as symlinks or if you experience problems related to symlinks
# when compiling LESS/Sass/CoffeScript assets.
# Options FollowSymlinks

500 internal error with RewriteEngine on .htaccess on localhost with wamp

I'm having a problem with a script. It doen't works with a htaccess file that is needed to work. Here's what the htaccess contains. I'm trying to install it on a wamp localhost. The code is:
#AddType x-mapp-php5 .php
#AddHandler x-mapp-php5 .php
RewriteEngine ON
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php/$0 [PT,L]
#RewriteRule ^(.*)$ /index.php?q=$1 [L,QSA]
Options All -Indexes
If I remove this it works:
RewriteEngine ON
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php/$0 [PT,L]
#RewriteRule ^(.*)$ /index.php?q=$1 [L,QSA]
But this way the script loads but every page show error 404. Is there a way to resolve this problem??
It looks like you don't have the rewrite modules loaded. Find your httpd.conf file and make sure this line (or something similar) is uncommented:
LoadModule rewrite_module modules/mod_rewrite.so
Check that you have the the apache rewrite module loaded.
go to wamp_manager -> apache -> modules and look for rewrite_module in the list.
If it does not have a TICK beside it click it. Apache will be bounced ( stop, start ). Try again.
The rewite engine will not work without the required module loaded.
I had the same problem. To un-comment the line, remove the # in front of the line
LoadModule rewrite_module modules/mod_rewrite.so
Worked for me in Wamp.
Directory of the httpd.conf file: C:\wamp\bin\apache\apache2.4.9\conf
This is one solution that solved the issue for me. Rewrite module was always enabled, used in IfModule rewrite_module, permissions were granted and .htaccess contents were fine, yet it still was 500 error trying to use rewrite module.
In httpd.conf by default:
This is a source of a 500 error if you try to use rewrite in .htaccess in some sub directory.
`
# Deny access to the entirety of your server's filesystem. You must
# explicitly permit access to web content directories in other
# <Directory> blocks below.
#
<Directory />
AllowOverride none
Require all denied
</Directory>
`
So one may want to use .htaccess with rewrite module in a specific directory. You would add a <directory> block for that directory. If one copies and pastes the directory block, you need to make sure the intent of the block you copy is correct for the directory you want to apply it to.
So for my intent this block, causes a 403 error, but does get rid of the 500 error.
<Directory "c:/Apache24/htdocs/store">
AllowOverride All
Options None
Require all granted
</Directory>
Changing to this solved the issue:
<Directory "c:/Apache24/htdocs/store">
AllowOverride All
Require all granted
</Directory>
I suppose this is why the issue is commonly seen, but rarely solved in these threads. If I simply copied a different block, typed my own block, or had any understanding of what I was doing, this wouldn't have been an issue.
I can't say this solves everybody's issue, but I hate when people solve-and-run w/o enlightening the rest of us. So for those that did my mistake, this is the answer.

How to deploy Symfony2 on a shared-hosting?

I want to access my symfony app in production env (http://www.sample.com/amateur1/web/app.php) from this url http://www.sample.com/amateur1.
To do that I moved the .htacces file to http://www.sample.com/amateur1/.htaccess with this contents:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /web/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ app.php [QSA,L]
</IfModule>
But when I go to http://www.sample.com/amateur1 shows a 404 Error, and prod.log isn't written.
I also used RewriteBase /amateur1/web/ because I don't know If RewriteBase path is relative to the DocumentRoot of the server, Or from the path where the .htaccess file is located. Also tried /amateur1 and /amateur1/ as RewriteBase due to this answer Symfony2: How to deploy in subdirectory (Apache)
With the three try's, The Exceptions page appears unstyled, and not loading any image. But then I get the following error in prod.log file:
[2013-02-15 02:06:47] request.ERROR: Symfony\Component\HttpKernel\Exception\NotFoundHttpException: No route found for "GET /amateur1/" (uncaught exception) at /home/u105859802/public_html/amateur1/app/cache/prod/classes.php line 5121 [] []
What I'm doing wrong ?
In your configuration, apache uses public_html as the document root
If Symfony2 is installed in directory /home/u105859802/public_html/amateur1, the Symfony public directory to serve is /home/u105859802/public_html/amateur1/web/
You should use
RewriteBase /amateur1/web/
But beware, it is not safe
You have to protect your symfony directories! (configuration is accessible)
Why don't you try moving your symfony files in your private area ?
You can rename the Symfony web directory to public_html
See how to do that in documentation cookbook
So, my recommendation structure looks like below :
/home/u105859802/
vendor
src
app
bin
public_html (web by default in symfony2) <- the only public directory
In most of the shared hosting, you can't override Apache settings in that case may need to wright a redirection rule in .htaccess file
Options +FollowSymLinks +ExecCGI
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www\.)?mydomain\.com$ [NC]
RewriteRule !^projectName/ /projectName/web/app.php/%{REQUEST_URI} [L,NC]
this is the rule I used in my project .
You may need to provide full paths to your assets other ways they will not get loaded .

what is wrong with this .htaccess and Yii urlManager settings?

I have a yii website under a sub directory e.g
http://localhost/~username/maindirectory/yiiapp/
My htaccess file:
DirectoryIndex index.php index.html index.htm
Options +FollowSymLinks
IndexIgnore */*
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteBase /yiiapp
# if a directory or a file exists, use it directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# otherwise forward it to index.php
RewriteRule . index.php
</IfModule>
protected/config/main.php
...
'urlManager'=>array(
'urlFormat'=>'path',
'showScriptName'=>false,
....
The issue:
let say I accesss :
step one: http://localhost/~username/maindirectory/yiiapp/
step two: click any link on home page (default yii app) let say About Us page
step three: http://localhost/~username/maindirectory/yiiapp/site/page?view=about
step four : click on any on the link (let say same page)
url will look like : http://localhost/yiiapp/site/page?view=about
so : all links are accessible as : http://localhost/yiiapp/.... , instead of removing index.php from link the while string b/w localhost and base directory is removed .
I tried this already and need the same sort of url on localhost , obviously without using sub domains
please help me fix this .
Partial answer:
The problem is that you are redirecting to an absolute URL on the same domain.
The URL probably looks like /yiiapp/site/page?view=about. However that leads to http://localhost/yiiapp/site/page?view=about. You must prepend the website directory relative to the domain (not sure if I expressed properly).
For example, the URL in the a href tag should look like /~username/maindirectory/yiiapp/site/page?view=about so you must prepend the /~username/maindirectory part from somewhere.
Have your tried:
'urlManager'=>array(
....
'baseUrl' => '/~username/maindirectory/yiiapp',
....
http://www.yiiframework.com/doc/api/1.1/CUrlManager#setBaseUrl-detail
so RewriteBase /~username/maindir/yiiapp , in .htaccess fixed the issue , not the
'baseUrl' => '/~username/maindirectory/yiiapp' thing in config/main.php
Here is the full .htaccess file:
DirectoryIndex index.php index.html index.htm
Options +FollowSymLinks
IndexIgnore */*
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteBase /~username/maindir/yiiapp
# if a directory or a file exists, use it directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# otherwise forward it to index.php
RewriteRule . index.php
</IfModule>

Resources