Control panel tak selalu perlu digunakan untuk mengelola website pribadi di VPS atau cloud server, hal ini dapat dilakukan jika kamu sudah memiliki pengalaman pada Linux atau menjadi system administrator, karena nantinya akan penuh dengan CLI (Command Line Interface) tidak ada GUI seperti cPanel atau CWP pada umumnya. Pada artikel ini kami akan membahas mengenai cara instalasi LAMP Stack di CentOS 8.
LAMP Stack
LAMP (Linux, Apache, MariaDB/MySQL & PHP) adalah salah satu stack yang diciptakan untuk memenuhi kebutuhan website yang berjalan di dalam server, LAMP Stack ini tidak ada GUI (Graphical User Interface) sehingga untuk menjalankan atau memproses sesuatu harus dengan command atau perintah.
Jika pada sebelumnya kami sudah membahas mengenai Cara Install LAMP di CentOS 7, maka kali ini akan dilakukan pada CentOS 8.
Baca Juga: Cara Instal Node.js dan Deploy App di CentOS 8
Apa itu DNF
DNF atau Dandified YUM merupakan generasi terbaru dari package manager untuk distribusi berbasis .rpm yang dirilis pada 2018. Pada command atau perintah di CentOS 8 ini, kita akan lebih banyak menggunakan DNF.
Sebelum mulai mempraktikkan cara instalasi LEMP Stack, pastikan kamu sudah memenuhi beberapa persyaratan berikut:
- VPS dengan OS CentOS 8.
- Domain yang sudah diarahkan ke alamat IP VPS. (Dewaweb juga menyediakan hosting murah gratis domain)
- Akses root.
Cara Instalasi LAMP Stack di CentOS 8
Berikut Cara Instalasi LAMP Stack di CentOS 8:
Update Packages CentOS 8
Kamu perlu melakukan update package pada CentOS 8 terlebih dulu menggunakan perintah DNF, kemudian reboot server.
$ dnf update
$ reboot
Instal Apache
Mengingat ini adalah ini LAMP, maka web server yang digunakan adalah Apache.
$ dnf install httpd httpd-tools -y
Setelah instalasinya selesai, start dan enable Apache on boot.
$ systemctl enable httpd
$ systemctl start httpd
Kemudian cek status Apache, apakah sudah berjalan atau belum.
$ systemctl status httpd
- httpd.service – The Apache HTTP Server
Loaded: loaded (/usr/lib/systemd/system/httpd.service; enabled; vendor prese>
Active: active (running) since Thu 2020-05-21 06:45:11 UTC; 4s ago
Docs: man:httpd.service(8)
Main PID: 2053 (httpd)
Status: “Started, listening on: port 80”
Tasks: 213 (limit: 6052)
Memory: 24.9M
CGroup: /system.slice/httpd.service
├─2053 /usr/sbin/httpd -DFOREGROUND
├─2054 /usr/sbin/httpd -DFOREGROUND
├─2055 /usr/sbin/httpd -DFOREGROUND
├─2056 /usr/sbin/httpd -DFOREGROUND
└─2057 /usr/sbin/httpd -DFOREGROUND
Setelah instalasi web server, untuk mendapatkan versi terbaru dari Apache, kamu bisa menggunakan command di bawah ini:
$ rpm -qi httpd
Name : httpd
Version : 2.4.37
Release : 16.module_el8.1.0+256+ae790463
Architecture: x86_64
Install Date: Thu 21 May 2020 06:44:49 AM UTC
Group : System Environment/Daemons
Size : 5611291
License : ASL 2.0
Signature : RSA/SHA256, Mon 23 Dec 2019 10:22:02 PM UTC, Key ID 05b555b38483c65d
Source RPM : httpd-2.4.37-16.module_el8.1.0+256+ae790463.src.rpm
Build Date : Mon 23 Dec 2019 08:46:30 PM UTC
Build Host : x86-02.mbox.centos.org
Relocations : (not relocatable)
Packager : CentOS Buildsys <[email protected]>
Vendor : CentOS
URL : https://httpd.apache.org/
Summary : Apache HTTP Server
Description :
The Apache HTTP Server is a powerful, efficient, and extensible
web server.
Baca Juga: Cara Instalasi dan Setup PHP, WebServer CWP di VPS CentOS
Instal MariaDB
Cara instalasi LAMP Stack di CentOS 8 selanjutnya adalah menginstal MariaDB. Di sini kami menggunakan MariaDB sebagai Database di LAMP Stack ini, karena MySQL saat ini sudah deprecated alias tidak up-to-date.
$ dnf install mariadb-server mariadb -y
Setelah instalasinya selesai, start dan enable MariaDB on boot.
$ systemctl start mariadb
$ systemctl enable mariadb
Kemudian cek status MariaDB, apakah sudah berjalan atau belum.
$ systemctl status mariadb
- mariadb.service – MariaDB 10.3 database server
Loaded: loaded (/usr/lib/systemd/system/mariadb.service; enabled; vendor pre>
Active: active (running) since Thu 2020-05-21 06:48:53 UTC; 26s ago
Docs: man:mysqld(8)
https://mariadb.com/kb/en/library/systemd/
Main PID: 5018 (mysqld)
Status: “Taking your SQL requests now…”
Tasks: 30 (limit: 6052)
Memory: 82.6M
CGroup: /system.slice/mariadb.service
└─5018 /usr/libexec/mysqld –basedir=/usr
Kemudian, ketikan perintah atau command di bawah ini untuk mulai inisialisasi MariaDB.
$ mysql_secure_installation
Enter current password for root (enter for none):
OK, successfully used password, moving on…
Set root password? [Y/n] y
New password:
Re-enter new password:
Password updated successfully!
Reloading privilege tables..
… Success!
Remove anonymous users? [Y/n] y
… Success!
Disallow root login remotely? [Y/n] y
… Success!
Remove test database and access to it? [Y/n] y
– Dropping test database…
… Success!
– Removing privileges on test database…
… Success!
Reload privilege tables now? [Y/n] y
… Success!
Cleaning up…
All done! If you’ve completed all of the above steps, your MariaDB
installation should now be secure.
Thanks for using MariaDB!
Install PHP
Di artikel cara instalasi LAMP Stack di CentOS 8 ini kami menggunakan PHP versi 7, karena versi di bawah itu sudah deprecated atau tidak up-to-date.
$ sudo dnf install https://dl.fedoraproject.org/pub/epel/epel-release-latest-8.noarch.rpm
Install EPEL Repository
$ dnf install https://dl.fedoraproject.org/pub/epel/epel-release-latest-8.noarch.rpm
Baca Juga: Cara Melakukan Speedtest Server di CentOS 7
Install YUM-Utils
$ dnf install dnf-utils http://rpms.remirepo.net/enterprise/remi-release-8.rpm
Gunakan command di bawah ini untuk melihat PHP module yang tersedia untuk diinstal.
$ dnf module list php
Remi’s Modular repository for Enterprise Linux 218 kB/s | 567 kB 00:02
Safe Remi’s RPM repository for Enterprise Linux 400 kB/s | 1.5 MB 00:03
Last metadata expiration check: 0:00:01 ago on Thu 21 May 2020 06:52:37 AM UTC.
CentOS-8 – AppStream
Name Stream Profiles Summary
php 7.2 [d] common [d], devel, minimal PHP scripting language
php 7.3 common, devel, minimal PHP scripting language
Remi’s Modular repository for Enterprise Linux 8 – x86_64
Name Stream Profiles Summary
php remi-7.2 common [d], devel, minimal PHP scripting language
php remi-7.3 common [d], devel, minimal PHP scripting language
php remi-7.4 common [d], devel, minimal PHP scripting language
Hint: [d]efault, [e]nabled, [x]disabled, [i]nstalled
Dari output di atas, PHP versi 7.4 adalah versi terbaru yang akan digunakan sebagai bagian rangkaian cara instalasi LAMP Stack berikut, tapi kamu perlu melakukan reset PHP module terlebih dulu dengan memasukkan command di bawah ini.
$ dnf module reset php
Dependencies resolved.
Nothing to do.
Complete!
Kemudian enable module php versi 7.4 yang terbaru atau up-to-date.
$ dnf module enable php:remi-7.4
Dependencies resolved.
================================================================================
Package Architecture Version Repository Size
================================================================================
Enabling module streams:
php remi-7.4
Transaction Summary
================================================================================
Is this ok [y/N]: y
Complete!
Lalu, install kebutuhan PHP Extension yang lain seperti di bawah ini.
$ dnf install php php-opcache php-gd php-curl php-mysqlnd
Untuk mengecek versi php yang digunakan bisa menggunakan command di bawah ini.
$ php -v
PHP 7.4.6 (cli) (built: May 12 2020 08:09:15) ( NTS )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies
with Zend OPcache v7.4.6, Copyright (c), by Zend Technologies
Start dan enable php-fpm on boot
$ systemctl enable php-fpm
$ systemctl start php-fpm
Untuk melihat status php-fpm
$ systemctl status php-fpm
- php-fpm.service – The PHP FastCGI Process Manager
Loaded: loaded (/usr/lib/systemd/system/php-fpm.service; enabled; vendor pre>
Active: active (running) since Thu 2020-05-21 06:55:56 UTC; 4s ago
Main PID: 5969 (php-fpm)
Status: “Ready to handle connections”
Tasks: 6 (limit: 6052)
Memory: 23.6M
CGroup: /system.slice/php-fpm.service
├─5969 php-fpm: master process (/etc/php-fpm.conf)
├─5970 php-fpm: pool www
├─5971 php-fpm: pool www
├─5972 php-fpm: pool www
├─5973 php-fpm: pool www
└─5974 php-fpm: pool www
Pada SELinux, untuk mengizinkan Apache untuk mengeksekusi php via php-fpm, perlu seperti di bawah ini.
$ setsebool -P httpd_execmem 1
Kemudian, reboot atau restart web server Apache.
$ systemctl restart httpd
Baca Juga: Cara Instalasi Go atau Golang di CentOS 7
Tes Akses
Setelah melakukan cara instalasi LAMP Stack di CentOS 8, sekarang kamu dapat melakukan tes dengan mengakses domain atau alamat IP yang kamu gunakan untuk melihat hasilnya.
Lalu tambahkan script di bawah ini pada info.php agar dapat ditampilkan di website.
<?php
phpinfo ();
?>
Kemudian akses domain atau IP yang kamu gunakan.
Selesai!
Simpulan
Jika kamu mengikuti langkah untuk cara instalasi LAMP Stack di CentOS 8 dengan benar, seharusnya saat ini kamu sudah dapat menggunakan LAMP Stack untuk CentOS 8. Selanjutnya, kamu dapat memanfaatkan LAMP Stack untuk mengelola VPS atau cloud server dengan lebih mudah.
Jika ada pertanyaan terkait website yang cepat, aman, dan selalu dapat diandalkan, kamu dapat bertanya ke Ninja Support legendaris dari penyedia layanan hosting Dewaweb yang siap sedia selama 24 jam setiap hari untuk membantumu.
Demikian artikel ini, jangan sungkan untuk meninggalkan ide-ide topik yang ingin kamu baca di blog Dewaweb. Semoga artikel ini membantu!