Ubuntu CodeIgniter Setup: A Step-by-Step Installation Guide

Ubuntu CodeIgniter Setup: A Step-by-Step Installation Guide

For developers looking to start with CodeIgniter on Ubuntu, the Ubuntu CodeIgniter setup is a crucial initial step. This guide will walk you through installing and configuring Apache, PHP, MySQL, and CodeIgniter on Ubuntu, ensuring a smooth setup for your web development environment.

Ubuntu CodeIgniter Setup: A Step-by-Step Installation Guide

Step 1: Update and Upgrade Your Ubuntu System

Begin by updating your system to ensure you have the latest security patches and software updates. Open a terminal and run:

$ sudo apt update && sudo apt upgrade -y

For more details on Ubuntu updates, visit Ubuntu Documentation.

This ensures that your Ubuntu CodeIgniter setup is built on a stable and secure foundation.

Step 2: Install Apache Web Server

Apache is a popular web server required for running CodeIgniter. Install it with:

$ sudo apt install apache2 -y

For configuration details, refer to the Apache HTTP Server Documentation.

Start and enable Apache to run on system boot:

$ sudo systemctl start apache2
$ sudo systemctl enable apache2

Verify the installation by navigating to http://localhost in your browser.

Step 3: Install PHP and Necessary Extensions

CodeIgniter is built on PHP, so install PHP along with essential extensions:

$ sudo apt install php libapache2-mod-php php-mysql php-xml php-mbstring php-curl -y

For PHP documentation, visit PHP Documentation.

Check the PHP version to confirm it’s installed correctly:

$ php -v

Step 4: Install MySQL Database Server

MySQL is commonly used with CodeIgniter for database management. Install it by running:

$ sudo apt install mysql-server -y

Consult the MySQL Documentation for additional details.

Secure the MySQL installation with:

$ sudo mysql_secure_installation

Step 5: Create a MySQL Database for CodeIgniter

Log in to the MySQL shell:

$ sudo mysql -u root -p

Create a database and user for CodeIgniter:

CREATE DATABASE codeigniter_db;
CREATE USER 'ci_user'@'localhost' IDENTIFIED BY 'strong_password';
GRANT ALL PRIVILEGES ON codeigniter_db.* TO 'ci_user'@'localhost';
FLUSH PRIVILEGES;
EXIT;

Replace strong_password with a secure password.

Step 6: Install Composer

Composer manages PHP dependencies. Install it with:

$ sudo apt install composer -y

For details, visit the Composer Documentation.

Verify the installation:

$ composer --version

Step 7: Install CodeIgniter

Navigate to the directory where you want to install CodeIgniter:

$ cd /var/www/html/

Use Composer to install CodeIgniter:

$ composer create-project codeigniter4/appstarter codeigniter

Step 8: Configure Apache for CodeIgniter

Create a virtual host file for CodeIgniter:

$ sudo nano /etc/apache2/sites-available/codeigniter.conf

Add the following configuration:

apacheCopy code<VirtualHost *:80>
    ServerAdmin webmaster@localhost
    DocumentRoot /var/www/html/codeigniter/public
    ServerName codeigniter.local

    <Directory /var/www/html/codeigniter/public>
        AllowOverride All
        Require all granted
    </Directory>

    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

For more on Apache virtual hosts, see Apache Virtual Hosts Documentation.

Enable the site and rewrite module:

$ sudo a2ensite codeigniter.conf
$ sudo a2enmod rewrite

Restart Apache:

$ sudo systemctl restart apache2

Step 9: Configure /etc/hosts File

Add an entry to the /etc/hosts file to access CodeIgniter via http://codeigniter.local:

$ sudo nano /etc/hosts

Add the following line:

127.0.0.1    codeigniter.local

Save and exit.

Step 10: Verify Your CodeIgniter Installation

Open your browser and visit http://codeigniter.local. You should see the CodeIgniter welcome page if the Ubuntu CodeIgniter setup was successful.

For more tutorials and guides, check out Ubuntu CodeIgniter Setup Tutorial.

Conclusion

You’ve completed the Ubuntu CodeIgniter setup! With Apache, PHP, MySQL, and Composer configured, you’re now ready to develop with CodeIgniter. Keep your system updated and secure to maintain a stable development environment.

Happy coding with CodeIgniter on Ubuntu!

Leave a Reply

Your email address will not be published. Required fields are marked *