How to Install PHP on Mac

Rodolfo Martins
2 min readMay 4, 2023

PHP is a popular programming language that is used to develop web applications. If you’re using a Mac and want to develop web applications using PHP, you’ll need to install PHP on your machine. In this article, we’ll guide you through the process of installing PHP on a Mac, step by step.

Step 1: Install Homebrew

Homebrew is a package manager for macOS that allows you to install and manage software packages easily. To install Homebrew, open the Terminal app on your Mac and run the following command:

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

This command will download and install Homebrew on your Mac.

Step 2: Install PHP

Once Homebrew is installed, you can use it to install PHP. Run the following command in your Terminal app:

brew install php

This command will install the latest version of PHP on your Mac.

Step 3: Check the PHP Version

To verify that PHP is installed correctly, you can check the version of PHP installed on your machine. Run the following command in your Terminal app:

php -v

This command will display the version of PHP installed on your Mac.

Step 4: Configure PHP

After installing PHP, you may want to configure it to suit your needs. You can do this by editing the php.ini file. To locate the php.ini file, run the following command in your Terminal app:

php --ini

This command will display the location of the php.ini file. You can then use a text editor to open the file and make the necessary changes.

Step 5: Start the PHP Server

You can start the PHP server by running the following command in your Terminal app:

php -S localhost:8000

This command will start the PHP server on port 8000. You can then open your web browser and go to http://localhost:8000 to view your PHP application.

Congratulations! You have successfully installed PHP on your Mac. You can now start developing web applications using PHP.

--

--