Cara Instalasi CodeIgniter Menggunakan Nginx di CentOS 8
CodeIgniter merupakan sebuah framework yang dapat Anda gunakan secara bebas karena framework ini open source. CodeIgniter dapat Anda gunakan untuk membangun aplikasi web berbasis PHP.
CodeIgniter sudah banyak digunakan oleh para pengembang dan web developer untuk membangun website yang powerfull tertentunya.
Sebelum melakukan instalasi codeiginet pastikan Anda telah install terlebih dahulu web server yang akan digunakan yaitu Nginx dan database nya MariaDB/MySQL dan PHP versi 7.x, jika Anda belum melakukan installasi kebutuhan tersebut silakan merujuk pada tutorial berikut
- Cara Instalasi Nginx Di CentOS 8
- Cara Instalasi PHP 7 di CentOS 8
- Cara Instalasi Database MariaDB di CentOS 8
Memastikan semua service berjalan (running)
1
2
3
4
5
6
7
8
[root@tutorial ~]#
[root@tutorial ~]# systemctl status nginx |grep Active
Active: active (running) since Tue 2020-08-25 15:01:08 UTC; 1h 2min ago
[root@tutorial ~]# systemctl status php-fpm |grep Active
Active: active (running) since Tue 2020-08-25 07:38:48 UTC; 8h ago
[root@tutorial ~]# systemctl status mariadb |grep Active
Active: active (running) since Tue 2020-08-25 07:37:13 UTC; 8h ago
[root@tutorial ~]#
Disini kami menggunakan PHP versi 7.4 dan silakan install beberapa module php berikut
1
2
3
4
5
6
7
8
[root@tutorial ~]# php --version
PHP 7.4.9 (cli) (built: Aug 4 2020 08:28:13) ( NTS )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies
with Zend OPcache v7.4.9, Copyright (c), by Zend Technologies
[root@tutorial ~]#
[root@tutorial ~]#
[root@tutorial ~]# dnf install php-curl php-common php-cli php-mysql php-mbstring php-xml php-zip -y
Selanjutnya melakukan instalasi composer
1
2
3
4
5
6
7
8
9
[root@tutorial ~]#
[root@tutorial ~]# curl -sS https://getcomposer.org/installer | php
All settings correct for using Composer
Downloading...
Composer (version 1.10.10) successfully installed to: /root/composer.phar
Use it: php composer.phar
[root@tutorial ~]#
Memindahkan file compos_er.phar_ ke /usr/bin/ dan memberikan permission execute.
1
2
3
4
5
6
[root@tutorial ~]# ls
anaconda-ks.cfg composer.phar original-ks.cfg
[root@tutorial ~]#
[root@tutorial ~]# mv composer.phar /usr/bin/composer
[root@tutorial ~]# chmod +x /usr/bin/composer
[root@tutorial ~]#
Membuat database codeigniter
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
[root@tutorial ~]# mysql -u root -p
Enter password:
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 11
Server version: 10.3.17-MariaDB MariaDB Server
Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MariaDB [(none)]> create database ci_db;
Query OK, 1 row affected (0.001 sec)
MariaDB [(none)]> grant all privileges on cidb.* to ci_db@'localhost' identified by 'secret-ci';
Query OK, 0 rows affected (0.001 sec)
MariaDB [(none)]> flush privileges;
Query OK, 0 rows affected (0.001 sec)
MariaDB [(none)]> quit
Bye
[root@tutorial ~]#
Menentukan path root direktori codeigniter dan membuat direktori codeigniter
1
2
3
4
5
6
[root@tutorial ~]#
[root@tutorial ~]# cd /usr/share/nginx/
[root@tutorial nginx]#
[root@tutorial nginx]# mkdir ci
[root@tutorial nginx]# cd ci/
[root@tutorial ci]#
Cloning file codeigniter menggunakan git
1
2
3
4
5
6
7
8
9
[root@tutorial ci]# git clone https://github.com/bcit-ci/CodeIgniter.git .
Cloning into '.'...
remote: Enumerating objects: 320, done.
remote: Counting objects: 100% (320/320), done.
remote: Compressing objects: 100% (296/296), done.
remote: Total 85001 (delta 184), reused 71 (delta 24), pack-reused 84681
Receiving objects: 100% (85001/85001), 52.55 MiB | 10.18 MiB/s, done.
Resolving deltas: 100% (68480/68480), done.
[root@tutorial ci]#
_Noted: Jika belum ada git silakan install terlebih dahulu jalankan perintah berikut dnf install git -y _
Jalankan composer install untuk melakukan proses instalasi codeigniter
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
[root@tutorial ci]#
[root@tutorial ci]# composer install
Do not run Composer as root/super user! See https://getcomposer.org/root for details
Loading composer repositories with package information
Updating dependencies (including require-dev)
Package operations: 27 installs, 0 updates, 0 removals
- Installing mikey179/vfsstream (v1.1.0): Downloading (100%)
- Installing myclabs/deep-copy (1.10.1): Loading from cache
- Installing sebastian/version (2.0.1): Loading from cache
- Installing sebastian/resource-operations (1.0.0): Downloading (100%)
- Installing sebastian/recursion-context (2.0.0): Downloading (100%)
...
...
...
Writing lock file
Generating autoload files
4 packages you are using are looking for funding.
Use the `composer fund` command to find out more!
[root@tutorial ci]#
Berikan hak akses dan owner pada direktori ci yang kita buat sebelumnya
1
2
[root@tutorial ci]# chown -R nginx:nginx /usr/share/nginx/ci/
[root@tutorial ci]# chmod -R 755 /usr/share/nginx/ci/
Konfiguraasi URL codeigniter Anda
1
[root@tutorial ci]# vim application/config/config.php
Isi URL Anda bisa menggunakan IP atau nama domain contohnya : http://ci.nurhamim.my.id
Konfigurasi database codeigniter
1
[root@tutorial ci]# vim application/config/database.php
Silakan input username, password dan nama database yang telah kita buat sebelumnya
Langkah selanjutnya membuat server block Nginx yang akan digunakan codeigniter
1
[root@tutorial ci]# vim /etc/nginx/conf.d/ci.conf
Berikut isi server block Nginx nya
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
server {
listen 80;
server_name ci.nurhamim.my.id;
root /usr/share/nginx/ci;
index index.php index.html index.htm;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
location ~ \.php {
include fastcgi.conf;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/run/php-fpm/www.sock;
}
location ~ /\.ht {
deny all;
}
}
Noted: Disini kami menggunakan unix socket jika ingin menggunakan port socket silakan disesuaikan di sisi php-fpm nya.
Pastikan tidak ada konfigurasi yang salah terhadap server block nginx
1
2
3
4
[root@tutorial ci]# nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
[root@tutorial ci]#
Reload Nginx dan php-fpm
1
2
3
[root@tutorial ci]# systemctl reload nginx
[root@tutorial ci]# systemctl reload php-fpm
[root@tutorial ci]#
Pastikan Anda sudah menambahkan A record pada subdomain atau domain Anda
Verifikasi dapat dilakukan menggunakan ping
Akses subdomain atau domain Anda melalui browser
Selamat Anda telah berhasil melakukan instalasi codeigniter di CentOS 8.
Selamat mencoba 😁