07-20-2023, 01:09 PM
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
- Log in to your SSH account and navigate to the public_html root directory with this command:
- Install CodeIgniter 4.
- For convenience, move the contents of project-root to the public_html directory.
- Once that’s done, enter this URL into the browser:
cd domains/yourdomain.com/public_html
composer create-project codeigniter4/appstarter project-root
mv project-root/* /home/u123456789/domains/yourdomain.com/public_html
https://yourdomain.com/public
Install CodeIgniter 4 Manually
- Download the latest version of CodeIgniter.
- Using File Manager, extract it in the root directory – yourdomain.com/public_html.
- The framework-4.1.9 folder will appear. Open it and double-click the folder within.
- Press CTRL + A to select all the files and use the Move button to transfer everything to public_html.
- Open the browser and enter this URL:
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
- Navigate to File Manager and open the Database.php file for editing. Here’s the full path:
- Locate the following section of the file and replace the details with the information of your newly-created database – username, password, and database.
- Set up your domain name by modifying CodeIgniter’s App.php file found here:
- Locate the following line and change its value to your real domain name:
/domains/yourdomain.com/public_html/app/Config/Database.php
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,
];
/domains/yourdomain.com/public_html/app/Config/App.php
public $baseURL = 'https://yourdomain.com/';
Configuring Virtual Hosts on VPS
- Ensure that the document root is synced with the installation directory of CodeIgniter. To do so, open the virtual host file.
- Change /path/to/codeigniter with the actual path of the CodeIgniter installation directory.
- For a more efficient development process, get rid of index.php from CodeIgniter’s URL format.
- Create a .htaccess file in the root folder of CodeIgniter.
- Paste the following lines to the file:
- Let Apache know that it should look for the newly-created .htaccess file. To achieve this, open the virtual host file again:
- Ensure that AllowOverride is set to All.
sudo nano /etc/apache2/sites-enabled/000-default
<VirtualHost *:80>
DocumentRoot /path/to/codeigniter
[...]
<VirtualHost *:80>
public $indexPage = 'index.php';
Replace it with this:
public $indexPage = '';
sudo nano public_html/.htaccess
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php?/$0 [PT,L]
sudo nano /etc/apache2/sites-enabled/000-default
<Directory>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
<Directory>

