Haloo gaes, pada tutorial kali ini aku akan share tutorial cara setup local development tanpa menginstall aplikasi web server seperti XAMPP ataupun MAMP. Kita akan menggunakan beberapa fitur bawaan Mac OS.
Mac OS yang aku gunakan saat ini adalah Mac OS Big Sur version 11.6.2
Apache2
Secara default Mac OS sudah terinstall apache2. Untuk mengeceknya buka terminal run apachectl -v . Hasilnya seperti ini.
dhimaskirana:~$ apachectl -v Server version: Apache/2.4.51 (Unix) Server built: Nov 1 2021 21:26:04
Secara default lokasi file-file yang akan ditampilkan oleh apache berlokasi di /Library/WebServer/Documents.
PHP
Secara default Mac OS sudah terinstall php versi 7.3. Untuk mengecek kalian bisa menjalankan php -v
dhimaskirana:~$ php -v WARNING: PHP is not recommended PHP is included in macOS for compatibility with legacy software. Future versions of macOS will not include PHP. PHP 7.3.29-to-be-removed-in-future-macOS (cli) (built: Sep 6 2021 05:14:39) ( NTS ) Copyright (c) 1997-2018 The PHP Group Zend Engine v3.3.29, Copyright (c) 1998-2018 Zend Technologies
Tetapi akan ada warning bahwa di versi mac berikutnya php akan dihapus dari Mac OS. Jadi sebaiknya kalian menginstall php sendiri menggunakan Homebrew.
Menginstall Homebrew
Nah, kita akan menginstall php menggunakan homebrew. Homebrew merupakan sebuah package manager untuk iOS, yang dapat diinstall dengan mudah melalui terminal.
Sebelum menginstall php, install homebrew dulu. Kunjungi website homebrew di brew.sh. Kemudian kalian copy script Install Homebrew dan jalankan pada terminal. Tunggu sampai proses instalasi selesai. Kalau kalian baru pertama kali menginstall homebrew, proses instalasi akan memakan waktu yang cukup lama.
Menginstall PHP
Oke homebrew sudah terinstall saatnya menginstall php. Untuk menginstall php jalankan perintah brew install php. Homebrew akan menginstall PHP versi terbaru. Tunggu sampai proses install selesai.
Setelah instalasi php selesai, jalankan perintah export PATH="/usr/local/opt/php/bin:$PATH" untuk menambahkan path php ke environment variable pada Mac OS, sehingga perintah php bisa dieksekusi secara global.
Jika berhasil, silahkan lakukan perintah php -v, maka versi yang muncul adalah versi terbaru.
dhimaskirana:~$ php -v PHP 8.1.3 (cli) (built: Mar 1 2022 10:23:25) (NTS) Copyright (c) The PHP Group Zend Engine v4.1.3, Copyright (c) Zend Technologies with Zend OPcache v8.1.3, Copyright (c), by Zend Technologies
Menginstall MySQL
Langkah selanjutnya adalah menginstall MySQL untuk keperluan database. Untuk menginstall mysql jalankan perintah brew install mysql@5.7. Tunggu hingga proses instalasi selesai. Jika sudah selesai, untuk mengecek versi mysql yang terinstall gunakan mysql –version
dhimaskirana:~$ mysql --version mysql Ver 14.14 Distrib 5.7.37, for osx10.16 (x86\_64) using EditLine wrapper
Set Modul PHP di Apache
Secara default apache di Mac OS tidak memuat modul php, oleh karena itu jalankan perintah brew info php. Maka akan keluar informasi terkait modul php yang sudah kita install melalui homebrew tadi seperti berikut ini.
\==> Caveats To enable PHP in Apache add the following to httpd.conf and restart Apache: LoadModule php\_module /usr/local/opt/php/lib/httpd/modules/libphp.so <filesmatch> SetHandler application/x-httpd-php </filesmatch> Finally, check DirectoryIndex includes index.php DirectoryIndex index.php index.html
Informasi ini yang akan kita gunakan untuk menkonfigurasikan apache supaya memuat modul php yang telah kita install.
Jalankan perintah berikut ini untuk membuat teks editor.
sudo /System/Applications/TextEdit.app/Contents/MacOS/TextEdit /private/etc/apache2/httpd.conf
Perintah ini akan membuka file httpd.conf (file konfigurasi apache2) menggunakan aplikasi bawaan Mac OS yaitu TextEdit secara administrator atau root. Jangan lupa masukan password.
Masukan semua konfigurasi ke dalam file httpd.conf seperti pada gambar di atas. Konfigurasi yang perlu di set adalah:
- LoadModule php
- SetHandler supaya bisa membaca file php
- DirectoryIndex
Jangan lupa klik simpan tersebut. Kemudian tutup aplikasi teks editornya.
Kemudian restart apache nya supaya apache nya mengenali php 8.1 yang telah di install tadi. Cara nya jalankan perintah untuk merestart apache.
sudo apachectl restart
Test PHP
Buat file index.php dalam sebuah folder phpinfo, kemudian masukan fungsi phpinfo(). Kemudian akses dengan alamat http://localhost/phpinfo/.
Jika informasi PHP muncul, maka apache sukses memuat modul php. Nah kalian bisa mencoba menginstall WordPress.
Install phpMyAdmin
Setelah php berhasil, kita akan gunakan phpMyAdmin untuk mengakses database mysql kita. phpMyAdmin adalah database management berbasis web browser, sehingga akan mempermudah kita membuat database.
Download phpMyAdmin di https://www.phpmyadmin.net/downloads/ kemudian pilih saja yang bahasa English saja.
Unzip, kemudian rename folder menjadi phpmyadmin, copy ke /Library/WebServer/Documents.
Akses menggunakan alamat http://localhost/phpmyadmin/.
Secara default akses mysql menggunakan username root dan password kosong.
Jika kalian mendapati error Login without a password is forbidden by configuration (see AllowNoPassword) berarti phpMyAdmin tidak mengijinkan password kosong.
Solusinya gampang, kalian buka folder phpmyadmin kemudian ada file config.sample.inc.php rename jadi config.inc.php.
Kemudian buka file config.inc.php dengan text editor kalian, kemudian set AllowNoPassword menjadi true. Simpan konfigurasi file kalian.
$cfg\['Servers'\]\[$i\]\['AllowNoPassword'\] = true;
mod_rewrite
Jika permalink WordPress kalian error padahal sudah buat file .htaccess di instalasi WordPress kemungkinan penyebabnya adalah modul mod_rewrite belum dimuat di apache.
Caranya adalah buka kembali file httpd.conf menggunakan perintah sudo supaya dibuka menggunakan akses root, kemudian uncomment rewrite_module. Kemudian simpan dan restart apache menggunakan perintah sudo apachectl restart.
Permission
Jika kalian mengcopy file ke dalam folder /Library/WebServer/Documents maka file kalian hanya bisa dibaca tetapi tidak bisa dieksekusi. Ini terjadi karena secara default apache berjalan diatas user _www dan group _www.
Solusinya adalah:
- Menambahkan username account kalian ke group _www
- Semua file yang kalian copy ke /Library/WebServer/Documents harus diubah owner dan groupnya ke _www
- Memberikan akses write ke group _www
Tambah Username ke Group _www
Langsung kita coba, tambahkan username kalian ke group _www dengan command berikut. whoami di command akan digantikan dengan username kalian.
sudo dseditgroup -o edit -a `whoami` -t user _www
Untuk mengecek apakah username kalian sudah masuk ke group _www bisa menggunakan command berikut
dscacheutil -q group -a name _www
Ubah Owner dan Group file ke _www
Setelah itu, setiap kita mengcopy file atau folder ke dalam /Library/WebServer/Documents, kita harus mengubah owner dan group semua file yg dicopy ke _www.
Sebagai contoh kalian copy folder wordpress ke /Library/WebServer/Documents. Maka buka terminal di /Library/WebServer/Documents, kemudian jalankan perintah:
sudo chown -R _www:_www wordpress
Memberikan akses write ke group _www
Setelah semua file menjadi owner dan group _www, maka sekarang kita akan memberikan akses supaya semua user di dalam group _www dapat write file kita.
g+w artinya group + (tambahkan) write.
sudo chmod -R g+w wordpress
Nah begitulah tutorial konfigurasi Apache, PHP, dan MySQL di Mac OS. Jika kalian menemui kesulitan bisa tulis di kolom komentar yaa, kita sama-sama belajar bareng.
Selamat mencoba.
The above is the detailed content of Tutorial Setup Localhost Mac (ApacheMySQL , and PHP ). For more information, please follow other related articles on the PHP Chinese website!

