mac osx localhost apache virtual host
Objektif
1. Memasang apache, php dan mysql secara manual di dalam Mac Osx 10.6 Snow Leopard.
2. Menggunakan url seperti http://subdomain.test.dev dalam localhost.
Memasang Apache dan PHP
Sebenarnya Mac osx 10.6 Show Leopard telah di datangkan dengan Apache 2.2.14 dan PHP 5.3.1. Jadi anda hanya perlu mulakan apache dengan arahan berikut.
sudo apachectl start
Kemudian uji localhost anda dengan menaip http://localhost/ di browser. Jika berjaya, anda akan dapat lihat mesej
It works!
Walaupun telah didatangkan dengan php, namun ia tidak di load di dalam apache secara default. Jadi anda perlu edit fail httpd.conf seperti di bawah
1. buka terminal
2. gunakan editor kegemaran anda untuk edit fail httpd.conf di lokasi /etc/apache2/httpd.conf .Dalam contoh ini, saya gunakan nano
sudo nano /private/etc/apache2/httpd.conf
3. cari line ini
#LoadModule php5_module libexec/apache2/libphp5.so
dan buang komen yang ada menjadi
LoadModule php5_module libexec/apache2/libphp5.so
4. Restart apache
sudo apachectl restart
Uji sama ada configuration anda berjaya ataupun tidak.
1. Bina fail phpinfo.php
sudo nano /Library/WebServer/Documents/phpinfo.php
taip dan save kod berikut
<?php
phpinfo();
?>
2. buka url berikut http://localhost/phpinfo.php
Memasang MYSQL
1. Muat turun fail Mysql http://dev.mysql.com/downloads/mysql/5.1.html#macosx-dmg .Pilih sama ada 32 bit ataupun 64 bit bergantung kepada sistem komputer anda.
2. Install kesemua file didalam *.dmg iaitu mysql, mysql startup item dan preference pane.
3. Start Mysql dari preferences.. ( Apple -> system preferences -> mysql )
Memasang virtual host
1. edit fail host
sudo nano /private/etc/hosts
2. Masukkan
127.0.0.1 subdomain.test.dev
3. Edit fail httpd.conf untuk enablekan virtual host
sudo nano /private/etc/apache2/httpd.conf
4. cari line ini
# Virtual hosts #Include /private/etc/apache2/extra/httpd-vhosts.conf
dan buang komen yang ada menjadi
# Virtual hosts Include /private/etc/apache2/extra/httpd-vhosts.conf
5. edit fail httpd-vhosts.conf
sudo nano /private/etc/apache2/extra/httpd-vhosts.conf
6. buang atau komen
## ServerAdmin webmaster@dummy-host.example.com # DocumentRoot "/usr/docs/dummy-host.example.com" # ServerName dummy-host.example.com # ServerAlias http://www.dummy-host.example.com # ErrorLog "/private/var/log/apache2/dummy-host.example.com-error_log" # CustomLog "/private/var/log/apache2/dummy-host.example.com-access_log" com$ # ## ServerAdmin webmaster@dummy-host2.example.com # DocumentRoot "/usr/docs/dummy-host2.example.com" # ServerName dummy-host2.example.com # ErrorLog "/private/var/log/apache2/dummy-host2.example.com-error_log" # CustomLog "/private/var/log/apache2/dummy-host2.example.com-access_log" co$ #
7. masukkan
<VirtualHost *:80>
DocumentRoot "/Library/WebServer/Documents"
ServerName localhost
</VirtualHost>
<VirtualHost *:80>
DocumentRoot "/Projects/myprojects"
ServerName subdomain.test.dev
ErrorLog "/Private/var/log/apache2/myprojects.local-error_log"
<Directory "/Projects/myprojects">
Options Indexes FollowSymLinks
AllowOverride All
Allow from all
</Directory>
</VirtualHost>
dalam contoh di atas, anda gantikan ServerName kepada nama virtual host anda dan path “/Projects/myprojects” dengan lokasi folder projek php anda.
8. clear cache
sudo dscacheutil -flushcache
9. restart apache
sudo apachectl restart
10. sekarang anda boleh akses ke url http://subdomain.test.dev
