Installing PHP 7.4 on macOS Sierra without brew? - php

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)

Related

How to load memcached on PHP in Mac OS X Catalina?

I have tried virtually everything I could for the last 3 hours. I just don't seem to get it to load on PHP. I was able to install it via brew install memcached and successfully make run it as a background service via memcached -d. But that's not really what I am looking for.
I am looking at loading it as one of my PHP modules. Running php -m on the terminal does not list memcached on it at all. Neither looking at phpinfo() or print_r(get_loaded_extensions()); on runtime gave me any luck. I am trying to officially access it in my project via something like extension_loaded('memcached'), of course, this returns a falsy value atm.
I have tried solutions like below:
How to install memcached module for php#7.1 on MacOS High Sierra?
https://donatstudios.com/OS-X-Mavericks-Memcached-PHP-Extension-Installation
Can I install the memcached PHP extension with PECL?
Most of the solutions are similar to the above linked. Unfortunately, this isn't working for me because of an issue similar to this:
Unable to use PHPIZE after update to MacOS Mojave
I also get below error when executing a make command:
make: *** No targets specified and no makefile found. Stop.
And the below error when running ./configure
checking for session includes... configure: error: Cannot find
php_session.h
Meanwhile, I also cannot attempt an install via pecl install memcached due to the error below:
configuration download directory "/tmp/pear/install" is not writeable.
Change download_dir config variable to a writeable dir to avoid this
warning
Basically everything just doesn't work. And honestly, I didn't even know how to start writing this question, so I'm just kinda throwing everything in here.
It doesn't help that there are no recent discussions about installing memcached on PHP since Catalina. A lot of resources are just 5 years old and that's not a good sign, a number of them aren't even valid solutions anymore.
I am losing my mind. Why this thing is so complicated to configure is beyond my comprehension. If someone can point me in the right direction that would be great!
So I was able to find a solution after 2 working days. What you should do is move away from using built-in Apache/PHP from macOS and use the ones from Homebrew.
Here are the descriptive step-by-step procedure I did:
1) Unload the built-in Apache.
2) Install a new Apache from Homebrew via brew install httpd and then run the service
3) Install PHP via brew install php
4) Configure httpd.conf from /usr/local/etc/httpd/, including loading Homebrew PHP module, mod_rewrite, setting up DirectoryIndex, ServerName, default Listen port, etc.
4.1) If you are using virtual hosts, set this up on /usr/local/etc/httpd/extra/
5) Configure ~/.bash_profile to use the new PHP version (test via php -v or which php)
6) Install PEAR
7) Install memcached via PEAR
I have compiled a list of links that you can use:
Apache & PHP Installation
https://tecadmin.net/install-apache-macos-homebrew/
https://getgrav.org/blog/macos-catalina-apache-multiple-php-versions
https://gist.github.com/DragonBe/0faebe58deced34744953e3bf6afbec7
Follow brew info php to configure Homebrew PHP to Homebrew Apache
Configure bash profile to use homebrew php by default
PHP --version shown incorrectly on osX
How to use the php that brew installed?
Install PEAR and configure
https://jasonmccreary.me/articles/install-pear-pecl-mac
Install memcached via PEAR
pecl install memcached then follow instructions
Or
How to install memcached module for php#7.1 on MacOS High Sierra?
https://donatstudios.com/OS-X-Mavericks-Memcached-PHP-Extension-Installation
Can I install the memcached PHP extension with PECL?
why don't you try vagrant box. You will get a virtual environment of your choice, install a ubuntu environment in minutes and you can get a LAMP or MEAN / MERN vagrant box ready made.
Steps :
1) Download and install virtualbox.
2) Download and install Vagrant
3) Go to terminal
Check if vagrant is installed or not.
vagrant -v
In order to get a ubuntu box spinning up, run these commands.
vagrant init ubuntu/trusty64
It will download you a ubuntu box in minutes.
vagrant up
vagrant ssh
Have a look at vagrant you will enjoy it.
Also there are whole lot of ready to use boxes
Vagrant boxes
Documentation : [Vagrant Document]

PHPInfo / Valet - Two different PHP versions

