Combining CoughPHP and LightVC

February 16, 2009
Tags: ,

In this tutorial, we will be creating an MVC application using the bare LightVC and CoughPHP distributions.

For the purposes of this tutorial, I will be working on my Macbook, with Apache 2. You may need to consult your documentation on your webserver to set up the server configs correctly.

Step 1:
Download the LightVC and CoughPHP distribution files.

I am using CoughPHP version 1.3.5 and LightVC 1.0.4 for this tutorial.

Step 2:
Unpack the LightVC and CoughPHP distributions.
I used the following command to unpack LightVC:

cd ~/Documents/
mkdir Source
cd Source
unzip -d ~/Downloads/

And CoughPHP:

cd ~/Documents/Source/
cd modules
tar -xzvf ~/Downloads/coughphp-1.3.5.tgz
mv coughphp-1.3.5 coughphp

Step 3:
Prepare LightVC.
Upon unpacking the LightVC distribution, I noticed that unzip set the permissions wrong, so I had to do the following:

cd ~/Documents/Source/
chmod -R a+r .
chmod a+x * webroot/* views/* modules/coughphp modules/coughphp/*

In addition the autoloader will need a world writable tmp directory:

cd ~/Documents/Source/
mkdir tmp
chmod 777 tmp

Step 4:
Edit your /etc/hosts file:

sudo nano /etc/hosts

(you will be prompted for your password)
Change the line to look like	localhost

Step 5:
Edit your apache conf files and (re)start apache

sudo nano /etc/apache2/httpd.conf

Add the lines:

		<Directory "/Users/pistole/Documents/Source/">
		    Options Indexes FollowSymLinks MultiViews

		    AllowOverride All

		    Order allow,deny
		    Allow from all


Replacing /Users/pistole/Documents/Source/ with the path you installed LightVC into.
Then run

sudo nano /etc/apache2/extra/httpd-vhosts.conf

Add the lines:

		<VirtualHost *:80>
		    DocumentRoot "/Users/pistole/Documents/Source/"
		    ErrorLog "/private/var/log/apache2/www-error_log"
		    CustomLog "/private/var/log/apache2/www-access_log" common
		    AddType application/x-httpd-php .php .html

Again, setting the right path. Also set the ServerAdmin to your email address.
Now start apache:

sudo /usr/sbin/apachectl start

If that doesn’t work, try:

sudo /usr/sbin/apachectl restart

Step 6:
Configure the Autoloader
edit and replace the following lines:

		// Lvc doesn't autoload the AppController, so we have to do it: (this also means we can put it anywhere)
		include(APP_PATH . 'classes/AppController.class.php');
		include(APP_PATH . 'classes/AppView.class.php');


		include(APP_PATH . 'modules/coughphp/extras/Autoloader.class.php');
		Autoloader::setCacheFilePath(APP_PATH . 'tmp/class_path_cache.txt');
			APP_PATH . 'classes/',
		spl_autoload_register(array('Autoloader', 'loadClass'));

This will load any classes named *.class.php in your directory automagically, including the aforementioned AppController and AppView classes.
Step 7:
Load the base CoughPHP include:
Once again edit and add the following below the autoloader block:

		include(APP_PATH . 'modules/coughphp/');
		include(APP_PATH . 'modules/coughphp/as_database/');

Step 8:
You’re done!
You have successfully created a LightVC application that loads the CoughPHP framework! go to in your browser to see your handywork!
In the next part of our tutorial, we will set up CoughPHP to talk to the database, generate some models and use them in the application.

6 Responses to “Combining CoughPHP and LightVC”

  1. good article. when will the next post be going up?

  2. It’s mostly written, hopefully in the next couple of days.

  3. I read your posts for quite a long time and should tell you that your articles always prove to be of a high value and quality for readers.

  4. how would i make sure its unpacked with correct folder permissions in windows? coz i think due to this i get a page not found error in your last tutorial for looking at

  5. please help me get this fixed, i really wish to learn lightvc with cough

  6. It would mean a lot to me if you could provide a zip package with the finished tutorial.. i can’t get things to work 🙁