Download Php for Mac Os X Sierra
How to Install PHP on macOS 10.13 High Sierra and 10.14 Mojave using Homebrew and PECL
Part ii of a 2 part serial to set up an Apache/PHP evolution surroundings on macOS
This article is for web developers who want Apache and PHP installed as part of their development environment setup on their Mac.
Brand sure to check out Part One ; my article on How to Install Apache on macOS 10.13 High Sierra and 10.14 Mojave using Homebrew is a pre-requisite to this article.
In the past, I used to rely on the version of Apache and PHP that came pre-loaded with the Bone on my MacBook Pro. I would then install the PHP extensions I needed (e.g. Xdebug, Redis, etc.) from Homebrew.
As of April 1, 2018, Homebrew deprecated the "Homebrew/php" tap in favor of a new "Homebrew/cadre" approach. In addition, although some disquisitional extensions are still supported (eastward.m. MySQLi), most PHP extensions are no longer distributed through Homebrew at all (e.thousand. php71-xdebug, php71-redis, etc.) and require installation through PECL (PHP Extension Customs Library).
With the ever irresolute security rules in macOS forth with the complications of using the macOS pre-installed PHP version forth with PECL, I've decided to change my whole approach and instead use a setup entirely from Homebrew. This new approach allows for a more than uncomplicated installation, more flexibility for versioning and will continue to work across all macOS versions.
These instructions work the same for macOS 10.13 Loftier Sierra and x.14 Mojave. I've non tested on prior versions of macOS, but information technology should work similarly. Also, you don't accept to get-go with a fresh OS install to use this article, but these instructions start at the start with the assumption you have nothing installed because that's just the easiest way to get.
Let'due south get started!
Install Homebrew
If you haven't washed this already, then you lot'll need to:
(Please note the following command is a single line that has wrapped due to page width constraints in Medium. Brand sure to copy the entire line)
$ ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)" Create PHP Log File Directories
PHP comes pre-configured with its own log directories, but we're going to create our own "/usr/local/log/" folder so they're easy to observe when nosotros need to. Follow these steps to create the advisable directories and set their permissions. Disregard any "already exists" messages you might become;
$ sudo mkdir /usr/local/log $ sudo mkdir /usr/local/log/php $ sudo chgrp -R staff /usr/local/log/php $ sudo chmod -R ug+w /usr/local/log/php/
Install and Configure PHP
Up until the end of March 2018, all PHP related brews were handled past Homebrew/php tap, merely that has been deprecated. So now nosotros use what'due south available in the Homebrew/cadre package. This should be better maintained, but is a much less consummate set of packages.
$ brew install php@seven.1 It should be noted that to install other versions of PHP you can simply change the version number (e.g. php@7.ii ). You lot as well take the ability to accept multiple versions of PHP installed at the same fourth dimension and switch between them. Yet this document is specifically designed for installing and configuring PHP 7.i.
Your new php.ini file is located in the following directory:
/usr/local/etc/php/seven.i/php.ini Enable the Necessary Apache Module
Now we need to configure Apache to apply the newly installed PHP module. To do this we'll need to edit the httpd.conf file we installed in Part I of this series:
$ open -east /usr/local/etc/httpd/httpd.conf Scroll to the bottom of the LoadModule entries and add the following line after the mod_rewrite module line:
(Delight note the following command is a single line that has wrapped due to page width constraints in Medium. Brand sure to copy the entire line)
LoadModule php7_module /usr/local/opt/php@7.ane/lib/httpd/modules/libphp7.and so Prepare Directory Index and File Handlers
Yous as well demand to set the Directory Indexes for PHP explicitly, so search for the following cake of text:
<IfModule dir_module>
DirectoryIndex index.html
</IfModule> … and then select and replace it with the post-obit lines:
<IfModule dir_module>
DirectoryIndex index.php index.html
</IfModule>
<FilesMatch \.php$>
SetHandler awarding/x-httpd-php
</FilesMatch> Salvage and exit the text editor.
To commencement the PHP service and brand sure it starts upon reboot, enter the following control in Final:
$ mash services start php@7.ane Validate the PHP Install
To examination if PHP is installed and running as expected, create a file called index.php in the Sites folder you created in Office One of this two part serial:
$ echo "<?php phpinfo();" > ~/Sites/index.php Restart Apache:
$ sudo apachectl -k restart At present do a difficult refresh on your browser (or shut and leave your browser and start information technology support again). Then browse to your local host and y'all should see a PHP info page similar to the one below:
If yous see a similar PHP info page, then congratulations ! Yous at present take Apache and PHP running successfully.
If yous have a problem and information technology doesn't appear that PHP is loading properly, it's possible your browser session is preventing it from refreshing. Attempt shutting downwards and quitting your browser completely. Run the apache reset over again and open your browser and attempt navigating to your localhost. It should work.
Install PECL Extensions
As of March 2018, Homebrew no longer distributes most PHP extensions and they must be installed using PECL. This includes the xdebug , igbinary and redis extensions.
The good news is that PECL is included in your PHP install and all you need to practise is add together its bin location to your system PATH to make it start working from your command line.
** Note: If y'all're installing PHP 7.2, then you can skip this section every bit PECL has already been added to your system PATH.
** Note: Before running the command below, it would be wise to cd into your /usr/local/Cellar/php@7.1/ folder and verify the version number that's listed in the command (e.g. "7.ane.22") information technology could be something different.
export PATH=$PATH:/usr/local/Cellar/php@7.1/7.1.22/bin/ This will add your PHP directory to your arrangement path and restart bash. You should be good to go!
Open Terminal and enter the command below. You should see a list of options instead of "control not found". If you see a listing of options, yous're good go.
$ pecl Install XDebug
This will install XDebug v2.6.0 which is the current stable release (as of this writing) that supports PHP 7.1.
There are other versions of XDebug. You can check them out hither and just substitute the version number you desire.
$ pecl install xdebug-two.6.0 This volition add a line to the elevation of your php.ini file that we will ready after we install the remaining extensions.
Install Igbinary
This will install Igbinary v2.0.6 which is the current stable release (as of this writing) and supports PHP 7.one.
There are other versions of Igbinary. You can check them out here and just substitute the version number y'all desire.
**Note: Y'all must install the Igbinary extension earlier you lot install Redis.
$ pecl install igbinary-2.0.6 This volition add a line to the top of your php.ini file that we will fix later we install Redis and its extension.
Install Redis
First install the Redis server component for our dev environment.
$ mash install redis One time that's complete start Redis and prepare it to restart on reboot.
$ brew services get-go redis Install the Redis PHP Extension
This will install Redis v4.0.2 which is the current stable release (as of this writing) and supports PHP seven.ane.
In that location are other versions of Redis. You tin can cheque them out here and simply substitute the version number you desire.
**Note: You must install the Igbinary extension before you lot install Redis.
$ pecl install redis-4.0.2 Y'all will be asked some questions during install. Answer them every bit follows:
- enable igbinary serializer back up? [no]: aye
- enable lzf compression support? [no]: no
Edit PHP Configuration Settings
Now that we've got all the necessary extensions installed, nosotros can make some final entries to the php.ini file for our evolution environment.
$ open -due east /usr/local/etc/php/7.1/php.ini Detect and remove these 3 lines that were added to the very superlative of the php.ini file in the prior steps. We'll re-add together them in a bit:
extension="redis.so"extension="igbinary.and then"
zend_extension="xdebug.and then"
Coil to the bottom of the php.ini file and paste the following lines in:
; CUSTOM variables
short_open_tag = Off
expose_php = Offerror_reporting = E_ALL & ~E_STRICT
display_errors = On
error_log = "/usr/local/log/php/php_errors.log"
upload_tmp_dir = "/tmp/"
allow_url_fopen = on
[xdebug]
zend_extension="xdebug.so"
xdebug.remote_enable=1
xdebug.remote_autostart=ane
xdebug.remote_host=localhost
xdebug.remote_handler=dbgp
xdebug.remote_port=9000
[redis]
extension="igbinary.so"
extension="redis.so"
session.save_handler = "redis"
session.save_path = "tcp://127.0.0.1:6379?weight=1&timeout=2.v"
Salve and exit the text editor.
Restart Apache:
$ sudo apachectl -grand restart Open your browser and navigate to your http://localhost and you lot should see your PHP info page. Scroll down through and you should run across all the necessary PHP extension information displayed for igbinary, Redis and XDebug with the proper version numbers you installed in the prior steps.
Congratulations ! Y'all now have Apache and PHP with associated extensions running on your Mac development environment.
Download Php for Mac Os X Sierra
Posted by: brendaholdia42.blogspot.com

0 Komentar
Post a Comment