How to install cakephp on localhost? - cakephp

I wanna to know how to install cakephp on localhost?
Please explain me.

I usually make an apache and mysql installation on a linuxbox. I can use windows too, however I do not recommend it ;)
So, I usually make a new entry into the /etc/hosts file to make a sitename available to cakephp.
127.0.0.1 localhost caketest.local
next step to copy all cakephp files into a subdirectory inside /home/myusername/public_html/caketest
app
cake
index.php
plugins
README
vendors
.htaccess
then I set up the site to apache (not neccessary),
<VirtualHost *:80>
DocumentRoot "/home/myusername/public_html/caketest"
ServerName caketest.local
# This should be omitted in the production environment
SetEnv APPLICATION_ENV development
<Directory "/home/myusername/public_html/caketest">
Options Indexes MultiViews FollowSymLinks
AllowOverride All
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
restart apache. you also need to edit the .htaccess files and place a RewriteBase directive with hte path to the actual directory, e.g.
RewriteBase /~myusername/caketest
create a database, set the db connection in cake config files and that's all.
you can point your browser to http://caketest.local
if you do not want a test site url you can skip hosts, and apache vhost creation, but the url to use should be http:/localhost/~myusername/caketest
another important thing is to enable userdir modul in apache, and also check if using php is enabled in userdirs too.

If you're on windows, get WAMP. Install it, then download CakePHP in C:\wamp\www\. Extract CakePHP in that folder so you have a folder kind of like this: C:\wamp\www\cakephp\. Now you can access the installation by going to localhost/cakephp/.

An old article of mine but still quite relevant:
Installing CakePHP

Assuming you have a *AMP setup (Apache+MySQL+PHP), just copy the files to your htdocs folder. On Ubuntu, it's /var/www, so you would create /var/www/myApp and copy the whole Cake structure into there, ending up with something like:
/var/www/myApp/app/
/var/www/myApp/cake/
/var/www/myApp/vendors/
/var/www/myApp/index.php
/var/www/myApp/.htaccess
Then you can access your app by the url: http://localhost/myApp

Related

Apache localhost authentication

I am trying to setup up basic authentication to a folder on my localhost running apache. Currently the app runs fine without authentication. I have setup a virtual host so I can access my application through dev.myapp.com
The code I add to my .htaccess file to force authentication is:
<Directory "/Users/myusername/Sites/dev.myapp.com">
AuthType Basic
AuthName Test
AuthBasicProvider file
AuthUserFile /etc/apache_users
Require valid-user
</Directory>
I have created a user.
When I type dev.myapp.com into the browser I get an internal server error. I am fairly new to apache. A point in the right direction would be appreciated.
Thanks.
First off, using .htaccess is a bit slower and requires that you have set the AllowOverride directive accordingly. It is recommended that you instead use httpd.conf to establish basic authentication. The Apache documentation explains all of this so check out this link http://httpd.apache.org/docs/2.2/howto/auth.html.
Regardless, I think I see the error. Your <Directory> tag looks a little odd. I understand the name of your site is dev.my.app.com but is that the actual name of the folder where the site dev.myapp.com points to on your server? Your httpd.conf file should have an entry like this:
<VirtualHost *>
DocumentRoot "document/root/path"
Other directives here
</VirtualHost>
The DocumentRoot is where Apache directs all incoming web traffic. If you are trying to establish authentication for your entire site, the value of DocumentRoot is most likely what you would want in your Directory tag ... making it <Directory /document/root/path>.
To locate httpd.conf look in in /etc/apache2/. Make sure to restart your server after you change the file (sudo /etc/init.d/apache2 restart). Hope that helps, please update if you haven't already resolved the problem.

Vagrant 403 Forbidden

