If you’re a Mac user and want to start coding in PHP, you’ll need to install PHP on your machine first. In this tutorial, We will show you how to properly install and configure PHP with mac OS system.
Once you have PHP installed, you can customize its configuration settings and install extensions to enhance its functionality. You can also start a PHP server on your local machine to test your web applications.
How to Install PHP on Mac OS using Brew
Installing PHP in Mac OS is a very easy and common task. Follow these steps and install PHP on your Mac today.
- Step 1: Install Homebrew
- Step 2: Install PHP
- Step 3: Verify PHP Installation
- Step 4: Configure PHP
- Step 5: Install PHP Extensions
- Step 6: Start PHP Server
Step 1: Install Homebrew
Homebrew is a package manager for macOS that simplifies the installation of software. To install Homebrew, open the Terminal app on your Mac and enter the following command:
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
Follow the instructions on the screen to complete the installation process.
Step 2: Install PHP
When you run the command on the terminal, the command installs PHP on your system. Now, you need to run the following command to install PHP:
brew install php
This will download and install the latest version of PHP available in Homebrew’s repository. Depending on your internet speed and Mac configuration, this may take a few minutes.
Step 3: Verify PHP Installation
Now, you need to verify installed PHP version, So open terminal app and run the following command:
php -v
It shows the PHP-installed version.
Step 4: Configure PHP
Enter the following command in the Terminal app:
php --ini
This will display the location of the php.ini file on your machine. Open the file in a text editor and modify the settings as needed. Some common configuration changes include increasing the maximum execution time and memory limit.
Step 5: Install PHP Extensions
PHP is easy to install with the help of Homebrew. It is equally easy to install a PHP extension.
To install a PHP extension, enter the following command in the Terminal app:
brew install php-extension-name
Replace “extension-name” with the name of the extension you want to install. For example, to install the MySQL extension, enter the following command:
brew install php-mysql
Step 6: Start PHP Server
To start a PHP server on your Mac, navigate to the directory containing your PHP files in the Terminal app and enter the following command:
php -S localhost:8000
Now, open the browser and visit http://localhost:8000 in your web browser.
Conclusion
Installing PHP on macOS is a straightforward process thanks to Homebrew. With PHP installed, you can start coding your web applications using one of the most popular server-side scripting languages available.
Recommended Tutorials
- Autocomplete Search Box in PHP MySQL
- Compare Arrays PHP | PHP array_diff() Function
- Get, Write, Read, Load, JSON File from Url PHP
- Functions: Remove First Character From String PHP
- Remove Specific/Special Characters From String In PHP
- How to Replace First and Last Character From String PHP
- Reverse String in PHP
- Array Push, POP PHP | PHP Array Tutorial
- PHP Search Multidimensional Array By key, value, and return key
- json_encode()- Convert Array To JSON | Object To JSON PHP
- PHP remove duplicates from multidimensional array
- PHP Remove Duplicate Elements or Values from Array PHP
- Get Highest Value in Multidimensional Array PHP
- PHP Get Min or Minimum Value in Array
- String PHP to Uppercase, Lowercase & First Letter Uppercase
- PHP: isset() vs empty() vs is_null()
- Chunk_split PHP Function Example
- PHP Function: Date and Time With Examples
- Reverse Number in PHP | PHP Tutorial
If you are using macOS, there’s a new option you can try: Servbay.dev. It includes all versions of PHP, MariaDB, and PostgreSQL, as well as Redis and Memcached. You can run multiple versions of PHP instances at the same time and it’s easy to switch between them for debugging/testing. With just a few clicks, you can enjoy your PHP development environment.