Subversion is a robust, open source version control system for software development. CodeIgniter is a powerful but lean Object Oriented PHP-based web development framework which utilizes the Model-View-Controller approach.
For quite a while, I used CVS for my revision control, but recently migrated to Subversion due to it's superior capabilities. If you're developing multiple CodeIgniter web sites which share system code and you're looking into implementing a revision control system. Here are some guidelines.
Mac OS X users can utilize apt-get by installing the fink package.
If not already installed
$ sudo apt-get subversion
The steps below outline how to set up and access repositories stored on a remote svn server. If your repositories will be stored locally, then you don't need to setup an svn user or run svnserve. You can checkout and commit files using the file:/// protocol specification in place of svn://server/. You also won't need to worry about setting up access permissions. if you are the only user accessing your repositories.
Create the svn user
$ sudo adduser --home /home/svnuser svnuser
Create the path for the repository
$ sudo mkdir /var/svn
$ sudo chown svnuser:svnuser /var/svn
Launch the svn server (must be run as svn user)
$ sudo -u svnuser svnserve -i -r /var/svn
Setup init.d to launch svnserve at startup. Edit /etc/inetd.conf and add the following line:
svn stream tcp nowait svnuser /usr/bin/svnserve svnserve -i -r /var/svn
Create the repository (must be run as user svn). You can keep your repositories anywhere on your machine. Mac OS X users might want it in /Users/Shared, for example.
$ sudo -u svnuser svnadmin create /var/svn/repos
Setup authentication by edit the svnserve.conf file in the conf directory. Uncomment the following line to use the default password file:
#password-db = passwd
Edit the passwd file and change user names & passwords as desired:
# harry = harryssecret
# sally = sallyssecret
Since passwords are stored as clear text, change the permissions on everything under the svn directory to prevent access by anyone but the svn user
$ sudo chmod -R o-rwx /var/svn
To import a new source code tree to the above repository, navigate to the parent directory of the source tree, then:
$svn import project --username harry --password harryssecret \
svn://server/var/svn/project -m "Initial Import"
the username and password must match the ones you setup in the passwd file earlier.
The -m option specifies a message to be included in the log. For future revisions, you can include a descriptive message of the changes here.
Once the source tree has been imported into the repository, you can delete it (or better yet, rename it), then checkout the source to make revisions.
$svn checkout svn://server/var/svn/project
The above command will recreate the source tree from the repository, adding a hidden .svn subdirectory directory to each directory which contains the revision control information.
To setup an svn external reference (link to an external repository):
$ export SVN_EDITOR=vim
$ svn propedit svn:externals /path/to/project
public http://svn.ellislab.com/CodeIgniter/trunk
Save & quit the editor, and your new external property is created.
Web developers typically have multiple projects under development at any one time, commonly hosted on the localhost web server. The best way to handle this is to configure Virtual Hosts under apache. Otherwise, you'll end up with URLs pointing to subdirectories and you'll have to include special configuration settings to point to the appropriate subdirectory. For details, see my post on setting up Virtual Hosts on Apache.
After working with CodeIgniter for while, I’ve worked out the following system for development and revision control of a CI site. The method I've outlined below involves creating a central location for your CodeIgniter system folder which can be shared between multiple CI sites, and allows linking to the CI svn repository for ease of updating the CI system code.
First off, here is the folder heirarchy under your web server's DocumentRoot. First for the CodeIgniter Base code:
CI/ CI/ system/ user_guide/ index.php license.txt
The reason for the double "/CI/CI" is due to the subversion repository setup as explained below. Your repository will be called "CI", and when you checkout the files from the repository, it will create a subdirectory called "CI". Next the folder hierarchy for the site & application folders:
example1.com/ index.php .htaccess favicon.ico css/ js/ images/ app/ config/ controllers/ (etc) example2.com/ index.php .htaccess favicon.ico css/ js/ images/ app/ config/ controllers/ (etc)
All of the CodeIgniter application files (models, views, controllers, libraries, etc) reside under the app folder. I then copy the index.php file from a standard CI installation, and modify the following variables:
$system_folder = "../CI/CI/system";
$application_folder = "app";
The layout works well with VirtualHosts under Apache, and splits your code and resources out of the CodeIgniter sources. Splitting your stuff from the CodeIgniter stuff lets you link your Subversion repository to theirs, so that you can keep it in sync with their development.
On the subversion server create a repository for the base CI code.
$ sudo -u svnuser svnadmin create /var/svn/CI
Add the appropriate access by editing svnserve.conf and password files as shown above.
Add a svn link to CodeIgniter’s repo
$svn propedit svn:externals
If you get a message that the editor isn't setup, then set the shell enviroment variable to your preferred editor. IE, to use vim:
$ export SVN_EDITOR=vim
When the editor is launched, add a single line:
public http://svn.ellislab.com/CodeIgniter/trunk
run an svn update to grab the framework
$ svn update
If you have an existing CodeIgniter application that you are adding to your subversion repository, rearrange your folder hierarchy to match the above layout. If you're starting a new code igniter site, you can copy the stock applications directory from the stock CI/system diretory to a directory called "app" within the site folder (ie, from {DocumentRoot}/CI/CI/system/applications to {DocumentRoot}/example1.com/app). Once this is complete, you can import the site into your repository.
$ svn import example1.com svn://server/var/svn/example1.com
Delete (or rename) the original
$ mv example1.com example1.com-pre_svn
Checkout the code
$ svn checkout svn://sever/var/svn/example1.com
This will re-create the directory structure of your site under the folder "example1.com", with the addition of the necessary .svn subdirectories which support the revision control process. For the most part, you can ignore the .svn files. Most FTP utilities will not transfer them to your web server when doing a site-wide upload.
If you need to generate a folder hierarchy of your site without the .svn directories for uploading to a web server, you can issue the following command
$ svn export svn://server/var/svn/example1.com example1.com-export
This is essentially identical to a "checkout", but does not include the .svn directories.
Comments
Nice work!
Keep more like this coming guy!