I've been running Vagrant successfully for about a week. Last night I ran vagrant reload and now I can no longer access my sites.
VirtualBox version 4.2.16
Vagrant version 1.2.7
My Vagrantfile and bootstrap.sh: https://github.com/kriskd/vagrant-settings
Running on Mac
My files live at /vagrant/Sites. At first my "welcome page" which lives at /vagrant/Sites rendered at
http://localhost:4567/
All my projects are folders under Sites. For example, /vagrant/Sites/test won't render index.html. I get the following
Forbidden
You don't have permission to access / on this server.
Apache/2.4.6 (Ubuntu) Server at localhost Port 4567
The vhost looks like:
<VirtualHost *:80>
DocumentRoot "/vagrant/Sites/test"
ServerName test
<Directory "/vagrant/Sites/test">
AllowOverride All
</Directory>
</VirtualHost>
The vhosts are owned by root. My project files are owned by vagrant and chmod'ed 0777.
After no success, I did a full vagrant destroy followed by vagrant up and then the localhost host welcome page stopped rendering as well with the forbidden error.
My hunch is that this is not a vagrant issue at all but solely an Apache configuration glitch. There are a few things I can think to check.
First, obviously, is to confirm that the user that apache is running under has read and execute permissions for the DocumentRoot folder.
Since you mentioned Apache 2.4, there have been changes in the configs from 2.2. Make sure your Allow from all statements now read Require all granted. (If you were still on 2.2, you'd want to make sure they said Allow from all instead of Deny from all.) In either case, you can set this in each <VirtualHost> individually, or set a default in your <Directory /> block of the main httpd.conf file.
Getting more obscure, you could check for selinux, although I'm pretty sure this isn't present in Ubuntu by default. (It is in CentOS, for example.)
This is solved and in the end came down to some very simple things.
Use "Require All granted" instead of "Allow from All"
Put each websites' content at the same level namely /vagrant/Sites/default, /vagrant/Sites/test, /vagrant/Sites/real-site
Add .conf extension to vhost names such as test.conf and real-site.conf
Add AllowOverride All to vhosts to respect sites' .htaccess file (I realize that was in my original post, it got lost as I tried to solve this)
All very basic things that eluded me for a better part of a week. I hope this can help someone else.
I had the same problem when changing the DocumentRoot.
Since you've changed your DocumentRoot to "/any/path/foo/bar", make sure you have the permissions set on "apache2.conf" for this path.
Search for:
<Directory /any/path/foo/bar>
in apache2.conf
And add a new block like this:
<Directory /any/path/foo/bar>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
And my guess is that everything is gonna be fine!
cd /etc/apache2/sites-available
for file in `ls *`; do sed 's/\(.*<\/Directory.*>\)/Require\ all\ granted\n\1/' $file > $file.new;mv $file.new $file ; done;
because it worked before, I would not waste time on fix file by file

cakephp URL get rid of /app/webroot

I have a application and I want to integrated it into my CakePhp website. I put it into webroot folder. I tried to open it in browser via
http//mywebsite.com/appname
but it failed. Instead, I need to reach it via
http//mywebsite.com/app/webroot/appname.
And will be redirect to
http//mywebsite.com/app/webroot/appname/index.
Anyone know how to get rid of the /app/webroot string in my url? I do check the cake routing documentation but feels like didn't found a solution there.
Your Apache virtual host is not configured right.
Your Document Root needs to point to the webroot dir:
<VirtualHost *:80>
DocumentRoot /mydir/somthing/cake/app/webroot
ServerName mywebsite.com
</VirtualHost>
Then this will work:
http//mywebsite.com/appname

cakephp - one framework, a few apps on localhost subdomain

How to prepare CakePHP framework to work for many apps in one CakePHP framework?
I want prepare structure folders like this:
app1/
app2/
app3/
cake/
vendors/
plugins/
index.php
I would like using http://app1.localhost/ do running app from app1/ folder?
It's possible?
Basically all you need to do is configure the app/webroot/index.php file of every individual app correctly to point to the correct ROOT/cake folder. The rest is Apache virtual host configuration to point the subdomains to the right app folder.
I'm running XAMPP but I'm assuming you're running something similar on your machine. Anyway, go into your apache\conf folder and open up the httpd.conf file. XAMPP has a file called apache\conf\extra\httpd-vhosts.conf that is better for adding Virtual Hosts.
So you'd want to enter the appropriate directives like so...
<VirtualHost *:80>
ServerAdmin postmaster#localhost
DocumentRoot "C:/path-to-your-app-webroot-folder-no-trailing-slash"
ServerName app.localhost
##ServerAlias www.dummy-host.localhost
ErrorLog "logs/app.localhost-error.log"
CustomLog "logs/app.localhost-access.log" combined
<Directory "C:/path-to-your-app-webroot-folder-no-trailing-slash">
Options Indexes FollowSymLinks Includes ExecCGI
AllowOverride All
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
Furthermore, if you're on Windows XP, you'll want to make an entry in your C:\Windows\system32\drivers\etc\hosts file of 127.0.0.1 app.localhost to resolve the sub-domain. That should get the job done.

Newbie - what do I need to do with httpd.conf to make CakePHP work correctly?

(Not sure if this belongs here or on webmasters; please move if necessary.)
I'm a total newbie to Cake and not much better with apache; I've done
a lot of PHP but always with a server that's already been set up by
someone else. So I'm going through the basic blog tutorial, and it
says:
A Note On mod_rewrite
Occasionally a new user will run in to mod_rewrite issues, so I'll
mention them marginally here. If the Cake welcome page looks a little
funny (no images or css styles), it probably means mod_rewrite isn't
functioning on your system. Here are some tips to help get you up and
running:
Make sure that an .htaccess override is allowed: in your httpd.conf,
you should have a section that defines a section for each Directory on
your server. Make sure the AllowOverride is set to All for the correct
Directory.
Make sure you are editing the system httpd.conf rather than a user- or
site-specific httpd.conf.
For some reason or another, you might have obtained a copy of CakePHP
without the needed .htaccess files. This sometimes happens because
some operating systems treat files that start with '.' as hidden, and
don't copy them. Make sure your copy of CakePHP is from the downloads
section of the site or our SVN repository.
Make sure you are loading up mod_rewrite correctly! You should see
something like LoadModule rewrite_module libexec/httpd/mod_rewrite.so
and AddModule mod_rewrite.c in your httpd.conf."
I'm using XAMPP on linux. I've found my httpd.conf file in opt/lampp/
etc, but am not sure what I need to do with it. I've searched for
"rewrite", and there's only one line:
LoadModule rewrite_module modules/mod_rewrite.so
There's nothing about AddModule mod_rewrite.c.
Do I just create a Directory section for the directory I've installed
Cake in and set AlllowOverride to All? (I created a separate
subdirectory of my wwwroot and installed in there, since I also have
installs of Joomla and CodeIgniter.) Is there anything else I need to
do? My download of Cake did come with two htaccess-type files
(._.htaccess and .htaccess) - do I need to do anything with them?
Thanks for any help you can provide to this non-server-admin.
EDIT TO ADD virtual host sample:
<VirtualHost *:80>
ServerAdmin webmaster#dummy-host.example.com
DocumentRoot /www/docs/dummy-host.example.com
ServerName dummy-host.example.com
ServerAlias www.dummy-host.example.com
ErrorLog logs/dummy-host.example.com-error_log
CustomLog logs/dummy-host.example.com-access_log common
</VirtualHost>
Step 1. You should have mod_rewrite enabled, check using <?php phpinfo();
Step 2. Check AllowOverride
// I believe you already did that.
// Make sure you are doing it for the correct webroot!
<Directory />
AlllowOverride to All
</Directory>
Step 3. Check your default .htaccess files are there in directories /mypro, /mypro/app, /mypro/app/webroot.
Step 4. .htaccess may need path fixes depending upon your cake project installation.
e.g. project url http://localhost/mypro/app/webroot/
/mypro/app/webroot/.htacess
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^$ mypro/app/webroot/ [L]
RewriteRule (.*) mypro/app/webroot/$1 [L]
</IfModule>
EDIT
If you are trying to setup it as local domains, Setup local domains (on windows) with WAMP configured
Note: this may be tweaked a little for different kind of installations
Find your hosts file (mine is located at C:\WINDOWS\system32\drivers\etc\hosts)
Insert this to bottom
# save and close this file named hosts
127.0.0.1 mypro.localhost
To test hostname open command prompt and run ping mypro.localhost # If ping is good then move on
Now open your apache config file
httpd.conf and httpd-vhosts.conf (my files are located at)
C:\wamp\bin\apache\Apache2.2.11\conf\httpd.conf
# uncomment line below
Include conf/extra/httpd-vhosts.conf
C:\wamp\bin\apache\Apache2.2.11\conf\extra\httpd-vhosts.conf
# Insert virtual host entries like this, trim dummy entries (if any)
# Changing DocumentRoot
<VirtualHost *:80>
DocumentRoot "C:/wamp/www"
ServerName localhost
</VirtualHost>
<VirtualHost *:80>
DocumentRoot "C:/wamp/www/mypro/app/webroot"
ServerName mypro.localhost
</VirtualHost>
Save and close files
Create directory C:/wamp/www/mypro (if you haven’t created before)
ModRewrite enables Apache to manipulate request URLs before it handles the request. For example, if you wanted to store your images in /website_images but you wanted to reference them in your HTML as /img/donkey.jpg you could use ModRewrite to change all requests from /img/* to /website_images/*. The way that it handles this is through Regular Expressions, which have entire books written about them.
As far as Apache goes, there are lots of configuration "directives" (aka options or settings). The most crucial to learn about when you're running your own server are going to be the VirtualHost ones. They allow Apache to handle requests to your server's IP address and route them to the correct website based on the hostname (the domain, essentially). You should place any website-specific directives within that website's VirtualHost configuration, including your ModRewrite rules. Note: you can also load additional directives from a .htaccess file in the website's directory, but this is suboptimal (and requires AllowOverride to be set. If you have access to httpd.conf and the related VirtualHost directives, you should use them instead.
It looks like Apache is already configured to load the ModRewrite module, so you don't need to change that. In the VirtualHost directives for your new CakePHP website, you can use the following directives under the <Directory /path/to/your/website> to setup ModRewrite:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php?url=$1 [QSA,L]
</IfModule>
It looks big and scary, but what that does is tells Apache to direct all requests that it can't handle (because the resources don't exist) to index.php. When that happens, CakePHP takes over and routes the request to the appropriate controller and action.
I'm not familiar with how XAMPP is configured, so I can't tell you where those VirtualHost definitions are going to be. Perhaps someone else can chime in here…

Resources