Answer the question
In order to leave comments, you need to log in
How to change php 7.3 on Mac OS?
Hello! I enter the command php -v result:
HP 7.1.23 (cli) (built: Nov 27 2018 16:59:25) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.1.0, Copyright (c) 1998-2018 Zend Technologies
brew unlink php71
Error: No such keg: /usr/local/Cellar/[email protected]
/usr/bin/php
Answer the question
In order to leave comments, you need to log in
Open a terminal and run the command:
curl -s https://php-osx.liip.ch/install.sh | bash -s 7.3
The macOS security system may require you to enter a password to gain access to system files - enter it. Liip scripts for installing PHP do not contain malicious code.
In case you already have a newer version installed, this command may cause a warning about a fresh version of PHP already installed.
As a result of the script, an archive with PHP 7.3 files will be deployed in the user's directory, in my case, it was here:
/usr/local/php5-7.3.8-20190811-205217/
The end of the installation looked like this (pay attention to the path to the unpacked files ):
Setting PHP 7.3 to work from the terminal
To check the current version running in the terminal, run the
php -v command
. For composer to work, I had PHP 7.2.16 installed in the terminal. To set up a new version of PHP to run from the terminal, you need to add the following lines to the end of the file in ~/.bash_profile if you are using the bash terminal environment:
export PATH="/usr/local/php5-7.3.8-20190811-205217/bin :$PATH"
export PATH="/usr/local/php5-7.3.8-20190811-205217/sbin:$PATH"
The path to the installed version of PHP may differ from the one I specified. The current path for you is contained in the terminal where the new version was installed and the curl command was run. After saving changes to the .bash_profile file, new terminal sessions will use the version you specify. To update the version within the current terminal session, read the file again by calling:
source ~/.bash_profile
Now, when you call php -v in the terminal, you should see the latest version of PHP:
If there is no file ~/.bash_profile
If the file is ~/ .bash_profile is not created, then this can be done directly from the terminal using the command:
touch ~/.bash_profile
And then take it into editing by calling:
sublime ~/.bash_profile
If you are not configured to launch the sublime text editor from the console, then you can do this with the help of this article.
Setting up PHP 7.3 in the built-in Apache server in macOS
The Apache web server is preinstalled in the macOS operating system, which allows you to develop websites and fully configure yourself without installing LAMP, Apache via brew, etc. In order for the built-in Apache server to load the correct version of the PHP module, it should be specified in the configuration file. The configuration file is located at:
/private/etc/apache2/httpd.conf
In this file, find the line containing the word php. By default, it looks like this:
#LoadModule php7_module libexec/apache2/libphp7.so
You should remove # from it at the beginning so that this line is not commented out, and instead of libexec/apache2/libphp7.so write the full path to the libphp7.so file in the directory with the new version of PHP 7.3. In my case, the line looks like this:
LoadModule php7_module /usr/local/php5-7.3.8-20190811-205217/libphp7.so
Save the file, enter a password that confirms our rights to save the file in the system location. And then you need to restart the Apache server with the command:
sudo apachectl restart
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question