Showing posts with label php. Show all posts
Showing posts with label php. Show all posts

Sunday, September 28, 2008

Setting up Cake on a custom folder

I wanted to try the PHP framework Cake, but if you look at the documentation it assumes you want to install Cake under the /var/www/html folder.

You can obviously install to other folders, but if not done properly, you'll encounter a start page with no images, no styles, and some error messages.

The steps I took to make Cake work in my folder (/home/me/dev/myapp) and to work with the http://localhost/myapp URL where:

  1. Uncompress the latest version of Cake to /home/me/dev/myapp
  2. Edit my /etc/apache2/users/me.conf and add the following (replace braces with chevrons):
    Alias /myapp/ "/home/me/dev/myapp/"
    {Directory "/home/me/dev/myapp/"}
    AllowOverride All
    Order allow,deny
    Allow from all
    {/Directory}
  3. Edit the .htaccess file in your /home/me/dev/myapp folder and add RewriteBase /myapp/ to it. Should look something like (replace braces with chevrons):
    {IfModule mod_rewrite.c}
    RewriteEngine on
    RewriteBase /myapp/
    RewriteRule ^$ app/webroot/ [L]
    RewriteRule (.*) app/webroot/$1 [L]
    {/IfModule}
  4. Make sure your /home/me/dev/myapp/app/tmp folder is writable by all
  5. Restart apache

And that's it. After these steps you should be able to access your application and see the default Cake page, including images & CSS.

Tuesday, June 10, 2008

PHP on the Mac

If you have a Mac with Leopard and want to use PHP, most of what you need is already installed. It's just a matter of making it work.

First you need to turn on apache. Just go to your "System Preferences", "Sharing" and turn on "Web Sharing". That's it, apache is running. You can check if all is ok by going to http://localhost.

You'll probably want MySql too. Just go to their site, download and install. No big fuss, but make sure you install the StartupItem if you want MySql to start when the system boots.

Next you must enable PHP. Launch a terminal and use your favorite text editor to edit /etc/apache2/httpd.conf. Look for LoadModule php5_module and uncomment the line. Restart apache with sudo apachectl graceful.

Now let's say your username is john, and you have on your home folder a ~/dev/phpproj where your php code is. One way to make this available (and there's lots of others) is to edit /etc/apache2/users/john.conf and add the following to the bottom of the file (replace [ with "lesser than" and ] with "greater than". Blogger doesn't like those symbols):
Alias /phpproj/ "/Users/john/dev/phpproj/"
[Directory "/Users/john/dev/phpproj/"]
Options Indexes MultiViews
Order allow,deny
Allow from all
[/Directory]
Now you can access http://localhost/phpproj/ to view your app.

At this point you might get a MySql error stating that you /var/mysql/mysql.sock does not exist, just go back to your terminal window and type:

cd /var
sudo mkdir mysql
cd mysql
sudo ln -s /private/tmp/mysql.sock mysql.sock

That's it!