Secara default, Leopard maupun Snow Leopard sebenarnya sudah terintegrasi dengan aplikasi webserver yang lengkap. Apache dan PHP sudah ter-include didalamnya. MySQL saja yang belum ada dalam paket, sebenarnya kita tinggal install MySQL sendiri juga bisa.
Macports, dapat dikatakan merupakan sebuah aplikasi yang berfungsi sebagai manajemen paket/aplikasi di sistem operasi yang dibuat Apple. Sehingga kita dapat menginstal berbagai macam aplikasi dengan mudah semudah jika menggunakan apt atau yum di Linux.
Sekarang kita mulai, go..go..go..
Download Macports id www.macports.org, sesuaikan dengan sistem yang digunakan, Tiger, Leopard ataupun Snow Leopard. Install Macports hingga selesai. (Setelah selesai disarankan untuk logoff dari system terlebih dahulu).
Jalankan Terminal (/Applications/Utilities/Terminal).
Install Apache:
$ sudo port install apache2 ---> Computing dependencies for apache2 --[ cut ]-- ########################################################### # A startup item has been generated that will aid in # starting apache2 with launchd. It is disabled # by default. Execute the following command to start it, # and to cause it to launch at startup: # # sudo launchctl load -w /Library/LaunchDaemons/org.macports.apache2.plist ########################################################### Note: apache2 installs files outside the common directory structure. ---> Installing apache2 @2.2.14_0+darwin+preforkmpm ---> Activating apache2 @2.2.14_0+darwin+preforkmpm ---> Cleaning apache2
Sampai disini, berarti Apache telah terinstall dengan sukses, kemudian jalankan perintah berikut
$ sudo launchctl load -w /Library/LaunchDaemons/org.macports.apache2.plist
perintah tersebut dimaksudkan agar Apache langsung dijalankan ketika komputer dihidupkan.
Install PHP:
$ sudo port install php5 ---> Computing dependencies for php5 --[ cut ]-- Note: php5 installs files outside the common directory structure. ---> Installing php5 @5.3.1_1+apache2+darwin_10+macosx ---> Activating php5 @5.3.1_1+apache2+darwin_10+macosx To customize php, copy /opt/local/etc/php5/php.ini-development (if this is a development server) or /opt/local/etc/php5/php.ini-production (if this is a production server) to /opt/local/etc/php5/php.ini and then make changes. If this is your first install, you need to activate PHP in your web server. To enable PHP in Apache, run cd /opt/local/apache2/modules /opt/local/apache2/bin/apxs -a -e -n "php5" libphp5.so ---> Cleaning php5 $ sudo port install php5-mysql --[ cut ]-- To use mysqlnd with a local MySQL server, edit /opt/local/etc/php5/php.ini and set mysql.default_socket, mysqli.default_socket and pdo_mysql.default_socket to /opt/local/var/run/mysql5/mysqld.sock
PHP5 telah berhasil diinstall. Selanjutnya kopi file /opt/local/etc/php5/php.ini-production menjadi /opt/local/etc/php5/php.ini
$ sudo cp /opt/local/etc/php5/php.ini-production /opt/local/etc/php5/php.ini
Arahkan mysql.default_socket, mysqli.default_socket and pdo_mysql.default_socket pada file php.ini ke /opt/local/var/run/mysql5/mysqld.sock
$ sudo nano /opt/local/etc/php5/php.ini
dilanjutkan dengan mengaktifkan modul PHP ke Apache:
$ cd /opt/local/apache2/modules $ sudo /opt/local/apache2/bin/apxs -a -e -n "php5" libphp5.so
Sekarang modul PHP telah terintegrasi dengan Apache, kini kita tinggal sedikit menyempurnakan konfigurasi Apache agar mengenali script PHP.
$ sudo nano /opt/local/apache2/conf/httpd.conf
tambahkan dua baris berikut (taruh diakhir file tidak masalah)
AddType application/x-httpd-php .php AddType application/x-httpd-php-source .phps
simpan dan restart apachenya.
$ sudo /opt/local/apache2/bin/apachectl stop $ sudo /opt/local/apache2/bin/apachectl start
untuk menguji nya buat script PHP dan simpan di /opt/local/apache2/htdocs, misal script phpinfo.php
<?php phpinfo(); ?>
setelah itu buka browser dan arahkan ke http://localhost/phpinfo.php.
Seharusnya informasi tentang PHP sekarang telah ditampilkan di browser, dengan kata lain sukses proses instalasi Apache dan PHP nya.
Sepertinya kurang afdol kalau belum ada databasenya, hehehe. Sekalian diinstall MySQL.
$ sudo port install mysql5-server --[ cut ]-- ########################################################### # A startup item has been generated that will aid in # starting mysql5-server with launchd. It is disabled # by default. Execute the following command to start it, # and to cause it to launch at startup: # # sudo launchctl load -w /Library/LaunchDaemons/org.macports.mysql5.plist ########################################################### ---> Installing mysql5-server @5.1.41_0 ****************************************************** * In order to setup the database, you might want to run * sudo -u _mysql mysql_install_db5 * if this is a new install ****************************************************** ---> Activating mysql5-server @5.1.41_0 ---> Cleaning mysql5-server
Instalasi MySQL sukses jika sudah seperti diatas. Lanjut agar MySQL di load juga pada saat booting.
$ sudo launchctl load -w /Library/LaunchDaemons/org.macports.mysql5.plist
Install database mysql untuk pertama kalinya, jalankan perintah berikut
$ sudo -u _mysql mysql_install_db5
Jalankan MySQL Daemon untuk pertama kali
$ sudo /opt/local/lib/mysql5/bin/mysqld_safe &
Buat password untuk user ‘root’ biar sedikit aman, hehehe
$ /opt/local/lib/mysql5/bin/mysqladmin -u root password '[password]'
Sekarang MySQL juga telah terinstall dengan sukses.
Kini tinggal testing apakah MySQL sudah dapat dikonek dengan benar. Untuk nge-tes nya buat tabel baru di database “test”.
$ /opt/local/lib/mysql5/bin/mysql -uroot -p test
CREATE TABLE satu (id INT NOT NULL AUTO_INCREMENT, nama VARCHAR(30), PRIMARY KEY (id)) ENGINE=MyISAM;
INSERT INTO satu (nama) VALUES ('nama satu'), ('nama dua'), ('nama tiga');
Sekarang buat script PHP dan simpan menjadi ‘tes-mysql.php’ dan taruh di /opt/local/apache2/htdocs
<?
$c = mysql_connect("localhost", "root", "[password]") or die("server DB error");
mysql_select_db("test") or die("database error");
$res = mysql_query("SELECT * FROM satu");
while ( $data = mysql_fetch_object($res) ) {
echo $data->nama . "<br />";
}
?>
Jalankan browser dan arahkan ke http://localhost/tes-mysql.php
Jika tidak ada kesalahanseharusnya saat ini data dari tabel “satu” telah tampil di browser anda.
OK, sedikit tutorial macports disini dan HAPPY NEW YEAR !!
6 Comment(s)