CakePHP Installation Broke (Probably Apache2 Problem) - cakephp

I tried to install CakePHP on my home Ubuntu 10.04 desktop for development/testing purposes, and I believe I have gone through all the appropriate steps. However, I am still running into the problem that my layout is broken. I believe this is a DocumentRoot or mod_rewrite problem, but I don't have enough experience in Apache to diagnose and fix it.
/var/www/cakephp/.htaccess
1 <IfModule mod_rewrite.c>
2 RewriteEngine on
3 RewriteRule ^$ app/webroot/ [L]
4 RewriteRule (.*) app/webroot/$1 [L]
5 </IfModule>
/var/www/cakephp/app/webroot/.htaccess
1 <IfModule mod_rewrite.c>
2 RewriteEngine On
3 RewriteCond %{REQUEST_FILENAME} !-d
4 RewriteCond %{REQUEST_FILENAME} !-f
5 RewriteRule ^(.*)$ index.php?url=$1 [QSA,L]
6 </IfModule>
Firebug gives this:
404 Not Found
Not Found
The requested URL /cakephp/css/cake.generic.css was not found on this server.
Apache/2.2.14 (Ubuntu) Server at localhost Port 80
I tried setting the permissions of css/ and cake.generic.css to 775. owner is www-data, which is right. tmp is writable too
I also can't access the directory from my browser, 404.

but that will change your default website doccument starting point for your localhost site.
if you add more sites to apache2, you'll have errors.
you might want to save your 000-default as a separate file
/etc/apache2/sites-available/cakephptesting
and configure that file with the proper docroot
and then edit your host file
/etc/hosts
and add an entry as
127.0.0.1 cakephptesting
that will allow you to access the site in a browser at http://cakephptesting

I found the solution. I had to go under /etc/apache2/sites-enabled/000-default and change DocumentRoot to /var/www/cakephp/app/webroot
Now everything loads fine. Thanks!
Sorry,
Signed,
The Apache2 Noob :)

Related

Error 403 forbidden when using React Router with Apache

