Cara Install Apache Mariadb PHP (LAMP) Di VPS Hosting Centos 8
Centos 8 telah dirilis dan anda dapat menggunakannya untuk nge-blog dan lain sebagainya. Kali ini saya akan menulis tutorial tentang cara install apache, mariadb dan php di vps hosting Centos 8. Kombinasi dari ketiga ini biasa disebut dengan LAMP. Anda bisa menggunakannya untuk meng-host-kan aplikasi php anda di Centos 8, jika telah melakukan konfigurasi LAMP dengan benar.
Install Apache
Untuk meng-install apache, lakukan perintah berikut melalui command line.
yum install httpd
Start apache
systemctl start httpd
Restart apache
systemctl restart httpd
Melihat status apache
systemctl status httpd
Untuk melihat apakah httpd sudah berjalan dengan benar, anda buka ip dari vps anda atau domain anda lewat browser. Jika ternyata tidak bisa, lakukan langkah berikut:
a. Buat file index.html dengan isi misalnya "Hello Centos 8". Letakkan file tersebut di dalam folder /var/www/html.
nano /var/www/html/index.html
b. Sekarang, buka sekali lagi ip dari vps anda atau domain anda lewat browser. Maka akan muncul halaman index.html tersebut.
Install Mariadb Server
Untuk meng-install mariadb server, lakukan perintah berikut melalui command line.
yum install mariadb-server
Start mariadb server
systemctl start mariadb
Restart mariadb server
systemctl restart mariadb
Melihat status mariadb server
systemctl status mariadb
Lakukan langkah berikut agar mariadb-server menjadi "secure".
mysql_secure_installation
Jika anda melakukan langkah tersebut, akan terlihat beberapa langkah berikut ini di command line anda. Saat pertama kali install mariadb server username default-nya yaitu root tidak memiliki password. Jadi anda harus membuat password-nya pada langkah ini.
NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB
SERVERS IN PRODUCTION USE! PLEASE READ EACH STEP CAREFULLY!
In order to log into MariaDB to secure it, we'll need the current
password for the root user. If you've just installed MariaDB, and
you haven't set the root password yet, the password will be blank,
so you should just press enter here.
Enter current password for root (enter for none):
OK, successfully used password, moving on...
Setting the root password ensures that nobody can log into the MariaDB
root user without the proper authorisation.
Set root password? [Y/n] y
New password:
Re-enter new password:
Password updated successfully!
Reloading privilege tables..
... Success!
By default, a MariaDB installation has an anonymous user, allowing anyone
to log into MariaDB without having to have a user account created for
them. This is intended only for testing, and to make the installation
go a bit smoother. You should remove them before moving into a
production environment.
Remove anonymous users? [Y/n] y
... Success!
Normally, root should only be allowed to connect from 'localhost'. This
ensures that someone cannot guess at the root password from the network.
Disallow root login remotely? [Y/n] y
... Success!
By default, MariaDB comes with a database named 'test' that anyone can
access. This is also intended only for testing, and should be removed
before moving into a production environment.
Remove test database and access to it? [Y/n] y
- Dropping test database...
... Success!
- Removing privileges on test database...
... Success!
Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.
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!
Untuk login ke mariadb-server, ketik perintah berikut dan tekan tombol enter.
mysql -uroot -p
Kemudian masukkan password anda.
Install PHP
PHP bawaan centos 8 adalah php 7.2. Untuk meng-install php, ketik perintah berikut melalui command line.
yum install php php-mysqlnd
Untuk mengecek apakah php sudah bisa berjalan normal, lakukan langkah berikut ini.
a. Buat file php, misalnya info.php. Letakkan file tersebut di folder /var/www/html
nano /var/www/html/info.php
b. Isikan script sederhana berikut ke dalam file info.php
<?php
// Show all information, defaults to INFO_ALL
phpinfo();
// Show just the module information.
// phpinfo(8) yields identical results.
phpinfo(INFO_MODULES);
?>
c. Sekarang buka file php tersebut lewat browser: http://ip_address/info.php.
Database Connection
Agar sistem ini yaitu LAMP dapat digunakan, sistem php harus dapat di-koneksi-kan ke mariadb server. Silakan lakukan beberapa langkah berikut ini.
a. Login ke mariadb server.
mysql -uroot -p
b. Buat database baru.
create database testing;
c. Buat database user
CREATE USER 'usertesting'@'localhost' IDENTIFIED BY 'Cwo48*&#';
d. Grant all privileges, agar user dapat mengakses ke database yang barusan dibuat.
GRANT ALL PRIVILEGES ON testing.* TO 'usertesting'@'localhost';
e. Buat file konek.php yang berisi script php berikut.
<?php
$servername = "localhost";
$username = "usertesting";
$password = "Cwo48*&#";
// Create connection
$conn = new mysqli($servername, $username, $password);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
echo "Connected successfully";
?>
f. Selanjutnya kunjungi halaman berikut lewat browser: http://ip_address/konek.php. Jika terlihat status "Connected successfully", itu artinya php sudah berhasil konek ke mariadb server.
Jika php dapat konek dengan database server, anda bisa meng-install aplikasi php di sistem LAMP Centos 8. Anda bisa install wordpress, joomla dan lain sebagainya.
Kesimpulan
Tutorial ini membutuhkan akses root atau sudo di VPS CentOS 8 Anda, serta koneksi internet yang stabil untuk mengunduh dan menginstal paket-paket yang dibutuhkan. Pastikan untuk melakukan backup data penting sebelum memulai.
Demikian tutorial cara install nginx mariadb php lamp di vps hosting centos 8. Semoga artikel ini membantu anda yang sekarang sedang belajar membuat website menggunakan vps hosting server centos.
Tags :