| |

Cara Install Apache, Mysql / MariaDB dan PHP ( LAMP ) di AlmaLinux 8.

LAMP adalah kepanjangan dari Linux, Apache, Mysql / MariaDB dan PHP. Fungsi utama adalah untuk host web server berbasis PHP dan mysql. Memiliki fungsi yang sama dengan XAMPP yang ada di Windows. Linux menjadi media host web server dikarenakan sistem yang stabil.

Artikel kali ini akan melakukan installasi Aache , Mysql / MariaDB dan PHP ( LAMP ) di AlmaLinux 8.7 ( Stone Smilodon )

Persiapan Instalasi

Penambahan respository EPEL dan Remi

# sudo dnf install -y https://dl.fedoraproject.org/pub/epel/epel-release-latest-8.noarch.rpm
# sudo dnf install -y https://rpms.remirepo.net/enterprise/remi-release-8.rpm

Berikut ini tampilan repolist yang ditambahkan

Dilanjutkan update dengan perintah dibawah ini.

# dnf update && dnf upgrade -y
# dnf repolist

Install Apache di AlmaLinux

Pertama install Apache web Server, instalasi menggunakan package manager

# dnf install @httpd

Setelah proses instalasi Complete !, untuk pertama kalinya apache dapat di start dengan systemd

# systemctl start httpd

untuk mengetahui status service apache

# systemctl status httpd

● httpd.service - The Apache HTTP Server
   Loaded: loaded (/usr/lib/systemd/system/httpd.service; disabled; vendor preset: disabled)
   Active: active (running) since Mon 2023-04-10 05:53:10 EDT; 33s ago
     Docs: man:httpd.service(8)
 Main PID: 65031 (httpd)
   Status: "Running, listening on: port 443, port 80"
    Tasks: 213 (limit: 11354)
   Memory: 35.0M
   CGroup: /system.slice/httpd.service
           ├─65031 /usr/sbin/httpd -DFOREGROUND
           ├─65032 /usr/sbin/httpd -DFOREGROUND
           ├─65033 /usr/sbin/httpd -DFOREGROUND
           ├─65034 /usr/sbin/httpd -DFOREGROUND
           └─65035 /usr/sbin/httpd -DFOREGROUND

Apr 10 05:53:08 alma8.sobit.link systemd[1]: Starting The Apache HTTP Server...
Apr 10 05:53:10 alma8.sobit.link systemd[1]: Started The Apache HTTP Server.
Apr 10 05:53:10 alma8.sobit.link httpd[65031]: Server configured, listening on: port 443, port >

Setelah apache running, agar secara otomatis start ketika reboot/boot service perlu di enable systemd

]# systemctl enable httpd
Created symlink /etc/systemd/system/multi-user.target.wants/httpd.service → /usr/lib/systemd/system/httpd.service.

Allow service httpd ke firewall

[root@alma8 ~]# firewall-cmd --permanent --zone=public --add-service=http
success
[root@alma8 ~]# firewall-cmd --reload
success

Jika sudah, akses ip host dari browser. Tampilan Test Page Apache akan seperti tampilan gambar dibawah ini.

Instalasi sudah selesai dan direktori kerja untuk apache adalah “/var/www/html”

Install Mariadb di AlmaLinux

MariaDB adalah versi Community dari Mysql dan sifatnya open source, Pertama cek list MariaDB yang tersedia di repository.

# dnf module list mariadb

Untuk memilih Versi yang ingin di install yaitu versi 10.5 gunakan perintah

# dnf module install mariadb:10.5

Setelah proses selesai, start MariaDB, enable MariaDB di systemd, dan cek status MariaDB apakah berjalan denga normal.

# systemctl start mariadb
# systemctl enable mariadb
# systemctl status mariadb

Lalu Kita setup MariaDB terlebih dahulu maria agar lebih aman.

# mariadb-secure-installation
//atau
# mysql_secure_installation

Di Tahap setup pertama setup root password MariaDB

Dilanjutkan dengan penghapusan anonym user, test database dll mudahnya untuk siap digunakan pilih jawaban “Y”

Jika sudah, untuk login atau masuk ke MariaDB guna membuat atau manajemen database.

# mariadb -u root -p
//atau
# mysql -u root -p

Lalu buatkan Database, User dan Table untuk Test nantinya.

[root@alma8 html]# mariadb -u root -p
Enter password:
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 18
Server version: 10.5.16-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 cobadb;
Query OK, 1 row affected (0.030 sec)

MariaDB [(none)]> grant all privileges on cobadb.* to 'cobause'@'localhost' identified by 'c0b4123';
Query OK, 0 rows affected (0.079 sec)

