{"id":995,"date":"2026-05-20T02:20:57","date_gmt":"2026-05-20T02:20:57","guid":{"rendered":"https:\/\/www.devopsschool.com\/tutorials\/?p=995"},"modified":"2026-05-20T02:20:58","modified_gmt":"2026-05-20T02:20:58","slug":"macos-step-by-step-tutorial-install-php-apache-and-mysql-on-macos-using-homebrew","status":"publish","type":"post","link":"https:\/\/www.devopsschool.com\/tutorials\/macos-step-by-step-tutorial-install-php-apache-and-mysql-on-macos-using-homebrew\/","title":{"rendered":"MacOS: Step-by-Step Tutorial: Install PHP, Apache, and MySQL on macOS using Homebrew"},"content":{"rendered":"\n<p><\/p>\n\n\n\n<p>This guide installs a clean local development stack on macOS using:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Apache  = httpd from Homebrew\nPHP     = PHP from Homebrew\nMySQL   = mysql@8.4 from Homebrew\n<\/code><\/pre>\n\n\n\n<p>Homebrew installs packages cleanly under its own directory and symlinks them into the Homebrew prefix, usually <code>\/opt\/homebrew<\/code> on Apple Silicon Macs. Homebrew\u2019s official formulae provide <code>httpd<\/code>, <code>php<\/code>, and MySQL packages directly. (<a href=\"https:\/\/brew.sh\/?utm_source=chatgpt.com\">brew.sh<\/a>)<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h1 class=\"wp-block-heading\">1. Check your Mac type<\/h1>\n\n\n\n<p>Run:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>uname -m\n<\/code><\/pre>\n\n\n\n<p>If output is:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>arm64\n<\/code><\/pre>\n\n\n\n<p>You are using Apple Silicon, such as M1, M2, M3, or M4.<\/p>\n\n\n\n<p>If output is:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>x86_64\n<\/code><\/pre>\n\n\n\n<p>You are using an Intel Mac.<\/p>\n\n\n\n<p>Most new Macs use this Homebrew path:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\/opt\/homebrew\n<\/code><\/pre>\n\n\n\n<p>Intel Macs usually use:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\/usr\/local\n<\/code><\/pre>\n\n\n\n<p>To avoid confusion, always use this command when you need the actual Homebrew path:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>brew --prefix\n<\/code><\/pre>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h1 class=\"wp-block-heading\">2. Install Xcode Command Line Tools<\/h1>\n\n\n\n<p>Homebrew requires Apple\u2019s Command Line Tools on macOS. Homebrew\u2019s installation documentation lists Command Line Tools for Xcode as one of the macOS requirements. (<a href=\"https:\/\/docs.brew.sh\/Installation?utm_source=chatgpt.com\">Homebrew Documentation<\/a>)<\/p>\n\n\n\n<p>Run:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>xcode-select --install\n<\/code><\/pre>\n\n\n\n<p>A popup may appear. Click <strong>Install<\/strong>.<\/p>\n\n\n\n<p>After installation, verify:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>xcode-select -p\n<\/code><\/pre>\n\n\n\n<p>Expected output may look like:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\/Library\/Developer\/CommandLineTools\n<\/code><\/pre>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h1 class=\"wp-block-heading\">3. Install Homebrew<\/h1>\n\n\n\n<p>Run:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\/bin\/bash -c \"$(curl -fsSL https:\/\/raw.githubusercontent.com\/Homebrew\/install\/HEAD\/install.sh)\"\n<\/code><\/pre>\n\n\n\n<p>After installation, add Homebrew to your shell profile.<\/p>\n\n\n\n<p>For Apple Silicon:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>echo 'eval \"$(\/opt\/homebrew\/bin\/brew shellenv)\"' &gt;&gt; ~\/.zprofile\neval \"$(\/opt\/homebrew\/bin\/brew shellenv)\"\n<\/code><\/pre>\n\n\n\n<p>For Intel Mac:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>echo 'eval \"$(\/usr\/local\/bin\/brew shellenv)\"' &gt;&gt; ~\/.zprofile\neval \"$(\/usr\/local\/bin\/brew shellenv)\"\n<\/code><\/pre>\n\n\n\n<p>Verify:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>brew --version\n<\/code><\/pre>\n\n\n\n<p>Example output:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Homebrew 4.x.x\n<\/code><\/pre>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h1 class=\"wp-block-heading\">4. Update Homebrew<\/h1>\n\n\n\n<p>Run:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>brew update\n<\/code><\/pre>\n\n\n\n<p>You can also check your Homebrew health:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>brew doctor\n<\/code><\/pre>\n\n\n\n<p>If you see:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Your system is ready to brew.\n<\/code><\/pre>\n\n\n\n<p>Perfect.<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h1 class=\"wp-block-heading\">5. Install Apache<\/h1>\n\n\n\n<p>Homebrew\u2019s Apache package is called <code>httpd<\/code>. The official Homebrew formula uses this command: <code>brew install httpd<\/code>. (<a href=\"https:\/\/formulae.brew.sh\/formula\/httpd?utm_source=chatgpt.com\">Homebrew Formulae<\/a>)<\/p>\n\n\n\n<p>Run:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>brew install httpd\n<\/code><\/pre>\n\n\n\n<p>Start Apache:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>brew services start httpd\n<\/code><\/pre>\n\n\n\n<p>Check status:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>brew services list\n<\/code><\/pre>\n\n\n\n<p>You should see something like:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>httpd started\n<\/code><\/pre>\n\n\n\n<p>Check Apache version:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>httpd -v\n<\/code><\/pre>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h1 class=\"wp-block-heading\">6. Test Apache<\/h1>\n\n\n\n<p>Homebrew Apache usually serves files from:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\/opt\/homebrew\/var\/www\n<\/code><\/pre>\n\n\n\n<p>On Intel Mac, it may be:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\/usr\/local\/var\/www\n<\/code><\/pre>\n\n\n\n<p>To find the correct location, run:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>brew --prefix\n<\/code><\/pre>\n\n\n\n<p>If output is <code>\/opt\/homebrew<\/code>, your web root is:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\/opt\/homebrew\/var\/www\n<\/code><\/pre>\n\n\n\n<p>Create a simple test file:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>echo \"Apache is working on macOS\" &gt; \"$(brew --prefix)\/var\/www\/index.html\"\n<\/code><\/pre>\n\n\n\n<p>Open in browser:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>http:&#47;&#47;localhost:8080\n<\/code><\/pre>\n\n\n\n<p>You should see:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Apache is working on macOS\n<\/code><\/pre>\n\n\n\n<p>By default, Homebrew Apache commonly uses port <code>8080<\/code>, which avoids conflict with macOS\u2019s built-in Apache.<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h1 class=\"wp-block-heading\">7. Install PHP<\/h1>\n\n\n\n<p>Run:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>brew install php\n<\/code><\/pre>\n\n\n\n<p>Check PHP version:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>php -v\n<\/code><\/pre>\n\n\n\n<p>Find PHP configuration files:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>php --ini\n<\/code><\/pre>\n\n\n\n<p>This is useful later when you want to edit PHP settings like:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>upload_max_filesize\npost_max_size\nmemory_limit\nmax_execution_time\n<\/code><\/pre>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h1 class=\"wp-block-heading\">8. Connect PHP with Apache<\/h1>\n\n\n\n<p>Homebrew\u2019s PHP formula provides the Apache configuration needed to load PHP. It specifically says to add the PHP module line, the PHP file handler, and ensure <code>DirectoryIndex<\/code> includes <code>index.php<\/code>. (<a href=\"https:\/\/formulae.brew.sh\/formula\/php?utm_source=chatgpt.com\">Homebrew Formulae<\/a>)<\/p>\n\n\n\n<p>Open Apache config:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>nano \"$(brew --prefix)\/etc\/httpd\/httpd.conf\"\n<\/code><\/pre>\n\n\n\n<p>Find the <code>LoadModule<\/code> section and add this line:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>LoadModule php_module \/opt\/homebrew\/opt\/php\/lib\/httpd\/modules\/libphp.so\n<\/code><\/pre>\n\n\n\n<p>For Intel Mac, use:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>LoadModule php_module \/usr\/local\/opt\/php\/lib\/httpd\/modules\/libphp.so\n<\/code><\/pre>\n\n\n\n<p>A safer universal way is to first check your Homebrew prefix:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>brew --prefix\n<\/code><\/pre>\n\n\n\n<p>Then use the matching path.<\/p>\n\n\n\n<p>Now add this PHP handler somewhere near the other handler settings:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;FilesMatch \\.php$&gt;\n    SetHandler application\/x-httpd-php\n&lt;\/FilesMatch&gt;\n<\/code><\/pre>\n\n\n\n<p>Now search for:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>DirectoryIndex index.html\n<\/code><\/pre>\n\n\n\n<p>Change it to:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>DirectoryIndex index.php index.html\n<\/code><\/pre>\n\n\n\n<p>Save and exit:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>CTRL + O\nEnter\nCTRL + X\n<\/code><\/pre>\n\n\n\n<p>Restart Apache:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>brew services restart httpd\n<\/code><\/pre>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h1 class=\"wp-block-heading\">9. Test PHP with Apache<\/h1>\n\n\n\n<p>Create a PHP test file:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>echo \"&lt;?php phpinfo(); ?&gt;\" &gt; \"$(brew --prefix)\/var\/www\/index.php\"\n<\/code><\/pre>\n\n\n\n<p>Open:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>http:&#47;&#47;localhost:8080\n<\/code><\/pre>\n\n\n\n<p>If PHP is working, you will see the PHP information page.<\/p>\n\n\n\n<p>After testing, remove the file because <code>phpinfo()<\/code> exposes system details:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>rm \"$(brew --prefix)\/var\/www\/index.php\"\n<\/code><\/pre>\n\n\n\n<p>Create a safer test file:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>cat &gt; \"$(brew --prefix)\/var\/www\/index.php\" &lt;&lt;'EOF'\n&lt;?php\necho \"PHP is working with Apache on macOS\";\nEOF\n<\/code><\/pre>\n\n\n\n<p>Open again:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>http:&#47;&#47;localhost:8080\n<\/code><\/pre>\n\n\n\n<p>Expected output:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>PHP is working with Apache on macOS\n<\/code><\/pre>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h1 class=\"wp-block-heading\">10. Install MySQL<\/h1>\n\n\n\n<p>For development, install MySQL 8.4:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>brew install mysql@8.4\n<\/code><\/pre>\n\n\n\n<p>Homebrew lists <code>mysql@8.4<\/code> as an available MySQL version. (<a href=\"https:\/\/formulae.brew.sh\/formula\/mysql?utm_source=chatgpt.com\">Homebrew Formulae<\/a>)<\/p>\n\n\n\n<p>Start MySQL:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>brew services start mysql@8.4\n<\/code><\/pre>\n\n\n\n<p>Check service:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>brew services list\n<\/code><\/pre>\n\n\n\n<p>Add MySQL to your shell path:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>echo 'export PATH=\"$(brew --prefix mysql@8.4)\/bin:$PATH\"' &gt;&gt; ~\/.zprofile\nsource ~\/.zprofile\n<\/code><\/pre>\n\n\n\n<p>Check MySQL version:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>mysql --version\n<\/code><\/pre>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h1 class=\"wp-block-heading\">11. Secure MySQL<\/h1>\n\n\n\n<p>Run:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>mysql_secure_installation\n<\/code><\/pre>\n\n\n\n<p>Recommended answers for local development:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Validate password component? Optional\nSet root password? Yes\nRemove anonymous users? Yes\nDisallow root login remotely? Yes\nRemove test database? Yes\nReload privilege tables? Yes\n<\/code><\/pre>\n\n\n\n<p>Now login:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>mysql -u root -p\n<\/code><\/pre>\n\n\n\n<p>Enter your MySQL root password.<\/p>\n\n\n\n<p>Test command:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>SHOW DATABASES;\n<\/code><\/pre>\n\n\n\n<p>Exit:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>exit;\n<\/code><\/pre>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h1 class=\"wp-block-heading\">12. Create a test database and user<\/h1>\n\n\n\n<p>Login:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>mysql -u root -p\n<\/code><\/pre>\n\n\n\n<p>Create database:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>CREATE DATABASE testapp;\n<\/code><\/pre>\n\n\n\n<p>Create user:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>CREATE USER 'testuser'@'localhost' IDENTIFIED BY 'StrongPassword123!';\n<\/code><\/pre>\n\n\n\n<p>Give permission:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>GRANT ALL PRIVILEGES ON testapp.* TO 'testuser'@'localhost';\n<\/code><\/pre>\n\n\n\n<p>Reload permissions:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>FLUSH PRIVILEGES;\n<\/code><\/pre>\n\n\n\n<p>Exit:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>exit;\n<\/code><\/pre>\n\n\n\n<p>Test login:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>mysql -u testuser -p testapp\n<\/code><\/pre>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h1 class=\"wp-block-heading\">13. Test PHP connection with MySQL<\/h1>\n\n\n\n<p>Create test file:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>cat &gt; \"$(brew --prefix)\/var\/www\/dbtest.php\" &lt;&lt;'EOF'\n&lt;?php\n$host = \"127.0.0.1\";\n$db   = \"testapp\";\n$user = \"testuser\";\n$pass = \"StrongPassword123!\";\n\ntry {\n    $pdo = new PDO(\"mysql:host=$host;dbname=$db;charset=utf8mb4\", $user, $pass);\n    echo \"PHP connected to MySQL successfully.\";\n} catch (PDOException $e) {\n    echo \"Database connection failed: \" . $e-&gt;getMessage();\n}\nEOF\n<\/code><\/pre>\n\n\n\n<p>Open:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>http:&#47;&#47;localhost:8080\/dbtest.php\n<\/code><\/pre>\n\n\n\n<p>Expected result:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>PHP connected to MySQL successfully.\n<\/code><\/pre>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h1 class=\"wp-block-heading\">14. Useful service commands<\/h1>\n\n\n\n<p>Start Apache:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>brew services start httpd\n<\/code><\/pre>\n\n\n\n<p>Stop Apache:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>brew services stop httpd\n<\/code><\/pre>\n\n\n\n<p>Restart Apache:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>brew services restart httpd\n<\/code><\/pre>\n\n\n\n<p>Start MySQL:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>brew services start mysql@8.4\n<\/code><\/pre>\n\n\n\n<p>Stop MySQL:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>brew services stop mysql@8.4\n<\/code><\/pre>\n\n\n\n<p>Restart MySQL:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>brew services restart mysql@8.4\n<\/code><\/pre>\n\n\n\n<p>Check all services:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>brew services list\n<\/code><\/pre>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h1 class=\"wp-block-heading\">15. Important file locations<\/h1>\n\n\n\n<p>For Apple Silicon Macs:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Apache config:\n \/opt\/homebrew\/etc\/httpd\/httpd.conf\n\nApache web root:\n \/opt\/homebrew\/var\/www\n\nPHP module:\n \/opt\/homebrew\/opt\/php\/lib\/httpd\/modules\/libphp.so\n\nMySQL binary:\n \/opt\/homebrew\/opt\/mysql@8.4\/bin\/mysql\n<\/code><\/pre>\n\n\n\n<p>For Intel Macs:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Apache config:\n \/usr\/local\/etc\/httpd\/httpd.conf\n\nApache web root:\n \/usr\/local\/var\/www\n\nPHP module:\n \/usr\/local\/opt\/php\/lib\/httpd\/modules\/libphp.so\n\nMySQL binary:\n \/usr\/local\/opt\/mysql@8.4\/bin\/mysql\n<\/code><\/pre>\n\n\n\n<p>Universal commands:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>brew --prefix\nbrew --prefix php\nbrew --prefix mysql@8.4\n<\/code><\/pre>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h1 class=\"wp-block-heading\">16. Optional: Change Apache port from 8080 to 80<\/h1>\n\n\n\n<p>By default, keep Apache on:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>http:&#47;&#47;localhost:8080\n<\/code><\/pre>\n\n\n\n<p>This is safer because port <code>80<\/code> may conflict with macOS\u2019s built-in Apache and usually requires root privileges.<\/p>\n\n\n\n<p>But if you want:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>http:&#47;&#47;localhost\n<\/code><\/pre>\n\n\n\n<p>Open Apache config:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>nano \"$(brew --prefix)\/etc\/httpd\/httpd.conf\"\n<\/code><\/pre>\n\n\n\n<p>Find:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Listen 8080\n<\/code><\/pre>\n\n\n\n<p>Change to:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Listen 80\n<\/code><\/pre>\n\n\n\n<p>Restart Apache with sudo:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo brew services restart httpd\n<\/code><\/pre>\n\n\n\n<p>But my recommendation: <strong>use port 8080 for local development<\/strong>.<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h1 class=\"wp-block-heading\">17. Optional: Create a project folder<\/h1>\n\n\n\n<p>Instead of putting everything directly in Apache\u2019s default web root, you can create your own project folder.<\/p>\n\n\n\n<p>Example:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>mkdir -p ~\/Sites\/myapp\n<\/code><\/pre>\n\n\n\n<p>Create file:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>cat &gt; ~\/Sites\/myapp\/index.php &lt;&lt;'EOF'\n&lt;?php\necho \"My PHP project is working\";\nEOF\n<\/code><\/pre>\n\n\n\n<p>Now update Apache config:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>nano \"$(brew --prefix)\/etc\/httpd\/httpd.conf\"\n<\/code><\/pre>\n\n\n\n<p>Find:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>DocumentRoot \"\/opt\/homebrew\/var\/www\"\n&lt;Directory \"\/opt\/homebrew\/var\/www\"&gt;\n<\/code><\/pre>\n\n\n\n<p>Change both paths to your project:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>DocumentRoot \"\/Users\/YOUR_USERNAME\/Sites\/myapp\"\n&lt;Directory \"\/Users\/YOUR_USERNAME\/Sites\/myapp\"&gt;\n<\/code><\/pre>\n\n\n\n<p>Replace <code>YOUR_USERNAME<\/code> with your macOS username.<\/p>\n\n\n\n<p>You can get it using:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>whoami\n<\/code><\/pre>\n\n\n\n<p>Also make sure this section allows access:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;Directory \"\/Users\/YOUR_USERNAME\/Sites\/myapp\"&gt;\n    Options Indexes FollowSymLinks\n    AllowOverride All\n    Require all granted\n&lt;\/Directory&gt;\n<\/code><\/pre>\n\n\n\n<p>Restart Apache:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>brew services restart httpd\n<\/code><\/pre>\n\n\n\n<p>Open:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>http:&#47;&#47;localhost:8080\n<\/code><\/pre>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h1 class=\"wp-block-heading\">18. Enable <code>.htaccess<\/code> support<\/h1>\n\n\n\n<p>For Laravel, WordPress, CodeIgniter, Flarum, and many PHP apps, you may need <code>.htaccess<\/code>.<\/p>\n\n\n\n<p>Open Apache config:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>nano \"$(brew --prefix)\/etc\/httpd\/httpd.conf\"\n<\/code><\/pre>\n\n\n\n<p>Find your directory block:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;Directory \"\/opt\/homebrew\/var\/www\"&gt;\n<\/code><\/pre>\n\n\n\n<p>Inside it, change:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>AllowOverride None\n<\/code><\/pre>\n\n\n\n<p>To:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>AllowOverride All\n<\/code><\/pre>\n\n\n\n<p>Also enable rewrite module. Find this line:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>#LoadModule rewrite_module lib\/httpd\/modules\/mod_rewrite.so\n<\/code><\/pre>\n\n\n\n<p>Uncomment it:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>LoadModule rewrite_module lib\/httpd\/modules\/mod_rewrite.so\n<\/code><\/pre>\n\n\n\n<p>Restart Apache:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>brew services restart httpd\n<\/code><\/pre>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h1 class=\"wp-block-heading\">19. Common problems and fixes<\/h1>\n\n\n\n<h2 class=\"wp-block-heading\">Problem 1: <code>localhost:8080<\/code> not opening<\/h2>\n\n\n\n<p>Check Apache service:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>brew services list\n<\/code><\/pre>\n\n\n\n<p>Restart:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>brew services restart httpd\n<\/code><\/pre>\n\n\n\n<p>Check Apache config syntax:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>apachectl configtest\n<\/code><\/pre>\n\n\n\n<p>Expected:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Syntax OK\n<\/code><\/pre>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">Problem 2: PHP file downloads instead of running<\/h2>\n\n\n\n<p>This means Apache is not processing PHP.<\/p>\n\n\n\n<p>Check whether this exists in <code>httpd.conf<\/code>:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>LoadModule php_module \/opt\/homebrew\/opt\/php\/lib\/httpd\/modules\/libphp.so\n<\/code><\/pre>\n\n\n\n<p>Also check:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;FilesMatch \\.php$&gt;\n    SetHandler application\/x-httpd-php\n&lt;\/FilesMatch&gt;\n<\/code><\/pre>\n\n\n\n<p>Restart:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>brew services restart httpd\n<\/code><\/pre>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">Problem 3: <code>mysql: command not found<\/code><\/h2>\n\n\n\n<p>Add MySQL to PATH:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>echo 'export PATH=\"$(brew --prefix mysql@8.4)\/bin:$PATH\"' &gt;&gt; ~\/.zprofile\nsource ~\/.zprofile\n<\/code><\/pre>\n\n\n\n<p>Check:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>mysql --version\n<\/code><\/pre>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">Problem 4: Permission denied in web root<\/h2>\n\n\n\n<p>Check ownership:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>ls -la \"$(brew --prefix)\/var\/www\"\n<\/code><\/pre>\n\n\n\n<p>Fix ownership:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo chown -R $(whoami):staff \"$(brew --prefix)\/var\/www\"\n<\/code><\/pre>\n\n\n\n<p>Then:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>chmod -R 755 \"$(brew --prefix)\/var\/www\"\n<\/code><\/pre>\n\n\n\n<p>For files:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>find \"$(brew --prefix)\/var\/www\" -type f -exec chmod 644 {} \\;\n<\/code><\/pre>\n\n\n\n<p>For directories:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>find \"$(brew --prefix)\/var\/www\" -type d -exec chmod 755 {} \\;\n<\/code><\/pre>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">Problem 5: Apache config has an error<\/h2>\n\n\n\n<p>Run:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>apachectl configtest\n<\/code><\/pre>\n\n\n\n<p>If it shows a line number, open the file:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>nano \"$(brew --prefix)\/etc\/httpd\/httpd.conf\"\n<\/code><\/pre>\n\n\n\n<p>Fix the mentioned line.<\/p>\n\n\n\n<p>Then restart:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>brew services restart httpd\n<\/code><\/pre>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h1 class=\"wp-block-heading\">20. Final verification checklist<\/h1>\n\n\n\n<p>Run these commands:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>brew services list\n<\/code><\/pre>\n\n\n\n<p>You should see:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>httpd       started\nmysql@8.4  started\n<\/code><\/pre>\n\n\n\n<p>Check Apache:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>httpd -v\n<\/code><\/pre>\n\n\n\n<p>Check PHP:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>php -v\n<\/code><\/pre>\n\n\n\n<p>Check MySQL:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>mysql --version\n<\/code><\/pre>\n\n\n\n<p>Check browser:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>http:&#47;&#47;localhost:8080\n<\/code><\/pre>\n\n\n\n<p>Check PHP:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>http:&#47;&#47;localhost:8080\/index.php\n<\/code><\/pre>\n\n\n\n<p>Check MySQL from PHP:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>http:&#47;&#47;localhost:8080\/dbtest.php\n<\/code><\/pre>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h1 class=\"wp-block-heading\">Recommended final setup<\/h1>\n\n\n\n<p>For your Mac, this is the clean structure:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Package manager: Homebrew\nApache config:   $(brew --prefix)\/etc\/httpd\/httpd.conf\nWeb root:        $(brew --prefix)\/var\/www\nPHP:             Homebrew PHP\nMySQL:           mysql@8.4\nURL:             http:\/\/localhost:8080\n<\/code><\/pre>\n\n\n\n<p>This setup is much cleaner than XAMPP for long-term PHP, WordPress, Laravel, Flarum, and custom development work on macOS.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>This guide installs a clean local development stack on macOS using: Homebrew installs packages cleanly under its own directory and symlinks them into the Homebrew prefix, usually&#8230; <\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[77],"tags":[],"class_list":["post-995","post","type-post","status-publish","format-standard","hentry","category-macos"],"_links":{"self":[{"href":"https:\/\/www.devopsschool.com\/tutorials\/wp-json\/wp\/v2\/posts\/995","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.devopsschool.com\/tutorials\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.devopsschool.com\/tutorials\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.devopsschool.com\/tutorials\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.devopsschool.com\/tutorials\/wp-json\/wp\/v2\/comments?post=995"}],"version-history":[{"count":1,"href":"https:\/\/www.devopsschool.com\/tutorials\/wp-json\/wp\/v2\/posts\/995\/revisions"}],"predecessor-version":[{"id":996,"href":"https:\/\/www.devopsschool.com\/tutorials\/wp-json\/wp\/v2\/posts\/995\/revisions\/996"}],"wp:attachment":[{"href":"https:\/\/www.devopsschool.com\/tutorials\/wp-json\/wp\/v2\/media?parent=995"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.devopsschool.com\/tutorials\/wp-json\/wp\/v2\/categories?post=995"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.devopsschool.com\/tutorials\/wp-json\/wp\/v2\/tags?post=995"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}