When I deploy my website built with React and React-router the landing page of my website works fine but when I try to navigate into my website I run into 403 forbidden response. I use Apache as an HTTP server and the general config of my server is the following :
<IfModule mod_php.c>
php_value date.timezone Europe/Brussels
</IfModule>
<IfModule mod_userdir.c>
UserDir /var/www/users/staff/*
</IfModule>
For your information, the website is located under /var/www/projects
I added the following .htaccess to my project :
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.html$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule . /index.html [L]
</IfModule>
Despite those configurations the 403 forbidden error when navigating in pages managed by react-router. Did I miss some configurations?
It seems that the settings you have applied are not enough, You should change some parameters in apache.conf too...
open the apache main config file, Its path varies depending on your distribution, that's located in one of these locations:
1- /etc/apache2/httpd.conf
2- /etc/apache2/apache2.conf
3- /etc/httpd/httpd.conf
4- /etc/httpd/conf/httpd.conf
look for "AllowOverride" parameter like the example below:
<Directory "/var/www/blahblah">
AllowOverride All
</Directory>
And give the "All" value to that.
Then create a .htaccess file in the root folder of the webserver & set the following configs:
Options -MultiViews
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.html [QSA,L]
NOTE: Before performing these things you have to enable the rewrite module, By entering the following commands you can do this:
debian base: sudo a2enmod rewrite
centos: uncomment mod_rewrite.so in /etc/httpd/conf/httpd.conf
Finally, restart your web server... Now expected there is no anymore problem.
If you got any permission/server error take a look at the webserver logs which are located in one of these locations:
1- /var/log/httpd/
2- /var/log/apache2

LetsEncrypt and CakePhp issue

I'm trying to install LetsEncrypt with cakephp and I'm having some issues.Let me describe:
First I'm installing LetsEncrypt on a server with CentOS 6.
As mentioned on several websites it needs a python upgrade from 2.6 to 2.7 as LetsEncrypt needs Python 2.7. Which I did.
Then if I run ./letsencrypt-auto I get
"No installers are available on your OS yet; try running "letsencrypt-auto certonly" to get a cert you can install manually"
I understand that this is normal as there is no installer for CentOS 6.
So I run ./letsencrypt-auto certonly.A window appears.I have the choice between:
Place files in webroot directory
Automatically use a temporary webserver
So I press 1.Then I enter my domain name.And I see:
Enter a new webroot
I press ok and I see my root directory.I select /root
And then I have the following error:
Failed authorization procedure. www.example.com (http-01): urn:acme:error:unauthorized :: The client lacks sufficient
authorization :: Invalid response from
http://www.example.com/.well-known/acme-challenge/-CnpDIgxBB9EOH-BCssGOyiunFjnMlGLWhWw9roE4Ds:
"
500 Internal Server Error Inter"
IMPORTANT NOTES:
- The following errors were reported by the server:
Domain: www.example.com Type: unauthorized Detail: Invalid
response from http://www.example.com/.well-known
/acme-challenge/-CnpDIgxBB9EOH-BCssGOyiunFjnMlGLWhWw9roE4Ds:
"
500 Internal Server Error
Inter"
To fix these errors, please make sure that your domain name was
entered correctly and the DNS A record(s) for that domain
contain(s) the right IP address.
And here comes cakephp. As mentioned I'm using cakephp. And it seems that for this specific issue you need to modify htaccess files as mentioned here
I need to add "RewriteRule ^(\.well-known/.*)$ $1 [L]" as the first rewrite rule in the root htaccess and the app/.htaccess
Which I did.
root .htaccess:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^(\.well-known/.*)$ $1 [L]
RewriteRule ^$ app/webroot/ [L]
RewriteRule (.*) app/webroot/$1 [L]
AddDefaultCharset UTF-8
</IfModule>
app/.htaccess:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^(\.well-known/.*)$ $1 [L]
RewriteRule ^$ webroot/ [L]
RewriteRule (.*) webroot/$1 [L]
AddDefaultCharset UTF-8
</IfModule>
But I still have the same problem
Any idea what I did wrong?
Thanks a lot
Cake's webroot has an .htaccess with a RewriteCond %{REQUEST_FILENAME} !-d rule that means cake will not be called in for any request that matches an actual directory inside webroot.
So just place the .well-known directory and everything else that is needed inside the webroot directory, you should be able to access them fine without messing up with .htaccess.
PS. In some cases the file Let's encrypt requires is not served back as text, in which case you should enable the headers apache module (if not enabled already) and put the following rule in your apache or virtualhost config:
<IfModule mod_headers.c>
<LocationMatch "/.well-known/acme-challenge/*">
Header set Content-Type "text/plain"
</LocationMatch>
</IfModule>

Installing CakePHP 2.4.7 on Windows

I am facing issue in my first intallation of CakePHP.
I am working on Windows OS and using WAMP. I am able to point my browser to localhost -> phpcake to open my installation of CakePHP.
However I get an error as below:
Missing Controller
Error: PhpcakeController could not be found.
Following are the steps which I followed for installing CakePHP:
Unzipped CakePHP, version 2.4.7 and loaded that in my WAMP
Created database using phpMyAdmin
Updated the app\Config\database.php file with login, password and databasename
The contents of the .htaccess files of cake is as below:
phpcake/.htaccess
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^$ app/webroot/ [L]
RewriteRule (.*) app/webroot/$1 [L]
</IfModule>
phpcake/app/.htaccess
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^$ webroot/ [L]
RewriteRule (.*) webroot/$1 [L]
</IfModule>
phpcake/app/webroot/.htaccess
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase D:/Vivek/phpcake/
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !^/(app/webroot/)?(img|css|js)/(.*)$
RewriteRule ^(.*)$ index.php [QSA,L]
</IfModule>
The mod_rewrite is disabled on my Apache. If I enable it, then I get 404 error on launching CakePHP install.
Could you guide me as to which step am I missing?
Finally i got it working. This is what i was doing (wrong).
In my WAMP i created an alias directory. Apache -> Alias -> Add an Alias Directory. In this alias i pointed to the location of my CakePHP unzipped folder. I updated the App/Config/Database.php to point to created MySQL database. However on selecting mod_rewrite module in Apache i was getting 404/403 errors. And without mod_rewrite i was getting missing controller error.
Missing Controller
Error: PhpcakeController could not be found.
I tried fresh installations 3 times with same results.
My understanding is that the mod_rewrite, the instructions in Alias file and .htaccess files were creating this trouble.
So this is what i did (Worked):
I copied my CakePHP into WAMP's www directory. That's it, it did the trick. I went through various articles about .htaccess, and mod_rewrite. Frankly speaking it is complex for me.

CakePHP not working, showing PHP Code inline PHP

Edit: I know what is causing the problem now, but still no solution. Basically unless the tmp directory is 777 Cake is unable to write to it so it fails. And if tmp is 777 then because of maybe some weird security setting PHP doesn't work. Any ideas if this is a possibility and how I can fix it?
Edit 2: Is it possible that because of character encoding the tmp is not 777 its showing ? garbage characters.
I just migrated my CakePHP app to Amazon AWS (Using a BitNami LAMPstack). I was getting PHP errors saying Could Not Connect to DB (which means PHP is executing).
When I fixed the DB settings it is now printing inline PHP.
For example:
<title><?php echo $title_for_layout; ?></title>
is showing in the HTML and the document title is hence a snippet of PHP code!
Please help I'm at a loss. Things I've tried doing:
Changing AllowOverride to All in the section in/opt/bitnami/apache2/conf/httpd.conf
Editing my php.ini for short_open_tag=On just in case
Making sure mod_rewrite is enabled in httpd.conf and that my htdocs and app folder have the correct .htaccess files.
Here are my .htaccess files just in case:
htdocs/.htaccess
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^$ app/webroot/ [L]
RewriteRule (.*) app/webroot/$1 [L]
</IfModule>
Options All -Indexes
htdocs/app/.htaccess
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^$ webroot/ [L]
RewriteRule (.*) webroot/$1 [L]
</IfModule>
htdocs/app/webroot/.htaccess
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php?/$1 [QSA,L]
</IfModule>
Well all I can say is thank god I paid attention in class last semester when they explained character encoding.
So I opened up all the .ctp files that weren't being exec'd as PHP in vim. I said :set encoding=utf-8 and :set fileencoding=utf-8
and then :x (keeping it newb-friendly just in case somebody wants a quick fix) :)
And its working like it should now. :)

Running a CakePHP project on Localhost

I have downloaded a CakePHP project from an online server and need to make it work locally, to do some changes.
I'm facing a problem similar to this one and have tried all possible solutions, with no luck.
Here's the situations:
Site home is in localhost/xpto (c:\xampp\htdocs\xpto) -> here, the site appears unformatted (no CSS) and too slow.
If I access localhost/xpto/something, I get the site with the CSS, but some links wont work.
I have mod_rewrite loaded (phpinfo()) together with the 3 .htaccess files, but still experience this problem.
Is there any known issue that I can explore to fix my site?
Please redirect me to any guides or tutorials that you may feel relevant to my issue
Use RewriteBase directive in .htaccess.
e.g my dev space is on my localhost, is located in /home/ati/public_html/cakerbs, under a subdir in my userdir. The rewriteBase looks like as follows in the root of the cake:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteBase /~ati/cakerbs
RewriteRule ^$ app/webroot/ [L]
RewriteRule (.*) app/webroot/$1 [L]
</IfModule>
in the app directory .htacces:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteBase /~ati/cakerbs
RewriteRule ^$ webroot/ [L]
RewriteRule (.*) webroot/$1 [L]
</IfModule>
in the webroot directory:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /~ati/cakerbs
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php?url=$1 [QSA,L]
</IfModule>
Check your XAMPP apache settings, it's very likely your current config is blocking things like the .htaccess files (I know EasyPHP does this by default with Cake). What I do to get around this error is to add a VirtualHost to my config like such:
<VirtualHost *>
DocumentRoot "C:/xampp/htdocs/xpto/"
ServerName xpto.dev
ServerAlias www.xpto.dev
ErrorLog "logs/xpto-error.log"
CustomLog "logs/xtpo-access.log" common
<Directory />
Options FollowSymLinks
AllowOverride All
Order deny,allow
Allow from all
</Directory>
</VirtualHost>
It may be better to update your whole config properly, but seeing as it's a dev environment for me, this does just fine. (Don't forget to add any hosts to your windows hosts file)
Then just open your favourite browser and go to http://xpto.dev/ and it should load up.
This may help your more: http://ailoo.net/2008/07/set-up-multiple-virtual-hosts-on-xampp-for-windows/

Resources