Males install XAMPP karena gede banget, akhirnya berkeputusan install semi-manual apache di Mojave gw, karena mac gw habis dibabat alias reinstall ulang. mau restore timemachine tapi ga bisa karena timemachineku yang dulu pake APFS yang case-sensitive, sementara utk yg baru ini gw mau install OneDrive(dibahas di blog lain).
Berikut step by step instalasinya
Instalasi XCode Command Line Tools
xcode-select --install
Operation Not Permitted di Terminal
Secara default, setelah instalasi osx kita tidak bisa melakukakn aktivitas administrasi maupun akses ke folder admin melalui terminal. cara enablenya :
- Buka System Preferences
- Pilih Security & Privacy
- Pilih tab Privacy
- dari menu sebelah kiri pilih Full Disk Access
- klik tanda plus, cari aplikasi terminal kemudian pilih
- tutup, dan relaunch aplikasi terminal
Instalasi Homebrew
Kalo Homebrew belum diinstall, jalankan :
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
Ikuti aja petunjuk yang di terminal, dan masukkan password kalau dibutuhkan. setelah instalasi selesai, check versi brew :
brew --version
Kalau di saya tampilnya
Homebrew 2.0.1
Homebrew/homebrew-core (git revision 6ffb; last commit 2019-02-16)
Library yang dibutuhkan sama mojave :
brew install openldap libiconv
Instalasi Apache
brew install httpd
Setelah selesai, start service dan test :
1. di browser anda dengan mengetik http://localhost:8080, sebagai catatan, default port untuk instalasi ini adalah 8080. jadi untuk testingnya harus pake port
2. liat servicenya jalan ga
ps ax | grep httpd
Seperti yang lain, untuk start/stop/restart gunakan perintah :
sudo apachectl start
sudo apachectl stop
sudo apachectl -k restart
Konfigurasi Apache
Letak konfigurasi apache ada di
/usr/local/etc/httpd/httpd.conf
untuk editnya, terserah mau pake apa, kalo gw udah kebiasaan pake VI
Ubah Port (8080 ke 80)
Cari Listen 8080, ganti ke Listen 80
DocumentRoot
Ganti lokasi documentroot ke folder favorit anda
Enable Rewrite
Karena gw pake CI dan kebetulan butuh untuk rewrite via htaccess, cari mod_rewrite.so dan lepas tanda pagar (#)
User & Groups
Ubah ke user kita, group staff
Servername
Dari pengalaman, kalau nama macbook kita agak aneh, kadang jadi error/warning pas restart apache via terminal. Makanya harus kita ubah nama komputer kita
Ubah Nama Mac
- Buka System Preferences
- Klik Sharing
- Klik Computer Name, pilih dan kemudian masukkan nama baru
- done
Instalasi PHP
Instalasi di brew, kita bisa milih versi phpnya, tapi yg disupport tanpa embel2 instalasi lainnya itu php 7.1 ke atas. kalo mau pilih php yg lebih tua harus tambah library untuk yg udah deprecated
Saran gw, mending ke 7+ biar lebih update. nah untuk instalasi sqlsrv, dari pengalaman gw gbs yang 7.1 keatas, sempat install 7.3, tapi malah pas instalasi driver sqlsrvnya error ga jelas yg ngehabisin waktu. Instalasi PHP 7.1 :
brew install php@7.1
setelah selesai, check versinya
php -v
PHP 7.1.25 (cli) (built: Dec 7 2018 08:20:45) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.1.0, Copyright (c) 1998-2018 Zend Technologies
with Zend OPcache v7.1.25, Copyright (c) 1999-2018, by Zend Technologies
Konfigurasi PHP
Enable lib phpnya di httpd.conf (lokasi ada diatas)
LoadModule php7_module /usr/local/opt/php@7.1/lib/httpd/modules/libphp7.so
Konfigurasi Lain di httpd.confg
DirectoryIndex index.php index.html
SetHandler application/x-httpd-php
Konfigurasi Lain di php.ini (lokasi /usr/local/etc/php/7.1)
short_open_tag=On
Udah selesai? restart service dan check pake script
phpinfo();
Instalasi sqlsrv untuk connect ke Microsoft SQL Server
Versi lengkapnya ada di sini
Install Library yg dibutuhkan
brew install autoconf automake libtool
Install Drivernya
sudo pecl install sqlsrv
sudo pecl install pdo_sqlsrv
Setelah itu restart apache
done
testing konektivitas sql server dengan melihat info.php yang tadi kita buat, search mssql, kalau ada brarti udah terinstall dengan sukses. test juga dengan script ini
$serverName = "10.211.55.3";
$connectionOptions = array(
"database" => "namadatabase",
"uid" => "sa",
"pwd" => "passwordnya"
);
// Establishes the connection
$conn = sqlsrv_connect($serverName, $connectionOptions);
if ($conn === false) {
die(formatErrors(sqlsrv_errors()));
}
sqlsrv_free_stmt($stmt);
sqlsrv_close($conn);
function formatErrors($errors)
{
// Display errors
echo "Error information:
";
foreach ($errors as $error) {
echo "SQLSTATE: ". $error['SQLSTATE'] . "
";
echo "Code: ". $error['code'] . "
";
echo "Message: ". $error['message'] . "
";
}
}