Обновление php mac os

Upgrade to PHP 8.1 with Homebrew on Mac

Next, upgrade PHP. You can either use the built-in php recipe, but I recommend to use the shivammathur/homebrew-php tap.

# Normal upgrade

# Upgrade with shivammathur/homebrew-php

brew tap shivammathur/php brew install shivammathur/php/php@8.1

To switch between versions, use the following command:

brew link --overwrite --force php@8.1

# Next steps

Check the current version by running php -v :

Restart Nginx or Apache, if you’re using Laravel Valet you can skip to the next section; you need some extra steps in order for the web server to properly work.

And make sure that your local web server also uses PHP 8.1 by visiting this script:

# index.php, accessible to your web server phpinfo();

The version should show 8.1.x .

Noticed a tpyo? You can submit a PR to fix it. If you want to stay up to date about what’s happening on this blog, you can follow me on Twitter or subscribe to my newsletter:

# Valet

If you’re using Laravel Valet, you should do the following steps to upgrade it:

You can use valet use to switch between PHP versions:

valet use php@8.1 valet use php@8.0

# Extensions

PHP extensions are installed using pecl. I personally use Redis and Xdebug. They can be installed like so:

pecl install redis pecl install xdebug

You can run pecl list to see which extensions are installed:

pecl list # Installed packages, channel pecl.php.net: # ========================================= # Package Version State # redis 5.3.4 stable # xdebug 3.1.1 stable

You can search for other extensions using pecl search :

pecl search pdf # Retrieving data. 0% # .. # Matched packages, channel pecl.php.net: # ======================================= # Package Stable/(Latest) Local # pdflib 4.1.4 (stable) Creating PDF on the fly with the PDFlib library

Make sure to restart your web server after installing new packages:

Make sure all extensions are correctly installed and loaded by checking both your PHP webserver and CLI installs:

var_dump(extension_loaded('redis'));

If extensions aren’t properly loaded, there are two easy fixes.

First, make sure the extensions are added in the correct ini file. You can run php —ini to know which file is loaded:

Configuration File (php.ini) Path: /opt/homebrew/etc/php/8.1 Loaded Configuration File: /opt/homebrew/etc/php/8.1/php.ini Scan for additional .ini files in: /opt/homebrew/etc/php/8.1/conf.d Additional .ini files parsed: /opt/homebrew/etc/php/8.1/conf.d/error_log.ini, /opt/homebrew/etc/php/8.1/conf.d/ext-opcache.ini, /opt/homebrew/etc/php/8.1/conf.d/php-memory-limits.ini
extension="redis.so" zend_extension="xdebug.so"

Note that if you’re testing installed extensions via the CLI, you don’t need to restart nginx, apache or Valet when making changes to ini settings.

The second thing you can do, if you’re updating from an older PHP version which also used pecl to install extension; is to reinstall every extension individually.

pecl uninstall redis pecl install redis

# Last step

Finally you should test and upgrade your projects for PHP 8 compatibility.

Источник

Update PHP Version in Mac

Update PHP Version in Mac

In this tutorial, we will introduce some methods to update to the latest stable version of PHP. As of current, the latest stable version of PHP is PHP 8.

Use Homebrew to Update to PHP 8 in Mac

We can utilize the Homebrew package manager to upgrade the current PHP version to the latest version in Mac. Homebrew is an open-source package management system that manages the installation of software in Mac and Linux. The package manager lets the user install and update the software according to the user. Installing PHP and upgrading it to the latest version is simplified by the use of Homebrew. It is the easiest way to install and upgrade PHP in Mac. We can use the following command to check the current version of PHP.

If brew is not previously installed in your system, type the code below in the macOS terminal to install brew.

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)" 

After installing Homebrew, add it to the PATH using the following command.

echo "export PATH=/opt/homebrew/bin:$PATH" >> ~/.bash_profile source ~/.bash_profile 

To install PHP, we can use the command brew install php . After installing a fresh PHP, set PHP to PATH using the following command.

echo 'export PATH="/usr/local/opt/php8/bin:$PATH"' >> ~/.bash_profile source ~/.bash_profile 

To update the PHP version, update the brew using the command brew update . Then, use the command brew upgrade php . It upgrades the current version to the latest version of PHP. Then, restart the webserver to see the changes. Use the command sudo apachectl restart to restart the Apache server. If you use Nginx, use the command sudo nginx -s reload .

If we want to switch between PHP versions, we can use the following built-in command to update to PHP 8.

brew tap shivammathur/php brew install shivammathur/php/php@8.0 

It will allow us to switch back to the previous version of PHP. We can use the following command to switch the PHP versions.

brew link --overwrite --force php@8.0 

The command above will switch the current PHP version to PHP 8. If we want to switch back to the previous version, we can replace the version in the above command.

Thus, we can upgrade to the latest version of PHP using Homebrew.

Subodh is a proactive software engineer, specialized in fintech industry and a writer who loves to express his software development learnings and set of skills through blogs and articles.

Related Article — PHP Update

Источник

Update PHP on Mac OS X

If you are running macOS Mojave or higher, the recommended solutions in this tutorial may no longer work. For those reasons, I recommend following my latest tutorial on installing Apache, MySQL, and PHP on macOS using Docker.

As noted in my posts on installing Apache, PHP and MySQL on Mac OS X, Mac OS X comes pre-installed with Apache and PHP. Unfortunately, the pre-installed version of PHP with macOS is outdated:

  • Mac OS 10.11 (El Capitan) pre-installed with PHP 5.5
  • Mac OS 10.12 (Sierra) pre-installed with PHP 5.6
  • Mac OS 10.14 (Mojave) pre-installed with PHP 7.1
  • Mac OS 10.15 (Catalina) pre-installed with PHP 7.3

