Thursday, August 17, 2006

Instalasi Apache PHP MySQL

Instalasi Mysql http://www.mysql.com
========================
$tar -zxvf mysql-version.tar.gz
$./configure --prefix=/usr/local/mysql

Jika ingin melihat opsi lain, ketikkan ./configure --help
$make
#make install
#groupadd mysql
#useradd -g mysql mysql
#cp support-files/my-medium.cnf /etc/my.cnf <-- file konfigurasi mysql
#cd /usr/local/mysql
#bin/mysql_install_db --user=mysql <-- instalasi/pembuatan database default
#chown -R root .
#chown -R mysql var/
#chgrp -R mysql .
#bin/mysqld_safe --user=mysql & <--menjalankan mysql


Otomatis mysql akan aktif, untuk mengeceknya, coba masuk ke mysql :
#/usr/local/mysql/bin/mysql
Klo instalasi berhasil seharusnya akan masuk, maka akan ada tampilan :
mysql>
mysql>show databases;
mysql>use mysql;
mysql>show tables;
mysql>select user,password from user;
mysql>delete from user where user='';
mysql>update user set password=password('password_kamu') where user='root';

Dengan begini maka account user root di mysql akan berpassword, maka untuk masuk ke mysql :
#/usr/local/mysql/bin/mysql -u root -p

Instalasi Apache Web Server http://httpd.apache.org
=========================
Qta pake versi terbaru saat ini :
$tar -jxvf httpd-2.2.2.tar.bz2
$cd httpd-2.2.2
$./configure --prefix=/usr/local/apache --enable-ssl --enable-cgi --enable-vhost-alias --enable-rewrite --enable-so

--prefix menunjukkan letak/path lokasi instalasi
--enable-ssl mengaktifkan mod_ssl untuk apliakasi https
--enable-cgi membolehkan server untuk mengeksekusi script cgi
--enable-vhost-alias untuk membuat alias dalam virtual host
--enable-rewrite membolehkan server untuk "rewrite" suatu halaman page
--enable-so mengaktifkan modul-modul server
Opsi-opsi diatas adalah opsional, tergantung keinginan qta. Untuk melihat opsi lengkap $./configure --help
Untuk membuat redirecting ke HTTPS, sebelumnya harus install openssl dulu.
Penghubung antara Apache dengan openssl adalah module mod_ssl.
Mod_ssl sebenarnya diperuntukkan apache 1.3.x sedangkan untuk apache-2.x mod_ssl telah diinclude kedalamnya sehingga ga perlu install, cukup mengenable aja.
$make
#make install

Untuk menjalankan Apache :
#/usr/local/apache/bin/apachectl start <-- start server
#/usr/local/apache/bin/apachectl stop <-- stop server
#/usr/local/apache/bin/apachectl restart <-- restart server

File konfigurasi apache ada di /usr/local/apache/conf/httpd.conf

Instalasi PHP http://www.php.net
==========================
$tar -jxvf php-5.1.4.tar.bz2
$cd php-5.1.4
$./configure --with-apxs2=/usr/local/apache/bin/apxs --with-gd --with-mysql=/usr/local/mysql/ --with-ming=/usr/local/bin/ --with-zlib-dir=/usr/include/ --with-pear

--with-apxs2 untuk membuat module php5 untuk apache2 yg mengacu pada apache yg diinstall
Untuk apache 1.3.x memakai --with-apxs=path_apache1_3 ato --with-apache=path_apache1_3
--with-gd untuk mensupport gd, image processing di php <-- sebelumnya install gd dulu
--with-mysql mensupport database mysql
--with-ming untuk mensupport flash processing di php <-- install ming dulu
--with-zlib support kompresi zlib
--with-pear mensupport pear
$make
#make install


Konfigurasi Apache untuk mengenali PHP
===============================
Edit file konfigurasi Apache, gunakan editor yg disenangi.
#mcedit /usr/local/apache/conf/httpd.conf
Pastikan apache telah mengaktifkan modul php5, sempurnakan ato tambahkan konfigurasi ini:

LoadModule php5_module modules/libphp5.so <-- pastikan ada file libphp5.so di /usr/local/apache/modules/
AddType application/x-httpd-php .php

Jangan lupa untuk merestart server Apache.
Untuk memastikan server sudah support PHP, coba bikin file test.php di DocumentRoot biasanya di /usr/local/apache/htdocs
//========test.php=======
phpinfo();
?>

Klo server sudah support PHP, maka test.php akan dieksekusi tapi jika belum maka file tidak dikenali sehingga akan muncul form download.

Auto Redirecting HTTPS
=======================
Edit file konfigurasi Apache
#mcedit /usr/local/apache/conf/httpd.conf

<-- document root server, setiap request HTTP akan diarahkan ke directory ini.
Options Indexes FollowSymLinks MultiViews
AllowOverride All
RewriteEngine On
RewriteCond %{SERVER_PORT} !^443$ <-- mengaktifkan port 443 untuk HTTPS
RewriteRule ^(.*) https://%{SERVER_NAME}/$1 [L,R] <-- rewrite page/encrypt ke HTTPS
Order allow,deny
Allow from all

#=== pada akhir file httpd.conf -- cek this ======
# Secure (SSL/TLS) connections
Include conf/extra/httpd-ssl.conf <-- hilangkan tanda '#' untuk mengaktifkan file konfigurasi SSL

SSLRandomSeed startup builtin
SSLRandomSeed connect builtin



Klo mo merubah konfigurasi SSL, termasuk letak sertifikat SSL, edit aja file /usr/local/apache/conf/extra/httpd-ssl.conf
Letak sertifikat secara default adalah di /usr/local/apache/conf

#============httpd-ssl.conf============

DocumentRoot "/docroot"
ServerName localhost:443
ServerAdmin imamwib@students.stttelkom.ac.id
ErrorLog /usr/local/apache/logs/error_log
TransferLog /usr/local/apache/logs/access_log

SSLEngine on
SSLCipherSuite ALL:!ADH:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv2:+EXP:+eNULL
SSLCertificateFile /usr/local/apache/conf/server.crt
SSLCertificateKeyFile /usr/local/apache/conf/server.key


SSLOptions +StdEnvVars


SSLOptions +StdEnvVars


BrowserMatch ".*MSIE.*" nokeepalive ssl-unclean-shutdown downgrade-1.0 force-response-1.0


CustomLog /usr/local/apache/logs/ssl_request_log "%t %h %{SSL_PROTOCOL}x %{SSL_CIPHER}x \"%r\" %b"


Nah..selanjutnya qta bikin sertifikasi SSL :
# openssl genrsa -out /usr/local/apache/conf/server.key 1024
# openssl req -new -days 365 -key /usr/local/apache/conf/server.key -out /usr/local/apache/conf/server.csr

# openssl x509 -in /usr/local/apache/conf/server.csr -out /usr/local/apache/conf/server.crt -req -signkey /usr/local/apache/conf/server.key -days 365
# cd /usr/local/apache/conf/
# chmod 400 server.*


Restartlah server Apache dan coba browsing
http://localhost maka secara otomatis akan diredirect ke https://localhost