Install PHP and MongoDB in Mac OS

XCODE and brew Should be installed already

MONGODB

brew services start [email protected]
brew services stop [email protected]

mongodb://localhost:27017

Apache

brew install httpd

brew services start httpd

Installation complete

The default ports have been set in /opt/homebrew/etc/httpd/httpd.conf to 8080 and in
/opt/homebrew/etc/httpd/extra/httpd-ssl.conf to 8443 so that httpd can run without sudo.

To restart httpd after an upgrade:
brew services restart httpd
Or, if you don’t want/need a background service you can just run:
/opt/homebrew/opt/httpd/bin/httpd -D FOREGROUND
kavin@Kavins-MacBook-Pro ~ % brew services start httpd
==> Successfully started httpd (label: homebrew.mxcl.httpd)

/opt/homebrew/var/www
brew services start httpd


PHP

/opt/homebrew/etc/php/8.2/

To enable PHP in Apache add the following to httpd.conf and restart Apache:
LoadModule php_module /opt/homebrew/opt/php/lib/httpd/modules/libphp.so

<FilesMatch \.php$>
    SetHandler application/x-httpd-php
</FilesMatch>

Finally, check DirectoryIndex includes index.php
DirectoryIndex index.php index.html

The php.ini and php-fpm.ini file can be found in:
/opt/homebrew/etc/php/8.2/

To restart php after an upgrade:
brew services restart php
Or, if you don’t want/need a background service you can just run:
/opt/homebrew/opt/php/sbin/php-fpm –nodaemonize

MONGODB

Build process completed successfully
Installing ‘/opt/homebrew/Cellar/php/8.2.5/pecl/20220829/mongodb.so’
install ok: channel://pecl.php.net/mongodb-1.15.2
php.ini “/Applications/XAMPP/xamppfiles/etc/php.ini” does not exist
You should add “extension=mongodb.so” to php.ini

MYSQL

We’ve installed your MySQL database without a root password. To secure it run:
mysql_secure_installation

MySQL is configured to only allow connections from localhost by default

To connect run:
mysql -u root

To restart mysql after an upgrade:
brew services restart mysql
Or, if you don’t want/need a background service you can just run:
/opt/homebrew/opt/mysql/bin/mysqld_safe –datadir=/opt/homebrew/var/mysql

How to install PHP + Apache + MySQL + phpMyAdmin on macOS Monterey using Homebrew · GitHub

PHPMYADMIN

To enable phpMyAdmin in Apache, add the following to httpd.conf and
restart Apache:
Alias /phpmyadmin /opt/homebrew/share/phpmyadmin

Options Indexes FollowSymLinks MultiViews
AllowOverride All
Require all granted
Order allow,deny Allow from all

Then open http://localhost/phpmyadmin
The configuration file is /opt/homebrew/etc/phpmyadmin.config.inc.php
==> Summary
🍺 /opt/homebrew/Cellar/phpmyadmin/5.2.1: 4,191 files, 48.1MB
==> Running brew cleanup phpmyadmin
Disable this behaviour by setting HOMEBREW_NO_INSTALL_CLEANUP.
Hide these hints with HOMEBREW_NO_ENV_HINTS (see man brew).

Reference

Getting Set Up to Run PHP with MongoDB | MongoDB

Leave a Reply

Your email address will not be published. Required fields are marked *