Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Set Up CodeIgniter for Your Website
#1

    Set Up CodeIgniter for Your Website
   

Set Up CodeIgniter for Your Website


   

Step 1. Installing CodeIgniter

   

CodeIgniter can be installed automatically via Composer or manually by using File Manager.

   

Install CodeIgniter 4 Using Composer

   
           
  1. Log in to your SSH account and navigate to the public_html root directory with this command:
  2.        
    cd domains/yourdomain.com/public_html
           
  3. Install CodeIgniter 4.
  4.        
    composer create-project codeigniter4/appstarter project-root
           
  5. For convenience, move the contents of project-root to the public_html directory.
  6.        
    mv project-root/* /home/u123456789/domains/yourdomain.com/public_html
           
  7. Once that’s done, enter this URL into the browser:
  8.        
    https://yourdomain.com/public
       
   

Install CodeIgniter 4 Manually

   
           
  1. Download the latest version of CodeIgniter.
  2.        
  3. Using File Manager, extract it in the root directory – yourdomain.com/public_html.
  4.        
  5. The framework-4.1.9 folder will appear. Open it and double-click the folder within.
  6.        
  7. Press CTRL + A to select all the files and use the Move button to transfer everything to public_html.
  8.        
  9. Open the browser and enter this URL:
  10.        
    https://yourdomain.com/public
       

   

Step 2. Configuring CodeIgniter

   

After installing CodeIgniter, it’s crucial to configure it so it works correctly.

   

Configuring CodeIgniter for Shared Plans

   
           
  1. Navigate to File Manager and open the Database.php file for editing. Here’s the full path:
  2.        
    /domains/yourdomain.com/public_html/app/Config/Database.php
           
  3. Locate the following section of the file and replace the details with the information of your newly-created database – username, password, and database.
  4.        
    public $default = [
        'DSN'      => '',
        'hostname' => 'localhost',
        'username' => 'u123456789_user',
        'password' => 'Y0ur$tr0ngPa$$w0rd',
        'database' => 'u123456789_name',
        'DBDriver' => 'MySQLi',
        'DBPrefix' => '',
        'pConnect' => false,
        'DBDebug'  => (ENVIRONMENT !== 'production'),
        'charset'  => 'utf8',
        'DBCollat' => 'utf8_general_ci',
        'swapPre'  => '',
        'encrypt'  => false,
        'compress' => false,
        'strictOn' => false,
        'failover' => [],
        'port'    => 3306,
    ];
           
           
  5. Set up your domain name by modifying CodeIgniter’s App.php file found here:
  6.        
    /domains/yourdomain.com/public_html/app/Config/App.php
           
  7. Locate the following line and change its value to your real domain name:
  8.        
    public $baseURL = 'https://yourdomain.com/';
       

   

Configuring Virtual Hosts on VPS

   
           
  1. Ensure that the document root is synced with the installation directory of CodeIgniter. To do so, open the virtual host file.
  2.        
    sudo nano /etc/apache2/sites-enabled/000-default
           
  3. Change /path/to/codeigniter with the actual path of the CodeIgniter installation directory.
  4.        
    <VirtualHost *:80>
        DocumentRoot /path/to/codeigniter
        [...]
    <VirtualHost *:80>
           
           
  5. For a more efficient development process, get rid of index.php from CodeIgniter’s URL format.
  6.        
    public $indexPage = 'index.php';
    Replace it with this:
    public $indexPage = '';
           
           
  7. Create a .htaccess file in the root folder of CodeIgniter.
  8.        
    sudo nano public_html/.htaccess
           
  9. Paste the following lines to the file:
  10.        
    RewriteEngine on
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule .* index.php?/$0 [PT,L]
           
           
  11. Let Apache know that it should look for the newly-created .htaccess file. To achieve this, open the virtual host file again:
  12.        
    sudo nano /etc/apache2/sites-enabled/000-default
           
  13. Ensure that AllowOverride is set to All.
  14.        
    <Directory>
        Options Indexes FollowSymLinks MultiViews
        AllowOverride All
        Order allow,deny
        allow from all
    <Directory>
           
       

   


Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)