Manually install PHP on Mac OS
- 25-07-2022
- Toanngo92
- 0 Comments
There are several precompiled and prepackaged versions of PHP for the MacOS platform. These can greatly assist in setting up a standard configuration. However, if required, for features such as a database driver or another secure server, users may have to build their own PHP and Web server. If users are not familiar with compiling and building their software, it would be a good option to check if there is a pre-built packaged PHP version with the required features.
The Homebrew package manager (Homebrew packet Manager) provides the fastest PHP installation solution on MacOS.
- Go to the Homebrew site ( https://brew.sh/ ) and install homebrew.
- Open terminal, use the following command to start the installation: brew install php
Users can also refer to the following alternative resources to easily install precompiled packages and binaries for PHP on MacOS:
- MacPorts: http://www.macports.org/
- Fink: http://www. finkproject.org/
Mac users also have the option of having pre-made sources or installing binaries shipped with the platform. In this case, the user only needs to edit the Apache configuration file to update the version and enable the Web server. The following steps describe the installation process on MacOS:
Step 1: Open the Apache configuration file in a text editor as root.
sudo open -a TextEdit /etc/httpd/httpd.conf
Step 2: Edit the file. Uncomment the following lines:
Load Module php8_module AddModule mod_php8.c AddType Application/x-httpd-php .php
Step 3: Restart the Web Server.
sudo apachectl graceful
Step 4: Open a text editor and write the following basic script:
<? php phpinfo();
Save it as an index.php file in the web server’s root directory
Step 5: Launch the file in the browser in the appropriate format: http://localhost/index.php