OK so I am experiencing something quite odd. My phpinfo() shows one version while php -v shows another.
I am running locally on a MacBook Air (Mojave), with Laravel and Valet.
phpinfo():
PHP Version 7.2.13
Configuration File (php.ini) Path /usr/local/etc/php/7.2
Loaded Configuration File /usr/local/etc/php/7.2/php.ini
Scan this dir for additional .ini files /usr/local/etc/php/7.2/conf.d
While in my terminal, it shows:
php -v
PHP 7.3.0 (cli) (built: Dec 7 2018 11:00:11) ( NTS )
Now, if I do a which php I get this:
/usr/local/bin/php
In my ~/.bash-profile, I have this:
export "PATH=~/.composer/vendor/bin:$PATH"
I have tried to:
Restart Nginx
Restart Valet
Unlink PHP#7.2 and link PHP#7.3with Homebrew:
Olivers-MacBook-Air:~ oliverbusk$ brew unlink php#7.2
Error: No such keg: /usr/local/Cellar/php#7.2
How can I get my actual valet site to use php#7.3?
Below simple fix worked for me.
rm ~/.config/valet/valet.sock
valet restart
In my case it worked after forcing the specific PHP version:
valet use php#7.4 --force
Good news, please upgrade to latest valet version, you can easily switch php version.
Source: https://laravel.com/docs/5.8/valet
PHP Versions
Valet allows you to switch PHP versions using the valet use php#version command. Valet will install the specified PHP version via Brew if it is not already installed:
valet use php#7.2
valet use php //without any specification, it will be using latest version
Something so basic as rebooting my Macbook solved this issue. Once rebooted, the correct version 7.3 showed in my phpinfo();
From MacBook pro (Mojave), with Laravel and Valet:
valet use php#7.2
To be able to effectively change the version of php on my machine I use the following script:
Add to your user's .bash_profile
Then use the following command to switch
switch-php7.x
switch-php() {
valet stop
brew unlink php#7.2 php#7.3 php#7.4
brew link --force --overwrite php#$1
brew services restart php#$1
composer global update
rm -f ~/.config/valet/valet.sock
valet install
}
https://gist.github.com/r1tt3r/e0f199eb274d5ff186b73956af594316
I am running linux valet on Ubuntu 20.04 , The following command works for me
valet use 8.0
Here, 8.0 refers to the php version.
NB: Tested this solution on Ubuntu 20.04 Desktop
If you are using Valet Linux Plus(Has more features than Valet Linux) Just do valet use {your PHP version} --update-cli. For instance to use php8.0 just run:
valet use 8.0 --update-cli
This will update both php-fpm version plus php-cli version too.
Basically the php valet uses and the one used by your macbook is different.
But as already mentioned by #Shiro and #Israel Alexis Palma Quezada, in newer versions valet use php73 would solve your problem.
If it's not working, try running composer global update to update your global packages, thus updating valet
To update the mac php version, execute the following lines:
export PATH="your/path/to/php#7.3/bin:$PATH"
export PATH="your/path/to/php#7.3/sbin:$PATH"
or simply add these two lines to your ~/.profile or ~/.bash_profile
Don't forget to run source ~/.profile or source ~/.bash_profile or whatever file you chose to edit.
Yesterday I encountered the same problem on Ubuntu 18.
At first I changed the PHP version:
$ sudo a2dismod php7.2
$ sudo a2enmod php7.3
$ sudo update-alternatives --set php /usr/bin/7.3
But valet was still showing the wrong PHP version. Rebooting did not work. In fact, phpinfo() was displaying PHP 7.1.
After run ps -aux | grep php I noticed few instances of php-fpm (5.6, 7.1 and 7.2) running.
I stopped them
$ sudo service php5.6-fpm stop
$ sudo service php7.1-fpm stop
$ sudo service php7.2-fpm stop
Then started 7.3
$ sudo service php7.3-fpm start
And now my phpinfo() display the correct version of PHP
I ran into this same problem while using valet plus today. When I switched PHP versions it was showing the previous one in my browser but the correct one in my terminal. Looking at the my brew services list:
brew services list
It showed that one of the valet-php services (valet-php#7.2) was not in the service list but somehow my valet was able to switch to it. Valet didn't install this PHP properly and that's what was causing the issue. I did the following to uninstall that PHP and reinstall it with brew.
brew uninstall valet-php#7.2
sudo rm -rf /usr/local/Cellar/valet-php#7.2/7.2.34_1
brew install valet-php#7.2
The PHP version that was once not showing in the brew services list now showed and I was able to "stop" that php version's service:
brew services stop valet-php#7.2
which made everything work properly again without a restart.

Apache and Terminal runs 2 different php builds, on Mac OS 10.8

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.

Enabling PostgreSQL support in PHP on Mac OS X

I'm having a terribly difficult time getting the command "pg_connect()" to work properly on my Mac. I'm currently writing a PHP script (to be executed from console) to read a PostgreSQL database and email a report.
I've gone into my php.ini file and added
extension=pgsql.so
But, I'm met with the following error.
PHP Warning: PHP Startup: Unable to load dynamic library '/usr/lib/php/extensions/no-debug-non-zts-20090626/php_pgsql.so' - dlopen(/usr/lib/php/extensions/no-debug-non-zts-20090626/php_pgsql.so, 9): image not found in Unknown on line 0
PHP Fatal error: Call to undefined function pg_connect() in... (blah file here)
When running phpinfo(), I see nothing about PostgreSQL, so what is my issue here?
The PHP version that comes bundled with OS X doesn't include PostgreSQL. You'll have to compile the extension yourself. Here are some instructions:
Find your version of PHP: php -v.
Download the version of PHP that matches yours: curl -O http://us.php.net/distributions/php-5.3.3.tar.gz. (This example downloads PHP 5.3.3 but this must match your version)
Extract the archive you downloaded: tar -xzvf php-5.3.3.tar.gz
Change to the PostgreSQL's extension directory: cd php-5.3.3/ext/pgsql/
Type phpize.
Type ./configure.
Type make.
Type sudo make install.
Add the extension to you php.ini file by adding extension=pgsql.so. (You may already have done this)
Restart Apache.
Update for OS X Mountain Lion
Apple has removed autoconf from the newer versions of XCode so the procedure above will fail at #5. To solve that problem:
Type /usr/bin/ruby -e "$(/usr/bin/curl -fksSL https://raw.github.com/mxcl/homebrew/master/Library/Contributions/install_homebrew.rb)".
Type sudo chown -R $USER /usr/local/Cellar.
Type brew update.
Type brew install autoconf.
That should install autoconf and allow you to install the module using the instructions above.
If you use home brew, you can solve this with a command as simple as:
brew install php55-pdo-pgsql
for other php version, search with:
brew search pgsql
This worked for me with OSX 10.9.4 «Mavericks»
Install sources
Download the PHP source code. Unlike on Mountain Lion, you don’t get any headers preinstalled to link against so need to put it in /usr/include/php. Mavericks ships with PHP 5.4.17, but the latest 5.4.x source from php.net should do:
tar -jxvf php-5.4.20.tar.bz2
sudo mkdir -p /usr/include
sudo mv php-5.4.20 /usr/include/php
Configure PHP
cd /usr/include/php
./configure --without-iconv
sudo cp /etc/php.ini.default /etc/php.ini
Building a module
I needed the pdo_pgsql module - the same pattern should apply to just about any module assuming you have the necessary dependencies installed:
cd ext/pdo_pgsql
In my case I had the following error:
Cannot find autoconf. Please check your autoconf installation and the
$PHP_AUTOCONF environment variable. Then, rerun this script. ERROR:
`phpize' failed
So I had to use this command:
brew install autoconf
Then:
phpize
After that I tried to do:
./configure
but I had the next problem:
checking for pg_config... not found configure: error: Cannot find
libpq-fe.h. Please specify correct PostgreSQL installation path
So the solution was to specify correct PostgreSQL installation path:
./configure --with-pdo-pgsql=/Library/PostgreSQL/9.3/
make
sudo make install
That copies pdo_pgsql.so to /usr/lib/php/extensions/no-debug-non-zts-20100525.
Then simply add
extension=pdo_pgsql.so to /etc/php.ini
Run php -m to confirm everything went to plan.
For those who installed php7/ngix/postgres with homebrew
You can install the PostgreSQL module with:
brew install php70-pdo-pgsql
After that, you have to restart the php service:
brew services restart php70
OS X El Capitan users can simply upgrade their version of PHP 5.6. This is a one liner that will do that.
curl -s http://php-osx.liip.ch/install.sh | bash -s 5.6
For php56 via brew:
brew install php56-pdo-pgsql
PostgreSQL by default is installed in a unusual place on MAC OS X:
/Library/PostgreSQL/9.3
Given the location above you can type this:
./configure --with-pgsql=/Library/PostgreSQL/9.3
I killed the whole day trying to make it work on El Capitan after I made an upgrade yesterday and it turned out that I forgot to modify httpd.conf and change the path from the default php module (version 5.5.27) to the one I installed (version 5.6.14). This should be done in httpd.conf by modifying your default LoadModule php5_module path to LoadModule php5_module /usr/local/opt/php56/libexec/apache2/libphp5.so.
Just decided to leave it here as the potential solution for those who upgrade their OS or just the PHP version and face the same problem.
For those of you having openssl error while make here is the solution
OSX uses openssl 0.98 while installer is searching for 1.0.0
refer this link for instructions
psycopg2 installation error - Library not loaded: libssl.dylib
I downloaded PostgreSQL for Mac, and used the stack builder after installation to standup the entire EnterpriseDB Apache/PHP stack end-to-end. I mention this as a possible time saving option, probably not ideal for all situations. Should work OK if the apache and postgres shipped with Mac OS X were never started.
To keep existing apache hosted applications (i.e. pre-PostgreSQL install legacy) stable, I would just install the newer EnterpriseDB apache on port 81 (stackbuilder will prompt for new port if legacy apache instance is already running). Then, use mod_proxy in httpd.conf for the apache running on port 80 to provide seamless user experience to applications hosted on PostgreSQL.

How do I upgrade PHP in Mac OS X?

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

Categories