Click Technology

Linux, Windows, Mac it's all good

Set up CodeIgniter quickly…

September12

The CodeIgniter framework is great, even the documentation is spot on being short and to-the-point.

They have installation instructions, sure, but here’s the commands to download it and set it up with the folders in the correct place.

First step, log into your server over SSH. I assume you are using Apache in this process for the web configuration, and that your root folder for serving web files is /var/www as is typical.

If you’re using nginx or something else, server side config is still straightforward, just a question of setting your document root AFAICS.

Here’s the steps..

This will download the CodeIgniter yip, unpack it, set it up, add a .htaccess file, set up the database connection and make you feel good about yourself generally. Use with the ususal care and attention.

cd /var/www
sudo rm -rf /var/www/yourwebsite.com
sudo mkdir /var/www/yourwebsite.com
cd /var/www/yourwebsite.com
sudo wget https://ellislab.com/codeigniter/download --output-document=./CodeIgniter_2.2.0.zip
sudo unzip CodeIgniter_2.2.0.zip
sudo rm CodeIgniter_2.2.0.zip
sudo mv ./CodeIgniter_2.2.0 ./public_html
sudo mv ./public_html/system/ ./
sudo mv ./public_html/application ./
sudo sed -i s/"$system_path = 'system';"/" = '\/var\/www\/yourwebsite.com\/system';"/g ./public_html/index.php
sudo sed -i s/"$system_path = 'application';"/" = '\/var\/www\/yourwebsite.com\/application';"/g ./public_html/index.php
sudo su -c $'echo "RewriteEngine on" >> /var/www/yourwebsite.com/public_html/.htaccess'
sudo su -c $'echo "RewriteCond \$1 !^(index\.php|images|robots\.txt)" >> /var/www/yourwebsite.com/public_html/.htaccess'
sudo su -c $'echo "RewriteRule ^(.*)$ /index.php/\$1 [L]" >> /var/www/yourwebsite.com/public_html/.htaccess'
sudo sed -i s/"\$autoload\['libraries'\] = array('');"/"\$autoload\['libraries'\] = array('database');"/g /var/www/yourwebsite.com/application/config/autoload.php
sudo sed -i s/"\$db\['default'\]\['username'\] = '';"/"\$db\['default'\]\['username'\] = 'your_database_username_for_your_codeigniter_app';"/g /var/www/yourwebsite.com/application/config/database.php
sudo sed -i s/"\$db\['default'\]\['password'\] = '';"/"\$db\['default'\]\['password'\] = 'your_database_password_for_username_above';"/g /var/www/yourwebsite.com/application/config/database.php
sudo sed -i s/"\$db\['default'\]\['database'\] = '';"/"\$db\['default'\]\['database'\] = 'my_codeigniter_app_database';"/g /var/www/yourwebsite.com/application/config/database.php
sudo su -c $'chown -R www-data:www-data /var/www/yourwebsite.com'
sudo su -c $'find /var/www/yourwebsite.com -type f -print0 | xargs -0 chmod 0664'
sudo su -c $'find /var/www/yourwebsite.com -type d -print0 | xargs -0 chmod 0775'
sudo su -c $'service apache2 restart'

OK, that’s it. Start working on the app. The part below was a step by step for the apache side of things when I wrote the article earlier, so I’ll leave it here for inspection. As far as you’re concerned, the CodeIgniter app is ready to go.

All you need to do now is configure your apache server. You’re using virtual hosts? Great. here’s the code..

Create the site configuration file…

sudo touch /etc/apache2/sites-available/yourwebsite.de

Open it for editing (say with vim or your favourite editor)

sudo vim /etc/apache2/sites-available/yourwebsite.de

Paste in the code below…

<virtualhost *:80>
        ServerName yourwebsite.de
        ServerAlias www.yourwebsite.de
        ServerAdmin webmaster@localhost
        DocumentRoot /var/www/yourwebsite.de/public_html
        <directory></directory>
                Options FollowSymLinks
                AllowOverride None
        
        <directory /var/www></directory>
                Options Indexes FollowSymLinks MultiViews
                AllowOverride All
                Order allow,deny
                allow from all
        

        ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
        <directory "/usr/lib/cgi-bin">
                AllowOverride None
                Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
                Order allow,deny
                Allow from all
        </directory>

        ErrorLog ${APACHE_LOG_DIR}/error.log

        # Possible values include: debug, info, notice, warn, error, crit,
        # alert, emerg.
        LogLevel warn

        CustomLog ${APACHE_LOG_DIR}/access.log combined
</virtualhost>

Save and close the file with

:wq

Now create a symlink from the sites-available to the sites-enabled folder to make the site appear…

sudo ln -s /etc/apache2/sites-available/yourwebsite.de /etc/apache2/sites-enabled/yourwebsite.de

.. and restart apache..

sudo service apache2 restart

Done.

posted under Linux Tips

Email will not be published

Website example

Your Comment:

This is my website for short blog posts and interesting materials that are noteworthy or have some handy-tip value.