Long URLs, often cluttered with keywords and tracking parameters, can deter visitors. A URL shortening script offers a solution, creating concise links ideal for social media and other platforms. These scripts are valuable for individual websites a

Following its high-profile acquisition by Facebook in 2012, Instagram adopted two sets of APIs for third-party use. These are the Instagram Graph API and the Instagram Basic Display API.As a developer building an app that requires information from a

Laravel simplifies handling temporary session data using its intuitive flash methods. This is perfect for displaying brief messages, alerts, or notifications within your application. Data persists only for the subsequent request by default: $request-

This is the second and final part of the series on building a React application with a Laravel back-end. In the first part of the series, we created a RESTful API using Laravel for a basic product-listing application. In this tutorial, we will be dev

Laravel provides concise HTTP response simulation syntax, simplifying HTTP interaction testing. This approach significantly reduces code redundancy while making your test simulation more intuitive. The basic implementation provides a variety of response type shortcuts: use Illuminate\Support\Facades\Http; Http::fake([ 'google.com' => 'Hello World', 'github.com' => ['foo' => 'bar'], 'forge.laravel.com' =>

The PHP Client URL (cURL) extension is a powerful tool for developers, enabling seamless interaction with remote servers and REST APIs. By leveraging libcurl, a well-respected multi-protocol file transfer library, PHP cURL facilitates efficient execution of various network protocols, including HTTP, HTTPS, and FTP. This extension offers granular control over HTTP requests, supports multiple concurrent operations, and provides built-in security features.

Do you want to provide real-time, instant solutions to your customers' most pressing problems? Live chat lets you have real-time conversations with customers and resolve their problems instantly. It allows you to provide faster service to your custom

The 2025 PHP Landscape Survey investigates current PHP development trends. It explores framework usage, deployment methods, and challenges, aiming to provide insights for developers and businesses. The survey anticipates growth in modern PHP versio


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

Atom editor mac version download
The most popular open source editor

Dreamweaver Mac version
Visual web development tools

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.
