I have installed php7.2 using homebrew. But when i run php -v i still get php7.1. Of which i think it wasn't installed with Homebrew. How can i enable disable 7.1 and enable 7.2.
I have tried this as suggested by the install.
To enable PHP in Apache add the following to httpd.conf and restart Apache:
LoadModule php7_module /usr/local/opt/php#7.2/lib/httpd/modules/libphp7.so
<FilesMatch \.php$>
SetHandler application/x-httpd-php
</FilesMatch>
Finally, check DirectoryIndex includes index.php
DirectoryIndex index.php index.html
Also tried, uncommenting this line in /etc/apache2/httpd.conf
LoadModule php7_module libexec/apache2/libphp7.so
I have solved this by linking the new installed version.
After installing the new php version(7.2) with homebrew, you have to run
brew link php#72 --force
if your previous version was a installed with homebrew, you have to unlink it also. E.g for php 7.1
brew unlink php71
This is for the php CLI(command line), for the Apache PHP you need to edit /etc/apache2/httpd.conf
When you run php -v, you get the version of PHP that is executed from the command line, not the version of PHP executed from Apache.
If you run:
/usr/local/bin/php -version
You will have the version of the PHP installed by Homebrew. To set it as the default PHP interpreter from the command line, your PATH environment variable should contain /usr/local/bin/ before /usr/bin.
To check the version of PHP executed within Apache run phpinfo by browsing the following PHP file:
<?php
phpinfo();
Related
On my mac I've got php installed and working fine. I recently wanted to install mcrypt, so I did so using brew. Although it seemed to install fine, it doesn't show up in my phpinfo(). So I think that the php that brew installed mcrypt in, isn't the php that apache uses.
Does anybody know how I can:
check whether there is a difference between the php installed by brew and the php which Apache uses?
make apache use the php that brew installed?
All tips are welcome!
According to the contributors of the Homebrew php formula...
The contributors of the Homebrew php formula give the following instructions. The exact instructions reproduced here install php7.4. Substitute the php version you need.
(Avoid "special" ways of accomplishing your objective; they are often problematic. "Official" approaches are more likely to give you a predictable, maintainable setup.)
$ brew search php // since php can be installed by homebrew but be missing from your PATH, review the list of php versions available through homebrew; a checkmark next to a version indicates one is installed
$ brew install php#7.4
$ echo 'export PATH="/usr/local/opt/php#7.4/bin:$PATH"' >> ~/.zshrc // add the alias to your path (issues you are using zsh, the default now for macOS); see comments output during installation
$ source ~/.zshrc // reload . zshrc to use the new settings immediately
The contributors of the formula also provide the following instructions for enabling PHP in Apache:
To enable PHP in Apache add the following to httpd.conf and restart Apache:
LoadModule php_module /usr/local/opt/php/lib/httpd/modules/libphp.so
<FilesMatch \.php$>
SetHandler application/x-httpd-php
</FilesMatch>`
Finally, check DirectoryIndex includes index.php
DirectoryIndex index.php index.html
The php.ini and php-fpm.ini file can be found in:
/usr/local/etc/php/7.4/
These instructions for enabling PHP in Apache appear in stdout when you install php. Alternatively in Terminal use brew info php or visit the Homebrew PHP formula page
You have to make your Apache use the PHP that you just downloaded.
Open your httpd.conf (mine is at /etc/apache2/httpd.conf) and look for the line that loads the PHP module, something like:
LoadModule php5_module path/to/php
Then, make it point to the PHP that brew installed for you with mcrypt support. Mine was at this path. Yours can vary depending on the PHP version that you installed.
/usr/local/Cellar/php54/5.4.21/libexec/apache2/libphp5.so
Finally you will need to restart your Apache server to load the new configuration:
sudo apachectl restart
Can't comment on stackoverflow yet due to my lack of experience but to add to the above answer is correct. Just an additional comment to find the correct path:
run:
brew info php54
or which ever version u have installed and it will show you the path:
To enable PHP in Apache add the following to httpd.conf and restart Apache:
LoadModule php5_module /usr/local/opt/php54/libexec/apache2/libphp5.so
brew install php installs php 7.3 at the moment, versions below are keg-only
You can make aliases for versions below by adding this to:
~/.profile
alias php#5.6='$(brew --prefix php#5.6)/bin/php'
alias php#7.0='$(brew --prefix php#7.0)/bin/php'
alias php#7.1='$(brew --prefix php#7.1)/bin/php'
alias php#7.2='$(brew --prefix php#7.2)/bin/php'
~/.bashrc
source ~/.profile
~/.zshrc
[[ -e ~/.profile ]] && emulate sh -c 'source ~/.profile'
Then you can:
php#5.6 -v
php#7.0 -v
php#7.1 -v
php#7.2 -v
If you use composer and the platform php is not set in your project then this can be handy:
~/.profile
alias composer#5.6='php#5.6 $(which composer)'
alias composer#7.0='php#7.0 $(which composer)'
alias composer#7.1='php#7.1 $(which composer)'
alias composer#7.2='php#7.2 $(which composer)'
If you use artisan a lot (artisan maps to php which is 7.3) then this can be handy:
~/.profile
alias artisan#5.6='php#5.6 artisan'
alias artisan#7.0='php#7.0 artisan'
alias artisan#7.1='php#7.1 artisan'
alias artisan#7.2='php#7.2 artisan'
I would create an alias to it so you don't disturb the system PHP install.
brew info php71
Brew installs into /usr/local/Cellar so you can add the following to your ~/.bash_alias or ~/.profile.
alias php7='/usr/local/Cellar/php71/7.1.10_21/bin/php'
Try: brew link php71 --force to use brew specific php version.
It worked for me.
As of 2021, all you need is
brew install php
then
brew link php
This will give you php 8.0 and setup your symlinks.
when I run the command php -v
I have version 8.0
I would like to change the version to 7.4
despite I have installed php7.4
but I don't know how to switch between the two versions
thank you
Let's assume that the location of php7.4 is /usr/bin/php7.4, in which case
/usr/bin/php7.4 -v
will yield something like this:
hence, you can use this method for whatever command that you would like to execute:
/usr/bin/php7.4 <yourcommand>
You can disable PHP 8 via
sudo a2dismod php8.0
if it bothers you. You can do so temporarily as well.
As your question is about the Arch Linux and it doesn't have the a2enmod & a2dismod. I am gonna providing working answer in the arch:
I assume you have installed php7 & php8 and just want to make apache to use the version 7.
first uninstall apache-php module and install the right one.
sudo pacman -R php-apache
sudo pacman -S php7-apache
then in the /etc/httpd/conf/httpd.conf change the module name:
from :
LoadModule php_module modules/libphp.so
Include conf/extra/php_module.conf
AddHandler php-script php
to:
LoadModule php7_module modules/libphp7.so
Include conf/extra/php7_module.conf
AddHandler php7-script php
after that you can reload the server:
sudo systemctl reload httpd
Upgrading to 10.15.1 (19B88) Mac OS Catalina broke my PHP 7.3.9 development environment.
$zip = new \ZipArchive;
Yields Exception 'Error' with message 'Class 'ZipArchive' not found'
zip and unzip are installed at Terminal command line.
Trying to use PECL failed. Trying to use Homebrew failed.
Do you know how to properly install ZipArchive manually on MacOS?
I had the same problem and this is what helped me.
Basically what I did is I just installed php using brew and then linked the php that I have installed using brew inside of httd.conf file. Here are the steps:
Install php using home brew
brew install php#7.3
This will install php. Now we need to link it
brew link php#7.3
If the command above wont work because of the missing directories, then just create them using mkdir and run it again.
Link you php in httd.conf file
Open the httpd.conf file which is located here /private/etc/apache2/httpd.conf
Open it and change this line
LoadModule php7_module libexec/apache2/libphp7.so
to this:
LoadModule php7_module /usr/local/Cellar/php/7.3.11/lib/httpd/modules/libphp7.so
What this basically dow is it just makes apache to use php that is installed using homebrew. Hope this was helpful to you.
Here is a link where it is better described how to connect homebrew installed php:
How to use the php that brew installed?
What I did was the following,
brew install php#7.3
php version 7.3.19 was installed.
Then edited my httpd.conf using
sudo nano /private/etc/apache2/httpd.conf
The following line in http.conf
LoadModule php7_module libexec/apache2/libphp7.so
was replaced with
LoadModule php7_module /usr/local/opt/php#7.3/lib/httpd/modules/libphp7.so
Added the following to http.conf right after modules block
<FilesMatch \.php$>
SetHandler application/x-httpd-php
</FilesMatch>
In nano I searched for DirectoryIndex using ctrl+W
added index.php to finally make it
DirectoryIndex index.php index.html
Then I updated my PATH variable using
echo 'export PATH="/usr/local/opt/php#7.3/bin:$PATH"' >> /Users/<your user>/.bash_profile
echo 'export PATH="/usr/local/opt/php#7.3/sbin:$PATH"' >> /Users/<your user>/.bash_profile
Then I made a new directory sbin as following,
sudo mkdir /usr/local/sbin
Changed ownership to current user,
sudo chown -R $(whoami) /usr/local/sbin
Linked brew
brew link php#7.3 --force
Restarted Apache
sudo apachectl restart
Please Note: You do not have to probably do all of the steps or do it in same order, I only wanted to share what I did and worked for me.
I have php5.6 on yosemite via brew running on Apache, but yet my phpinfo file shows php5.5
I have updated the /private/etc/apache2/httpd.conf file load module to:
LoadModule php5_module /usr/local/opt/php56/libexec/apache2/libphp5.so
I have restarted apache. I have restarted the terminal after adding both:
export PATH="/usr/local/opt/php56/bin/:/usr/local/sbin:/usr/local/bin:$PATH"
export PATH="$(brew --prefix homebrew/php/php56)/bin:$PATH"
which php returns
/usr/local/opt/php56/bin/php
I have restarted the entire computer and when running a phpinfo file returns
PHP Version 5.5.20
I installed Homebrew and decided to upgrade php version to 5.5. Make it through the command:
brew install php55
All went well, and then I ordered a .bash_profile:
export PATH="$(brew --prefix homebrew/php/php55)/bin:/usr/local/bin:$PATH"
Next in the directory /Library/WebServer/Documents/ I created info.php file:
<?php phpinfo(); ?>
And opened it through the browser, but display the old version of php 5.4.30. How to enable php5.5 or delete old version php5.4.30? Help me!
I solved the problem, in the Apache configuration file nttpd.conf was need to set the path to the new version of php:
#LoadModule php5_module libexec/apache2/libphp5.so
LoadModule php5_module /usr/local/Cellar/php55/5.5.19/libexec/apache2/libphp5.so