MariaDB [(none)]> use cobadb;
Database changed

MariaDB [cobadb]> create table TabelPertama (
    -> ID int,
    -> Nama varchar(255));
Query OK, 0 rows affected (0.156 sec)

MariaDB [(none)]> flush privileges;
Query OK, 0 rows affected (0.033 sec)

MariaDB [(none)]> quit

Sampai Disini instalasi Mysql sudah selesai.

Instalasi PHP 8.2 di AlmlaLinux

Cek ketersediaan Linux pada repository

# dnf module list php
[root@alma8 ~]# dnf module list php
Last metadata expiration check: 1:59:28 ago on Tue 11 Apr 2023 12:41:27 AM EDT.
AlmaLinux 8 - AppStream
Name       Stream        Profiles                        Summary
php        7.2 [d]       common [d], devel, minimal      PHP scripting language
php        7.3           common [d], devel, minimal      PHP scripting language
php        7.4           common [d], devel, minimal      PHP scripting language
php        8.0           common [d], 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
php        remi-8.0      common [d], devel, minimal      PHP scripting language
php        remi-8.1      common [d], devel, minimal      PHP scripting language
php        remi-8.2      common [d], devel, minimal      PHP scripting language

Hint: [d]efault, [e]nabled, [x]disabled, [i]nstalled
[root@alma8 ~]#

Untuk mendapatkan package php 8.2 saja dari remi repository gunakan perintah.

#  dnf module enable php:remi-8.2 
[root@alma8 ~]# dnf module enable php:remi-8.2
Last metadata expiration check: 2:01:06 ago on Tue 11 Apr 2023 12:41:27 AM EDT.
Dependencies resolved.
====================================================================================
 Package            Architecture      Version              Repository          Size
====================================================================================
Enabling module streams:
 php                                  remi-8.2

Transaction Summary
====================================================================================

Is this ok [y/N]: y

Complete!

Dengan begini ketika di cek list module php 8.2 sudah bertanda “e” seperti dibawah ini

Jika sudah lanjutkan dengan instalasi

# dnf install php php-common php-bcmath php-json php-imagick php-cli php-mbstring php-xml php-zip php-mysqlnd php-opcache php-curl php-intl php-gd

Seperti yang dilihat diatas instalasi hanya mendownload semua package yang berkaitan dengan php 8.2

Cek kembali untuk memastikan persi PHP yang terinstall

[root@alma8 ~]# php -v
PHP 8.2.4 (cli) (built: Mar 14 2023 16:11:05) (NTS gcc x86_64)
Copyright (c) The PHP Group
Zend Engine v4.2.4, Copyright (c) Zend Technologies
    with Zend OPcache v8.2.4, Copyright (c), by Zend Technologies

Restart service apache / httpd agar dapat membaca php

# systemctl restart httpd

Untuk Test, buatkan file php untuk mengecek php dan module pendukung.

# vi /var/www/html/coba.php

isi file coba.php dan save

<?php
phpinfo();
?>

Akses http://IP-HOST/coba.php atau domain dari host menggunakan browser. Pada contoh dibawah ini.

http://192.168.0.61/coba.php

Sampai disini instalasi php sudah selesai.

Test koneksi PHP ke MariaDB

Buatkan file php dengan nama testdb.php

# vi /var/www/html/testdb.php

Isikan semua baris code php dibawah ini untuk test koneksi. dan SAVE

<?php

$dbname = 'cobadb';
$dbuser = 'cobause';
$dbpass = 'c0b4123';
$dbhost = 'localhost';

$connect = mysqli_connect($dbhost, $dbuser, $dbpass) or die("Unable to Connect to '$dbhost'");
mysqli_select_db($connect, $dbname) or die("Could not open the db '$dbname'");

$test_query = "SHOW TABLES FROM $dbname";
$result = mysqli_query($connect, $test_query);

$tblCnt = 0;
while($tbl = mysqli_fetch_array($result)) {
  $tblCnt++;
  #echo $tbl[0]."<br />\n";
}

if (!$tblCnt) {
  echo "Tidak ada Tabel <br />\n";
} else {
  echo "Terdapat $tblCnt tables<br />\n";
}
$connect -> close();
?>

Untuk Test pertama bisa menggunakan command / perintah.

# ]# php -f /var/www/html/testdb.php
Terdapat 1 tables<br />

Atau dengan akses melalui browser

# http://192.168.0.61/testdb.php

Sampai disini LAMP (Apache, MariaDB / Mysql, dan PHP ) sudah terinstall dan siap digunakan.

Similar Posts

4.8 4 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments