I feel this is an awfully obtuse question to ask, but strangely, this problem is poorly documented.
I would like to upgrade PHP, but there are several problems:
There is no built-in package manager. MacPorts doesn't recognize php as an installed package because it didn't install PHP itself.
Running locate php indicates there are probably many dependencies.
I don't know HOW php was installed, as it was included with the OS, so I don't know whether I should install from source or download binaries. I also don't know the proper way to uninstall the previous version without breaking dependencies.
I am running on Leopard. I have a feeling Apple doesn't want you to upgrade. Would buying Snow Leopard and upgrade solve this problem (and future ones like it)?
You may want to check out Marc Liyanage's PHP package. It comes in a nice Mac OS X installer package that you can double-click. He keeps it pretty up to date.
http://php-osx.liip.ch/
Also, although upgrading to Snow Leopard won't help you do PHP updates in the future, it will probably give you a newer version of PHP. I'm running OS X 10.6.2 and it has PHP 5.3.0.
I use this: https://github.com/Homebrew/homebrew-php
The command is:
$ xcode-select --install
$ brew tap homebrew/dupes
$ brew tap homebrew/versions
$ brew tap homebrew/homebrew-php
$ brew options php56
$ brew install php56
Then config in your .bash_profile or .bashrc
# Homebrew PHP CLI
export PATH="$(brew --prefix homebrew/php/php56)/bin:$PATH"
I think one simple way to do it, is:
1 - Check you where is your current PHP:
$ which php
$ /usr/local/bin/php
You see? Usually, our commands that we run is a link in /usr/local/bin so...
2 - Unlink this current link of PHP
unlink /usr/local/bin/php
If you prefere, before unlink it, check the path and then remove php files (do ls -al /usr/local/bin | grep php and then rm -rf into desired path)
3 - Install PHP 7.1
curl -s http://php-osx.liip.ch/install.sh | bash -s 7.1
4 - Create new link (using php 7.1 bin that you have installed)
ln /usr/local/php5-7.1.9-20170914-100859/bin/php /usr/local/bin/php
Like I said, its a simple way I think.
There is no built-in package manager. MacPorts doesn't recognize php as an installed package because it didn't install PHP itself.
You could still install it with MacPorts. sudo port install php52 (or whichever version you want) will install PHP.
It won't overwrite the Apple-supplied version. It'll install it under /opt/local. You can add /opt/local to the beginning of your $PATH, and use the MacPorts version in your Apache config.
Option #1
As recommended here, this site provides a convenient, up-to-date one liner.
This doesn't overwrite the base version of PHP on your system, but instead installs it cleanly in /usr/local/php5.
Option #2
My preferred method is to just install via Homebrew.
Before I go on, I have the latest version (v5.0.15) of OS X Server (yes, horrible, I know...however, the web server seems to work A-OK). I searched high and low for days trying to update (or at least get Apache to point to) a new version of PHP. My mcrypt did not work, along with other extensions and I installed and reinstalled PHP countless times from http://php-osx.liip.ch/ and other tutorials until I finally noticed a tid-bit of information written in a comment in one of the many different .conf files OS X Server keeps which was that OS X Server loads it's own custom .conf file before it loads the Apache httpd.conf (located at /etc/apache2/httpd.conf). The server file is located:
/Library/Server/Web/Config/apache2/httpd_server_app.conf
When you open this file, you have to comment out this line like so:
#LoadModule php5_module libexec/apache2/libphp5.so
Then add in the correct path (which should already be installed if you have installed via the http://php-osx.liip.ch/ link):
LoadModule php5_module /usr/local/php5/libphp5.so
After this modification, my PHP finally loaded the correct PHP installation. That being said, if things go wonky, it may be because OS X is made to work off the native installation of PHP at the time of OS X installation. To revert, just undo the change above.
Anyway, hopefully this is helpful for anyone else spending countless hours on this.
Upgrading to Snow Leopard won't solve the your primary problem of keeping PHP up to date. Apple doesn't always keep the third party software that it bundles up to date with OS updates. And relying on Apple to get you the bug fix / security update you need is asking for trouble.
Additionally, I would recommend installing through MacPorts (and doing the config necessary to use it instead of Apple's PHP) rather than try to upgrade the Apple supplied PHP in place. Anything you do to /usr/bin risks being overwritten by some future Apple update.
Saving on keystrokes, this worked on MacOS Sierra:
$ brew install homebrew/php/php71
$ /usr/local/opt/php71/bin/php -v
PHP 7.1.4 (cli) (built: Apr 14 2017 15:02:16) ( NTS )
Copyright (c) 1997-2017 The PHP Group
Zend Engine v3.1.0, Copyright (c) 1998-2017 Zend Technologies
Check your current php version in terminal with the following command,
$ php -v
You see current php version in terminal, and next command run in terminal if you want to upgrade your php version with php concat with version liked as,
$ brew install homebrew/php/php71
Please restart terminal if you finished php version upgrade installed and run the command.
$ php -v
Now you see the current php version in terminal....thank
Use this Command:
curl -s http://php-osx.liip.ch/install.sh | bash -s 7.0
You can use curl to update php version.
curl -s http://php-osx.liip.ch/install.sh | bash -s 7.3
Last Step:
export PATH=/usr/local/php5/bin:$PATH
Check the upgraded version
php -v
best way to upgrade is
compile it from source
see this tutorial that may be helful for you
http://www.computersnyou.com/2012/09/how-to-upgrade-php-in-mac-osx-compiling.html
to upgrade php7 to latest stable version brew upgrade php7
or for php5.X to latest stable version
brew upgrade php56
use brew list to check installed version
Related
Since updating my mac to Montery my php-server 0.8.0 in atom no longer works and I'm given this error
Listening on http://localhost:8000
Document root is /Applications/MAMP/htdocs
PHP Server could not launch
Have you defined the right path to PHP in your settings? Using PHP
Can anybody help me set this back up? Here are my settings.
v
macOS 12 (”Monterey”) is the first version that no longer ships with PHP included. That said, you will need to install PHP yourself. The PHP documentation lists several ways to install it, the most common way is to use Homebrew:
Enter the following in a terminal window to install Homebrew
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
Now you can install the latest PHP version
brew install php
The last couple of PHP 7.x versions are still maintained by the Homebrew team, for even older releases there's a ”tap” (third party repository.)
I am unable to find any info on installing PHP 7.4, all the info seems to go untill 7.3 but that has not been helpful.
What I have done so far is execute:
curl -s https://php-osx.liip.ch/install.sh | bash -s 7.4
And this is the message I got:
It doesn't seem to install. How can I solve this problem?
If you check the script https://php-osx.liip.ch/install.sh you can see it only support 7.3
Yes, you can install and upgrade to latest php version on mac without homebrew.
For me I use MacPorts a package manager for MacOS which is similar to HomeBrew but more stable.
Example to upgrade to php74:
sudo port install php74
Install the extensions you need
sudo port install php74-cgi php74-gd php74-curl php74-intl php74-iconv php74-gettext php74-mbstring php74-imap php74-mcrypt php74-xmlrpc php74-mysql php74-openssl php74-sockets php74-zip php74-tidy php74-opcache php74-xsl php74-sqlite
Select php74 as the active PHP version. With this command you can have multiple php version and quickly switch from one to the other.
sudo port select php php74
Check which PHP binary is used (should return /opt/local/bin/php). Perhaps you may need to restart you terminal.
which php
Check the version (should return “PHP 7.4.XX (cli)…”)
php --version
Also, If you use XAMPP ensure to restart Apache Web server.
(Article Reference)
it seems like a little bit stupid question, but Google for one hour and cannot find it:
How to install php on macOS via brew and use in in shell.
Install is simple (if you have brew already installed):
brew install php
But after installation, when i use php -v i still see default php on mac os and not the brew's one. Shoud I Add brew php binary into PATH, bash profile, or what?
Thank you!
homebrew creates symbolic links in /usr/local/bin to pretty much every binary it installs. So the answer to your question is to add that to your path in your login profile. That will probably be $HOME/.profile and you can add a line like:
export PATH=/usr/local/bin:$PATH
Then it will be set each time you login or open a new Terminal.
So in my case, the trouble was with some access permissions on specific folders on my Mac OS, so just sharing what I learned: if it's not working, carefully examile log / error feed, there can be a hint for you!
On April 1, 2018 Homebrew discontinued the Homebrew/php tap and went with a core install approach, which means many of the extensions now must be installed with PECL. I have written a two part blog series to help with installing Apache and PHP w/ PECL on later versions of MacOS. You can find it at the link below, I hope it helps!
https://medium.com/#crmcmullen/how-to-install-php-on-macos-10-13-high-sierra-and-10-14-mojave-using-homebrew-and-pecl-ef2276db3d62
Step 1: Install Homebrew
The first step is to install Homebrew and this is a tool (package manager for macOS) that will allow us to install easily PHP and basically any other package/tools.
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
Step 2: Install PHP
To install PHP we can use the command below. The first command will automatically install the latest version of PHP which is at the current moment of writing this post version 8.
brew install php
If other versions may be preferred we can specify the PHP version and the code will look like the following.
brew install php#7.4
Step 3: The php.ini Config
The default PHP configuration should be sufficient to get started but if there are any other configurations, we can change them through the php.ini located on this path. Do note the PHP version number which in this case is version 8.
/usr/local/etc/php/8.1/php.ini
Step 4: Check if PHP is running
To check if PHP is already running we can make use of the brew services command. First, we can list the services that we have installed.
brew services list
If PHP is not started we can then run the command below to start the service in the background.
brew services start php#8.1
Step 5: Checking PHP Version
Lastly to check the PHP version do run:
php -v
By now you will have PHP running on the background process and every time you logged in to the system it will start by default. Thanks for reading and have a good try.
How to install/enable php-gd and mcrypt in Yosemite 10.10 - PHP 5.5.14 build?
note that following steps install newest PHP 5.5.x
To check if you have gd and mcrypt installed use $ php -m to display compiled in modules, continue if you are missing desired modules and please see accepted answer.
GD
So, Apple installed GD (and you're using their build of PHP, which is fine), but did not include support for PNG.
You are definitely missing "full" gd (with png support) module if:
imagecreatefrompng() function is missing.
"Call to undefined function imagecreatefrompng()"
Mcrypt
install brew using accepted answer and omit part with gd installation (unless you need it), and use following steps:
do search - $ brew search mcrypt
pick the version of PHP you want
install - $ brew install php55-mcrypt
confirm using $ php -m | grep mcrypt
Want to switch between PHP versions?
Check out brew-php-switcher and follow instructions.
You are right, Yosemite's built-in PHP comes without PNG and FreeType support.
Update 2015/10 for El Captian: With OS X 10.11 El Capitan PNG support is back, but FreeType is still missing.
Solution
Use the Homebrew package manager to painlessly build and install a complete PHP and replace it in Apache's config. The whole process only takes about ten minutes if you follow the steps below.
A quick (but complete) walk through
(Note 1: I use Homebrew here, a package management system for OS X. If you are acquainted with MacPorts – another package manager – you can acchieve the same results with that system. It is also possible to use my Homebrew solution in parallel to an existing MacPorts installation on your machine.)
(Note 2: If you want to read all the details about the installation process, have a look at the Homebrew basic installation and the Homebrew PHP installation information. But you really won't need that if you follow these steps.)
Now let's go...
First install Xcode from App Store. If you already have it, check App Store again, to make sure you've got the latest version!
Now you need to install the Xcode Command Line Tools. To do so, open a Terminal and enter:
xcode-select --install
The next command will install the Homebrew package manager system:
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
The script explains what it will do and then pauses before it does it.
The next command to enter is a kind of system status test:
brew doctor
This checks the basics of the Homebrew installation.
I got a warning "You have MacPorts or Fink installed: /opt/local/bin/port ..." which I ignored successfully. ;)
Now setup the homebrew/dupes tap which has dependencies we need:
brew tap homebrew/dupes
Setup the homebrew/versions tap which also has dependencies we need:
brew tap homebrew/versions
Then run the following command:
brew tap homebrew/homebrew-php
Now you are ready to finally build PHP. For a list of available configuration options you may run one of these:
brew options php55
brew options php56
But I was fine just using the defaults.
To do so enter ONE of these two, depending on your needs:
brew install php55
brew install php56
(This takes a while, please be patient!)
while installing php56 (5.6.x) on Yosemite (10.10.5) there is a bug please see this issue on github. use brew install php56 --without-ldap instead.
If you get an error of type "Cannot find OpenSSL's " you have not installed the Xcode Command Line Tools as I told you in the beginning. ;) Go ahead, install them and re-run that last command.
PHP is built now and the script will end with some details about how to use it:
Open httpd.conf (should be located at /private/etc/apache2/httpd.conf) and enable PHP by adding ONE of these two lines, depending on which PHP version you just installed:
LoadModule php5_module /usr/local/opt/php55/libexec/apache2/libphp5.so
LoadModule php5_module /usr/local/opt/php56/libexec/apache2/libphp5.so
Don't forget to comment out any existing LoadModule php5_module... line that might be present from Yosemite's own PHP version!
Restart Apache
sudo apachectl restart
Your new php.ini file can be found in: /usr/local/etc/php/5.5/php.ini
Enjoy!
The answer from #Jpsy is good, but there's another option, from the guys from liip, here. This is a PHP package that comes pre-built for Yosemite (older versions works too) but it is just one line of code:
curl -s http://php-osx.liip.ch/install.sh | bash -s 5.5
After that, everything is ready to work as expected. The configuration that cames with that installation is well suited for Symfony 2 development, but it should work just fine with other use cases.
Finally, if you need to use the updated PHP CLI, too, but you don't want to use the PHP version that comes with the OS, then you could also add to your .bash_profile or similar this line of code:
export PATH=/usr/local/php5/bin:$PATH
I don't have enough rep to make a comment, but if you're using OS X Server for Yosemite (Version 4 from the App Store) the file to edit is:
/library/server/web/config/apache2/httpd_server_app.conf
mine looks like this now and confirmed it is working after using php 5.6 from homebrew.
#LoadModule php5_module libexec/apache2/libphp5.so
LoadModule php5_module /usr/local/opt/php56/libexec/apache2/libphp5.so
Standard Apache coming with Yosemite the file to update after
sudo brew install php55
is in /etc/apache2/httpd.conf
Note that location of php.ini is also changed. The standard one coming with Yosemite is in /etc/php.ini, the one with homebrewed version is in /usr/local/etc/php/5.5/php.ini
Since Mac OS 10.8 had an old PHP version I had to install a never version of PHP. So I just compile PHP 5.4.13. Then I do a php -v on the terminal and it shows me that the new php version is running. But When I do a phpinfo from the browser it shows me the old PHP version which is PHP 5.3.x. This is even after creating a soft link to the new php build,
/opt/local/lib/php(old one) -> /usr/bin/php(new one)
Any ideas how to fix this issue?
I just ran into the same issue, wanting to try Laravel which requires mcrypt.
In a nutshell, I had been using the built-in PHP 5.3.26 that came with Mountain Lion, then some months later after I'd gotten more familiar with homebrew, I used it to install a newer version of PHP.
brew update
brew upgrade
brew install php53 php53-mcrypt ...
I put
<?php phpinfo();
into ~/Sites/info.php then went to localhost/info.php to see my Apache+PHP config. On the page, I saw this, under Loaded Configuration File:
/private/etc/php.ini
Then in Termninal, I ran this:
php -i | grep ini
which showed this output
Loaded Configuration File => /usr/local/etc/php/5.3/php.ini
Plus even more configs loaded as well ...
Additional .ini files parsed => /usr/local/etc/php/5.3/conf.d/ext-mcrypt.ini,
/usr/local/etc/php/5.3/conf.d/ext-xdebug.ini,
/usr/local/etc/php/5.3/conf.d/redis.ini
The problem I had was that mcrypt was loading in the php cli version, but my Laravel test page wouldn't load giving an mcrypt extension not found error [1]
I used a diffmerge tool [2] to compare the original Apple php.ini in /private/etc/ to the one homebrew installed in /usr/local/etc/php/5.3/ and found there to be significant differences! So check carefully before trying this:
What I did next was to backup
sudo mv /private/etc/php.ini /private/etc/php.ini.apple
Then symlink the php.ini to homebrew's instead
ln -s /usr/local/etc/php/5.3/php.ini /private/etc/php.ini
Finally after reloading Apache
sudo apachectl restart
And mcrypt loaded, and now they're using a single config.
If you have another app on your localhost that breaks with the new config, just remove the symlink, and change it to the .apple version and restart Apache to revert back.
Laravel requires the Mcrypt PHP extension
https://sourcegear.com/diffmerge/
This might be a good reference:
how do i install php 5.4 on Mac OS X Lion?
There are some detailed instructions on upgrading PHP to 5.4, and also notes on how MacPorts can make it pretty painless.
I'm running OS X 10.9. I updated PHP to v5.5.8 and found that Apache was correctly running the new version but the terminal was still running the old one. After hunting around for a solution for a while, I eventually thought, "I'll give it a restart."
Bingo! Terminal and Apache are running the same version of PHP.