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

name = MariaDB
baseurl =

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


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


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
       Require ip
       Require ip ::1

menjadi seperti ini

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

dan dari seperti ini

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

menjadi seperti ini

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

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 = "";
    .port = "8080";

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


Start dan enable varnish

systemctl start varnish
systemctl enable varnish

Cobalah mengakses 3 alamat berikut pada browser


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.

1 Comment

  1. Menampilkan Client IP Apache Menggunakan Varnish - Notulensiku

    […] kita menggunakan varnish seperti pada tutorial ini dan ini, maka client ip pada access_log Apache menjadi berasal dari Hal ini dikarenakan Apache […]

Leave A Comment