Please give me a step by step process on how to install CodeIgniter on Ubuntu. I'm still a newbie. Thank you!

2 Answers 2


Assuming you have Apache2 installed and running...

Create a home for CI in the /opt directory. (Another place we could use is /usr/local, but Ubuntu likes to reserve /opt as the safe place for locally-installed software, so let's use that.)

Become root; make a directory; download CI. (The switch with wget is not zero; it's capital O.)

sudo su -
mkdir -p /opt/share/php
cd /opt/share/php
wget http://codeigniter.com/download.php -O CodeIgniter_2.0.0.zip

Unzip the archive. The files were archived from a Windows machine, so they all have the executable bit set. We do not want that, so we change them to 0644. The CI framework version will change from time to time, but I only want to refer to it as "ci" (and not "CodeIgniter_2.0.0"). If it changes to CodeIgniter_2.0.1 tomorrow, I can change the symbolic link to point to a new version without editing any other files...

unzip CodeIgniter_2.0.0.zip && rm CodeIgniter_2.0.0.zip
find /opt/share/php -type f -exec chmod 0644 {} \;
ln -s CodeIgniter_2.0.0 ci

Let's add CI to PHP include_path. Use a different text editor than vim, maybe gedit, if you like...

vim /etc/php5/apache2/php.ini

And the relevant portion of php.ini to change:

; Paths and Directories ;

; UNIX: "/path1:/path2"
include_path = ".:/opt/share/php/ci/system:/usr/share/php"

Save. Assuming we have nothing we want right now in /var/www, remove whatever is already in the /var/www directory; make directories for CI logging and caching; and, copy the application directory.

cd /var/www
rm -rf *
mkdir public logs cache
cp -rp /opt/share/php/ci/application .
cp /opt/share/php/ci/index.php public/

Let's set some CI variables. Use a different text editor than vim, maybe gedit, if you like...

vim public/index.php

And the relevant variables to change:

$system_folder = "/opt/share/php/ci/system";
$application_folder = "../application";

Save. Now let's set up Apache, using your favorite text editor over vim if you like:

vim /etc/apache2/sites-enabled/000-default

And as an example, the file contents (change ServerAdmin and ServerName):

<VirtualHost *:80>
    ServerAdmin your@email.com
    ServerName www.hostname.com
    DocumentRoot /var/www/public
    ErrorLog ${APACHE_LOG_DIR}/error.log
    LogLevel warn 
    CustomLog ${APACHE_LOG_DIR}/access.log combined

    <Directory />
        Options FollowSymLinks
        AllowOverride None

    <Directory /var/www/public/>
        Options Indexes FollowSymLinks MultiViews
        AllowOverride None
        <IfModule mod_rewrite.c>
            RewriteEngine On
            RewriteBase /
            RewriteCond %{REQUEST_FILENAME} !-f
            RewriteCond %{REQUEST_FILENAME} !-d
            RewriteRule ^(.*)$ index.php?/$1 [L]
        Order allow,deny
        allow from all

    Alias /user_guide/ "/opt/share/php/ci/user_guide/"
    <Directory "/opt/share/php/ci/user_guide/">
        Options Indexes MultiViews FollowSymLinks
        AllowOverride None
        Order deny,allow
        Deny from all
        Allow from ::1/128
        Allow from ::1/128
        Allow from ::1/128

Save. Now let's do what CI needs us to do in order to remove "index.php" from the URL, while also defining "base_url" to the value of the SERVER_NAME.

vim /var/www/application/config/config.php

And the relevant portion of that file:

$config['base_url'] = 'http://' . $_SERVER['SERVER_NAME'] . '/';
$config['index_page'] = '';

Save. Now let's set up ACL, so that permissions are very nice. First mount the file systems with the acl option in /etc/fstab.

vim /etc/fstab

UUID=xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx / ext4 defaults,acl 0 1

mount -o remount,acl /

Then make a group to which a user may belong for this purpose (your user).

groupadd developers
usermod -a -G developers $username

The user needs to log out and in again to become a member of the developers group. Here we'll let members of the developers group do what they wish within the public and application directory, while the Apache user can read. However, the logs and cache directories are for root and apache only. (Done as an example.)

chown -R root.developers /var/www/public
chmod 0775 /var/www/public
chmod g+s /var/www/public
setfacl -d -m u::rwx,g::rwx,o::r-x /var/www/public
chown -R root.developers /var/www/application
chmod 0775 /var/www/application
chmod g+s /var/www/application
setfacl -d -m u::rwx,g::rwx,o::r-x /var/www/application
find /var/www/application -type d -exec setfacl -d -m u::rwx,g::rwx,o::r-x {} \;
find /var/www/application -type f -exec setfacl -m u::rw-,g::rw-,o::r-- {} \;
chgrp www-data /var/www/logs
chgrp www-data /var/www/cache
chmod 0770 /var/www/logs
chmod 0770 /var/www/cache

Restart Apache.

service apache2 restart

Install an IDE. (Komodo Edit is also a very nice IDE.) Netbeans uses php-doc.

apt-get install netbeans php-doc

I have trouble with fonts in NetBeans unless I use the Sun JDK.

apt-get install sun-java6-jdk

Open NetBeans. Go to:

Tools->Plugins->Available Plugins

Find PHP and install it. Make a new project:

File->New Project->PHP with existing sources...

Existing sources are located in /var/www. Use PHP 5.3.

If you follow this, you'll get:

  • A common location for CI, so that it will be easy and efficient to build many sites
  • An easy way to upgrade CI
  • A safe place for CI to survive a distribution upgrade
  • Correct CI file permissions
  • Correct PATH and CI variables
  • Flexible permissions within /var/www
  • Correctly functioning mod_rewrite settings
  • Documentation available locally at /user_guide/
  • A nice IDE with code completion - even CI code completion (not just PHP)

Assuming you have Apache up and running, just follow the Installation Instruction from the official documentation:

CodeIgniter is installed in four steps:

  • Unzip the package.

  • Upload the CodeIgniter folders and files to your server. Normally the index.php file will be at your root.

  • Open the application/config/config.php file with a text editor and set your base URL. If you intend to use encryption or sessions, set your encryption key.

  • If you intend to use a database, open the application/config/database.php file with a text editor and set your database settings.

(further instructions)

  • i tried copying the codeigniter files in my /var/www but i cant even paste my files there, it says i dont have permission,, what do i do?i installed apache2, mysql and php5,
    – RedKing
    Feb 9, 2011 at 13:02
  • This is not an uncommon issue. See this answer on how to make apache use a directory you own (that is, a directory you have write access to). Alternatively, hit Alt+F2 and type gksu nautilus to access the directory with superuser privileges (not recommended). We have a bunch of questions about permissions here, try finding one that solves your problem, or ask a new one if you can't find any. If you do, make sure to explain your situation in detail. Feb 9, 2011 at 13:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.