Many of these PHP versions are already end of life. In fact, macOS Mojave was the first time the pre-installed version was recent — although still not the latest PHP version.

So what do you do if you want to upgrade or install a different PHP version on your Mac? Well, you could use Homebrew. But I found a pre-packaged alternative — PHP OSX.

PHP OSX is a package installer for PHP versions 5.3 to 7.3 (current). It’s available for Mac OS 10.6+ (Snow Leopard to Mojave). While installing PHP OSX is just a few steps, I’ll walk you through each of them.

Installing PHP

First, choose the version of PHP you want to install. In this example, I’ll install PHP 7.2 as that is the latest stable version of PHP. However, if you want to install PHP 7.1 that is available as well.

 
curl -s http://php-osx.liip.ch/install.sh | bash -s 7.2

If you’re not comfortable executing scripts from the Internet, you can do the install by hand.

Configuring Apache

Provided you are using the pre-installed version of Apache, PHP OSX will add the /etc/apache2/other/+php-osx.conf configuration file which will automatically be loaded by Apache.

If you had previously enabled PHP (as I did), you’ll need to comment out the following line in /etc/apache2/httpd.conf :

 
1LoadModule php7_module /usr/local/php5/libphp7.so

If you are running an older version of Mac OS X, the line may be:

 
1LoadModule php5_module /usr/local/php5/libphp5.so

Updating your PATH

Although Apache will now run the new version of PHP, the command line will not. In order for the command line to use the new version of PHP you will need to update your PATH .

 
export PATH=/usr/local/php5/bin:$PATH

If you don’t want to run the command above every time you open a new terminal, you can update the PATH in your .bash_profile .

Configuring PHP

Finally, you will want to update some of the PHP configuration values. PHP OSX installs a PHP INI file for you to change. To edit this file, run:

 
sudo vi /usr/local/php5/php.d/99-liip-developer.ini

If you kept all of your local PHP configuration within a single INI file (as I did), you can simply append it to the PHP OSX file with:

 
sudo cat /Library/Server/Web/Config/php/local.ini >> /usr/local/php5/php.d/99-liip-developer.ini

Now you’ll just need to review your PHP code to ensure it’s compatible with your newly installed PHP version. And for that, I recommend PHP Shift.

Find this interesting? Let’s continue the conversation on Twitter.

Источник

Обновление до PHP 8.2 с помощью Homebrew на Mac

Обновление до PHP 8.2 с помощью Homebrew на Mac

Для начала убедитесь что brew установлен крайней версии:

Теперь уже можно переходить к обновлению PHP. Вы можете использовать встроенные средства PHP, но я рекомендую использовать tap shivammathur/homebrew-php

Стандартное обновление

Обновление с помощью shivammathur/homebrew-php

brew tap shivammathur/php brew install shivammathur/php/php@8.2 

Для переключения между версиями используйте следующую команду

brew link --overwrite --force php@8.2 

Хотите больше информации о homebrew — посетите следующий репозиторий

Следующие шаги

Проверьте текущую версию при помощи php -v

NGINX или Apache

ИспользуетеNGINX или Apache? То Вам необходимо перезапустить их (если вы используете Laravel Valet, то просто пропустите этот пункт и перейдите к следующему). Выполняем команды:

sudo nginx -s reload sudo apachectl restart 

И убедитесь, что ваш локальный веб сервер также использует PHP 8.2 прописав следующую команду:

# index.php, accessible to your web server phpinfo(); 

Valet

Если вы используете Laravel Valet, вам нужно выполнить следующие шаги для обновления:

Вы можете использовать valet use для переключения между версиями PHP

valet use php@8.2 valet use php@8.1 

Расширения

Расширения PHP устанавливаются с помощью pecl. Я лично использую Redis и Xdebug. Они могут быть установлены следующим образом:

pecl install redis pecl install xdebug 

Вы можете запустить команду pecl list, чтобы посмотреть какие расширения установлены.

# Installed packages, channel pecl.php.net:

Вы можете искать другие расширения используяpecl search

Убедитесь, что вы перезапустили свой веб сервер после установки каких-либо расширения.

sudo nginx -s reload sudo apachectl restart valet restart 

Убедитесь, что все расширения правильно установлены и загружены, проверив установки вашего веб-сервера PHP и CLI:

php -i | grep redis var_dump(extension_loaded('redis')); 

Если расширения загружены неправильно, есть два простых решения.

Во-первых, убедитесь, что расширения добавлены в правильный ini-файл. Вы можете запустить php —ini , чтобы узнать, какой файл загружен:

Configuration File (php.ini) Path: /opt/homebrew/etc/php/8.2

Loaded Configuration File: /opt/homebrew/etc/php/8.2/php.ini

Scan for additional .ini files in: /opt/homebrew/etc/php/8.2/conf.d

Additional .ini files parsed: /opt/homebrew/etc/php/8.2/conf.d/error_log.ini,

Теперь проверьте этот файл .ini

extension="redis.so" zend_extension="xdebug.so" 

Обратите внимание, что если вы тестируете установленные расширения через CLI, вам не нужно перезапускать nginx, apache или Valet при внесении изменений в настройки ini.

Второе, что вы можете сделать, если вы обновляетесь с более старой версии PHP, которая также использовала pecl для установки расширения; это переустановить каждое расширение по отдельности.

pecl uninstall redis pecl install redis 

Последний шаг

Наконец, вы должны протестировать и обновить свои проекты для совместимости с PHP 8.2.

Источник

Читайте также:  List string сортировка java
Оцените статью