Categories: Linux

Install Varnish Apache PHP Mariadb (LAMP) Centos 7

Dari postingan sebelumnya, ada tutorial untuk menginstall varnish dan apache. Tutorial kali ini membahas cara instalasi Varnish, Apache, Mariadb 10.1, PHP, dan PhpMyAdmin.

Install Mariadb

Buat file baru di /etc/yum.repos.d/MariaDB.repo

nano /etc/yum.repos.d/MariaDB.repo

Masukkan repository mariadb

[mariadb]
name = MariaDB
baseurl = http://yum.mariadb.org/10.1/centos7-amd64
gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB
gpgcheck=1

Install mariadb server dan mariadb client

yum install MariaDB-server MariaDB-client

Start dan enable mariadb

systemctl start mariadb
systemctl enable mariadb

Jalankan mysql_secure_installation

mysql_secure_installation
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] 
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] 
 ... 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] 
 ... 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] 
 - 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] 
 ... 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 apache

yum install httpd -y

Start dan enable apache

systemctl start httpd
systemctl enable httpd

Install php dan phpmyadmin

yum install epel-release
yum install php phpmyadmin

Buka httpd.conf

nano /etc/httpd/conf/httpd.conf

Ganti Listen 80 menjadi Listen 8080, dan restart apache

systemctl restart httpd

Sekarang kita coba mengakses default page nya apache, buka http://ip-address:8080 . Jika benar, akan muncul tampilan berikut

Untuk mencoba php, buat file baru

nano /var/www/html/info.php

Masukkan script berikut

<?php
    phpinfo();
?>

Akses kembali alamat  http://ip-address:8080/info.php  melalui browser. Jika benar, akan tampil berikut:

Untuk dapat mengakses phpmyadmin, maka akses ke internet harus dibuka dulu. Buka file konfigurasi phpmyadmin

nano /etc/httpd/conf.d/phpMyAdmin.conf

Ganti dari seperti ini

  <IfModule mod_authz_core.c>
     # Apache 2.4
     <RequireAny>
       Require ip 127.0.0.1
       Require ip ::1
     </RequireAny>
   </IfModule>

menjadi seperti ini

  <IfModule mod_authz_core.c>
     # Apache 2.4
     <RequireAny>
       #Require ip 127.0.0.1
       #Require ip ::1
        Require all granted
     </RequireAny>
   </IfModule>

dan dari seperti ini

  <IfModule mod_authz_core.c>
     # Apache 2.4
     <RequireAny>
       Require ip 127.0.0.1
       Require ip ::1
     </RequireAny>
   </IfModule>

menjadi seperti ini

   <IfModule mod_authz_core.c>
     # Apache 2.4
     <RequireAny>
       #Require ip 127.0.0.1
       #Require ip ::1
        Require all granted
     </RequireAny>
   </IfModule>

Restart apache

systemctl restart httpd

Akses http://ip-address:8080/phpmyadmin , jika benar, akan muncul halaman login phpmyadmin

Sampai langkah ini, LAMP sudah terinstal dengan benar. Langkah selanjutnya adalah menginstall varnish cache seperti pada langkah di sini.

Install varnish

yum install varnish -y

Buka /etc/varnish/default.vcl , pastikan backend default bernilai seperti berikut

backend default {
    .host = "127.0.0.1";
    .port = "8080";
}

Buka /etc/varnish/varnish.params , pastikan VARNISH_LISTEN_PORT bernilai 80

VARNISH_LISTEN_PORT=80

Start dan enable varnish

systemctl start varnish
systemctl enable varnish

Cobalah mengakses 3 alamat berikut pada browser

http://ip-address
http://ip-address/info.php
http://ip-address/phpmyadmin

Jika benar, maka pada browser akan muncul tampilan seperti ketika varnish belum kita install.

Ketika kita melakukan pengecekan menggunakan curl, hasilnya seperti berikut

curl -I http://ip-address
HTTP/1.1 403 Forbidden
Date: Wed, 07 Dec 2016 23:39:21 GMT
Server: Apache/2.4.6 (CentOS) PHP/5.4.16
Last-Modified: Thu, 16 Oct 2014 13:20:58 GMT
ETag: "1321-5058a1e728280"
Accept-Ranges: bytes
Content-Length: 4897
Content-Type: text/html; charset=UTF-8
X-Varnish: 163863
Age: 0
Via: 1.1 varnish-v4
Connection: keep-alive

Terlihat pada bagian Via, tertulis varnish-v4. Itu tandanya varnish telah terinstal dengan benar.

Jika sudah berhasil, maka port 8080 kita tutup aksesnya dari luar.

Buka kembali file httpd.conf

nano /etc/httpd/conf/httpd.conf

Ganti Listen 8080 menjadi Listen localhost:8080

Listen localhost:8080

Restart apache

systemctl restart apache

Jika benar, maka ketika kita mengakses http://ip-address:8080 , maka tidak akan muncul apapun di browser.

Akhmad Fakhoni Listiyan Dede

View Comments

Share
Published by
Akhmad Fakhoni Listiyan Dede

Recent Posts

Mengimplementasikan AI untuk Melakukan Review pada Pull Request Github

Halo semua Github memiliki fitur terkait Pull Request yang cukup luar biasa, yaitu dapat melakukan…

7 months ago

Install kubernetes cluster using kubeadm

Hello everyone! 👋 Welcome to our step-by-step guide on using kubeadm to install Kubernetes. It's…

1 year ago

Meningkatkan Efisiensi Memory Proxmox Lebih dari 20%

Proxmox adalah hypervisor yang populer digunakan karena penggunaannya yang cukup simpel jika dibandingkan dengan hypervisor…

4 years ago

Longhorn Failed Upgrade from v0.8.1 to v1.0.0 caused by pv created before v0.6.2

This post is mirror of https://forums.rancher.com/t/failed-upgrade-from-v0-8-1-to-v1-0-0-caused-by-pv-created-before-v0-6-2/17586 I scale down all pods that has vpc to…

5 years ago

Cara Setup Network Ubuntu Server 18.04 pada Proxmox

Ubuntu Konfigurasi network pada Ubuntu Server 18.04 berbeda dengan ubuntu versi sebelumnya. Versi sebelumnya menggunakan…

5 years ago

VSCode Terminal Font Fix on MacOS

For detailed problems, see https://notulensiku.com/2019/02/fix-integrated-terminal-font-vscode/ To solve on mac, you need to install powerline fonts…

5 years ago