Pendahuluan
- Linux sebagai sistem operasi
- Apache HTTP Server sebagai web server
- MySQL sebagai sistem basis data
- Perl atau PHP atau Pyton sebagai bahasa pemrograman yang dipakai
Pada tulisan ini kita akan mempelajari bagaimana me-konfigurasi sebuah Linux, Apache, MySQL, and PHP (LAMP).
Persiapan
- Download images ISO CentOS versi 7 dari mirror yang terdekat dengan lokasi kita (daftar mirror server dapat dilihat di: http://isoredirect.centos.org/centos/7/isos/x86_64/ ). ISO yang di download boleh versi DVD atau minimal. Dalam tulisan ini, saya menggunakan yang minimal.
- koneksi internet yang stabil (syukur-syukur stabil & cepat :p )
Pada tutorial ini kita akan mengatur nama hostname menjadi server1.karedok.net dengan alamat IP 192.168.2.10 dan gateway 192.168.2.1. Pengaturan ini mungkin akan berbeda dengan kebutuhan kamu. Jadi, silakan disesuaikan.
Update server
untuk melakukan update server kita jalankan perintah:
yum update -y
Sesuaikan file /etc/hosts
nano /etc/hosts 127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4 192.168.1.10 server1.karedok.net server1 ::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
Tambahkan repositori EPEL
yum -y install epel-release
Install Apache
Untuk CentOS 7 tersedia paket apache 2.4. Apache2 merupakan paket bawaan CentOS 7, untuk mendapatkannya kita jalankan perintah:
yum -y install httpd
jalankan service apache:
systemctl start httpd
Atur agar apache dijalankan saat server hidup:
systemctl enable httpd
buka akses firewall untuk protokol http & https:
firewall-cmd --permanent --zone=public --add-service=http firewall-cmd --permanent --zone=public --add-service=https firewall-cmd --reload
Sekarang kita coba buka melalui browser internet IP server kita http://192.168.0.10, sekarang seharusnya kita akan mendapatkan tampilan seperti berikut:
Install PHP
Kita install paket agar apache dapat mendukung PHP5:
yum -y install php
Jalankan ulang service Apache nya:
systemctl restart httpd.service
Memastikan instalasi PHP5
Folder tempat menaruh file website bawaan adalah /var/www/html. Kita akan membuat sebuah file PHP pada direktori tersebut. File ini akan menampilkan informasi detail tentang instalasi PHP pada server kita, misalnya PHP versi berapa yg terinstall, dukungan terhadap PHP apa saja, dsb.
Untuk membuat file, jalankan perintah:
vi /var/www/html/info.php
Untuk mulai meng-edit file, tekan tombol i terlebih dahulu baru kemudian ketik skrip berikut:
<?php phpinfo(); ?>
Sekarang jalankan melalui browser http://192.168.0.10/info.php. Jika sudah benar, maka akan tampil sebagai berikut:
Seperti yang kita lihat, PHP5 sudah terpasang dan terintegrasi dengan Apache 2.0. Jika di scroll kebawah, kita akan dapat melihat module PHP5 apa saja yang sudah terpasang & aktif pada server kita. MySQL belum ada dalam daftar karena kita belum menginstall paket MySQL dan modul PHP-MySQL.
Install MySQL dan modul PHP5 agak mendukung MySQL
Agar PHP5 bisa mendukung MySQL, kita perlu melakukan instalasi MySQL dan paket php-mysql. Pada tahap ini, kita juga akan melakukan instalasi modul PHP5 lainnya yang umumnya dipakai. Untuk melihal terdapat modul PHP5 apa saja dalam repo, kita bisa melakukan perintah:
yum search php
Install paket MySQL dan modul PHP5 standar yang diperlukan oleh CMS umumnya.seperti WordPress, Joomla and Drupal:
yum -y install mariadb-server mariadb php-mysql php-gd php-ldap php-odbc php-pear php-xml php-xmlrpc php-mbstring php-snmp php-soap curl curl-devel
restart Apache2:
systemctl restart httpd
Sekarang refresh http://192.168.0.10/info.php pada browser dan scroll ke bagian modul untuk memastikan modul sudah terpasang. Sekarang sekarusnya sudah ada modul lainnya seperti misalnya curl, dll.
Konfigurasi MySQL
Jalankan service MySQL dan set agar service berjalan saat server hidup:
systemctl start mariadb.service systemctl enable mariadb.service
Set password untuk akun root MySQL root:
mysql_secure_installation [root@server1 ~]# mysql_secure_installation /usr/bin/mysql_secure_installation: line 379: find_mysql_client: command not found 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): <--ENTER 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: <--MasukkanPassword Re-enter new password: <--MasukkanPassword 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] <--ENTER ... 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] <--ENTER ... 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] <--ENTER - 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] <--ENTER ... 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 phpMyAdmin
phpMyAdmin adalah sebuah aplikasi web yang digunakan untuk manajemen database MySQL kita. Untuk menginstall phpMyAdmin melalui perintah berikut:
yum install phpMyAdmin
Konfigurasi phpMyAdmin.
Ada beberapa bagian konfigurasi apache phpMyAdmin yang harus kita ubah agat dapat diakses tidak hanya dari localhost:
vi /etc/httpd/conf.d/phpMyAdmin.conf
[...] Alias /phpMyAdmin /usr/share/phpMyAdmin Alias /phpmyadmin /usr/share/phpMyAdmin #<Directory /usr/share/phpMyAdmin/> # <IfModule mod_authz_core.c> # # Apache 2.4 # <RequireAny> # Require ip 127.0.0.1 # Require ip ::1 # </RequireAny> # </IfModule> # <IfModule !mod_authz_core.c> # # Apache 2.2 # Order Deny,Allow # Deny from All # Allow from 127.0.0.1 # Allow from ::1 # </IfModule> #</Directory> <Directory /usr/share/phpMyAdmin/> Options none AllowOverride Limit Require all granted </Directory> [...]
Lalu ubah metode otentikasi phpMyAdmin dari cookie menjadi http:
vi /etc/phpMyAdmin/config.inc.php [...] $cfg['Servers'][$i]['auth_type'] = 'http'; // Authentication method (config, http or cookie based)? [...]
Restart Apache:
systemctl restart httpd.service
Sekarang phpMyAdmin bisa kita akses melalui http://192.168.0.10/phpmyadmin/
.: Selamat mencoba :.