Install Apache, PHP and MySQL on MacOS 12 (Monterey).

Author
By Darío Rivera
Posted On in MacOS

MacOS is an excellent operating system for developing web applications. If you are a developer or need to set up a project developed in PHP with Apache and MySQL, this article will guide you step by step to the necessary configuration packages.

Apache Installation

The first step is to install Apache. For this, you can review our article exclusively dedicated to this installation.

- Install and configure Apache on MacOS 12 (Monterey)

PHP Installation

The next step would be to install PHP in any of its supported versions. For this, you can review our next article.

- Install several versions of PHP on MacOS 12 (Monterey)

Configure Apache with PHP

After this, you must configure Apache to work with PHP. To do this, you must first find the following lines

<IfModule dir_module>
    DirectoryIndex index.html
</IfModule>

And replace them with

<IfModule dir_module>
    DirectoryIndex index.php index.html
</IfModule>

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

Subsequently, during the PHP installation, you should have received a message to configure the library in Apache. You must configure this line in the /opt/homebrew/etc/httpd/httpd.conf file.

LoadModule php7_module /opt/homebrew/opt/php@7.4/lib/httpd/modules/libphp7.so

MySQL Installation

brew install mysql
mysql.server start

Once this is done, the next step will be to secure the installation. This means performing some configurations such as verifying created passwords (length, special characters, uppercase and lowercase letters), removing anonymous users, disabling remote login, and deleting test databases. You can use the following command for this and follow the instructions.

mysql_secure_installation
brew services start mysql

Acerca de Darío Rivera

Author

Application Architect at Elentra Corp . Quality developer and passionate learner with 10+ years of experience in web technologies. Creator of EasyHttp , an standard way to consume HTTP Clients.

LinkedIn Twitter Instagram

Sólo aquellos que han alcanzado el éxito saben que siempre estuvo a un paso del momento en que pensaron renunciar.