With the development of Internet technology, more and more coders are beginning to use Mac as a development environment. However, the PHP environment version that comes with the Mac system is relatively old, so a higher version of the PHP environment needs to be used for development. This article will introduce how to install PHP7.1 through brew.
Preparation
First, we need to ensure that Homebrew has been installed on the Mac system. If it is not installed, you can install it through the following command:
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
After the installation is completed, you can check whether Homebrew is installed successfully by running the following command:
brew --version
Next, we need to install the dependent libraries required by PHP7.1, including libiconv, icu4c, libjpeg, libpng, libmcrypt, freetype, etc., which can be installed at once through the following command:
brew install autoconf icu4c jpeg libmcrypt libpng libxml2 libzip pkg-config zlib freetype fontconfig libiconv
Install PHP7.1
Next, we can install PHP7.1 through the following command:
brew tap homebrew/homebrew-php
brew install https://github.com/Homebrew/homebrew-php/blob/86f9a1aaf7c5660070e878ca11b703f2c929f148/Formula/php.rb --with-httpd24
Here we need to note that php.rb is installed instead of php71.rb, because php71.rb has been deprecated.
After the installation is complete, you can check whether PHP is installed successfully by running the following command:
php -v
Configure PHP
After installing PHP, you need to configure PHP Make some adjustments to the configuration to make it run smoothly in our development environment.
First, we need to open the PHP configuration file and enter the following command in the terminal:
cd /usr/local/etc/php/7.1/
cp php.ini.default php .ini
At this point, we can edit the php.ini file through vim or nano commands for configuration. For example, we can set the recording level of PHP's error log to E_ALL:
error_reporting = E_ALL
At the same time, we can also set PHP's time zone to our region:
date.timezone = Asia/Shanghai
Finally, we need to restart Apache to enable PHP:
sudo apachectl restart
At this point, we have successfully installed PHP7.1 and configure it as necessary.
Conclusion
Through the above steps, we can quickly and easily install PHP7.1 on the Mac system and make the necessary configurations to achieve better development results. However, we should also note that installation and configuration are processes that are constantly changing and updating. Therefore, it is recommended that you always pay attention to official documents and community information, and maintain technical reserves and the pace of updates and iterations.
The above is the detailed content of Mac uses brew to install php7.1. For more information, please follow other related articles on the PHP Chinese website!