I've installed an updated version of PHP 7.4 using homebrew.
But still, when i run php -v on the command line, i get :
WARNING: PHP is not recommended
PHP is included in macOS for compatibility with legacy software.
Future versions of macOS will not include PHP.
PHP 7.3.24-(to be removed in future macOS) (cli) (built: Dec 21 2020 21:33:25) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.3.24, Copyright (c) 1998-2018 Zend Technologies
As you can see, it's still using the one that comes with Mac Os.
When i run phpinfo from a php script, i can see it's using the correct one, as i configured on Apache, as shown below.
What i need to do to make the command line use the brew installed version of PHP ?
After installing a package, Homebrew shows you some helpful information you have to notice that information.
Anyway, you can access that information after that, by running below command.
brew info php#7.4
If you notice there is a Caveats section like below, it contains some configurations you have to do manually.
==> Caveats
To enable PHP in Apache add the following to httpd.conf and restart Apache:
LoadModule php7_module /usr/local/opt/php#7.4/lib/httpd/modules/libphp7.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/
php#7.4 is keg-only, which means it was not symlinked into /usr/local,
because this is an alternate version of another formula.
If you need to have php#7.4 first in your PATH, run:
echo 'export PATH="/usr/local/opt/php#7.4/bin:$PATH"' >> ~/.zshrc
echo 'export PATH="/usr/local/opt/php#7.4/sbin:$PATH"' >> ~/.zshrc
For compilers to find php#7.4 you may need to set:
export LDFLAGS="-L/usr/local/opt/php#7.4/lib"
export CPPFLAGS="-I/usr/local/opt/php#7.4/include"
To restart php#7.4 after an upgrade:
brew services restart php#7.4
Or, if you don't want/need a background service you can just run:
/usr/local/opt/php#7.4/sbin/php-fpm --nodaemonize
In your case, you have to add bellow lines to your shell runcom file by runing these commands in your terminal, if you using Zsh it whould be ~/.zshrc if you are using Bash, it would be ~/.bashrc.
echo 'export PATH="/usr/local/opt/php#7.4/bin:$PATH"' >> path/to/runcom/file
echo 'export PATH="/usr/local/opt/php#7.4/sbin:$PATH"' >> path/to/runcom/file
This would add your PHP installed by Hombrew in the path, and prefer it over macOS bundled PHP.
Related
I recently switched from Linux/Ubuntu to Mac. I Installed Apache2 and PHP 8 using homebrew on my MacOS Monterey 12.4 which came preinstalled with my MacBook Pro (M1). I have successfully configured the Apache and it is working perfectly as I am able to access my localhost. I have even changed the document root from its default location to my customized location (in my home directory)
After Successfully installing apache I installed php. I verified this by running the following commands
isthakur#Inders-MacBook-Pro apache2 % php -v
PHP 8.1.6 (cli) (built: May 12 2022 23:30:39) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.1.6, Copyright (c) Zend Technologies
with Zend OPcache v8.1.6, Copyright (c), by Zend Technologies
PHP is installed on following location /opt/homebrew/bin/php
but I am unable to get output on browser I have created a php file on my document root with following codes and named it test.php
<?php
phpinfo();
?>
When I try to open this file through browser (http://localhost/test.php) the codes are displayed on browser which means that server is not processing PHP.
Any kind of help is welcome and I thank everyone in anticipation.
Regards
after reading blogs and responses online I found that MacOS comes preinstalled with apache and even php was pre installed prior to MacOS Monterey (12) So I reset my Mac and found that apache is preinstalled and I just need to run it using following command
sudo apachectl start
and I can access apache. Since PHP was not installed I need to install it using homebrew. after installing the php I saw that I need to modify my https.conf file as following.
To enable PHP in Apache add the following to httpd.conf and restart Apache:
LoadModule php_module /opt/homebrew/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:
/opt/homebrew/etc/php/8.1/
To restart php after an upgrade:
brew services restart php
Or, if you don't want/need a background service you can just run:
/opt/homebrew/opt/php/sbin/php-fpm --nodaemonize
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.
I am using this guide to get php running now that I've updated to Catalina:
https://getgrav.org/blog/macos-catalina-apache-multiple-php-versions
I got all the way to the PHP portion and things went sideways. I used
$ brew install php#7.3
$ brew install php#7.4
and the installs went fine but when I ran
php -v
I got what must be some old install:
PHP 7.3.11 (cli) (built: Apr 17 2020 19:14:14) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.3.11, Copyright (c) 1998-2018 Zend Technologies
When I run
which php
I get
/usr/bin/php
Which is definitely not the right one. In my httpd.conf I have it pointing to the one given to me by brew like this:
LoadModule php7_module /usr/local/opt/php/lib/httpd/modules/libphp7.so
I also have all the other requisites (afaik) like these in my httpd.conf as well:
<IfModule dir_module>
DirectoryIndex index.php index.html
</IfModule>
<FilesMatch \.php$>
SetHandler application/x-httpd-php
</FilesMatch>
When I add the info.php file like the guide says and go to http://localhost/info.php I just get the plain text "echo " ~/Sites/info.php" and not the actual PHP info page so I know it's not working. Any idea how I can get it to use the right PHP? Any help is appreciated! Thanks!
I have installed Phalcon on my vServer and it seems to be loaded,
but if I try to run website I get an error
PHP Fatal error: Class 'Phalcon\\Config\\Adapter\\Ini' not found in /home...
php -v
PHP 5.6.10 (cli) (built: Jun 11 2015 08:33:51)
Copyright (c) 1997-2015 The PHP Group
Zend Engine v2.6.0, Copyright (c) 1998-2015 Zend Technologies
I followed the instructions on Phalcon website.
If I list php modules using php -m Phalcon is listed, I don't have
any errors, just don't know why it's not working!
Also, Phalcon is not listed on phpinfo(); page.
looks like you changed the config for the php console client but that config is not the same for the php module in apache.
Review what config is being loaded for apache module
When installing phalcon in order to get the extension working make sure to restart nginx / apache2, and if you are running PHP as a module php5-fpm service as well.
$ sudo service nginx restart
$ sudo service php5-fpm restart
I encountered the same problem and the reason is that I recompiled php with source code but not recompiled phalcon again after that. I solved that by compiling phalcon again with the correct phpize.
Sometimes when phalcon is installed, it creates a separate .ini file for itself and adds the extension therein. This is common in mac and linux OS. In such situation, type php --ini on the terminal. You should see an out put similar to the following...
Configuration File (php.ini) Path: /usr/local/etc/php/5.6
Loaded Configuration File: /usr/local/etc/php/5.6/php.ini
Scan for additional .ini files in: /usr/local/etc/php/5.6/conf.d
Additional .ini files parsed: /usr/local/etc/php/5.6/conf.d/ext-mongodb.ini,
/usr/local/etc/php/5.6/conf.d/ext-phalcon.ini
As you can see, phalcon created the /usr/local/etc/php/5.6/conf.d/ext-phalcon.ini file.
SOLUTION:
Open the file using sudo nano /usr/local/etc/php/5.6/conf.d/ext-phalcon.ini, copy the line in which the extension is loaded and paste in /usr/local/etc/php/5.6/php.ini if you are using XAMPP, copy the line to /Applications/XAMPP/xamppfiles/etc/php.ini Restart your server and check if that works.
I was upgrading my distro, from kali(wheezy) to sid. But when I was setting up my web server, I reinstalled all over, apache2, php, mysql etc., but I get this error when I access localhost/phpmyadmin: that URL is not showing an index / login page of phpmyadmin, but showing the code. In my /var/www the default is index.html, I renamed it to index.php, and it's ok, page is loaded, I do the same with my other directory in /var/www I added index.php or foo.php and access it, no problem, but when I enter phpmyadmin it's showing code. I tried installing phpminiadmin and adminer, but I get the same error, both are showing the code and not the web page.
Here is my apache2.conf
http://pastebin.com/MLYNQc6S
And here is my spec :
#php -v
PHP 5.5.7-2 (cli) (built: Dec 13 2013 00:25:07)
Copyright (c) 1997-2013 The PHP Group
Zend Engine v2.5.0, Copyright (c) 1998-2013 Zend Technologies
with Zend OPcache v7.0.3-dev, Copyright (c) 1999-2013, by Zend Technologies
with Xdebug v2.2.3, Copyright (c) 2002-2013, by Derick Rethans
# mysql --version
mysql Ver 14.14 Distrib 5.5.33, for debian-linux-gnu (i686) using readline 6.2
# apache2 -v
Server version: Apache/2.4.6 (Debian)
Server built: Aug 12 2013 18:20:23
uname -a
Linux angga.id 3.7-trunk-686-pae #1 SMP Debian 3.7.2-0+kali8 i686 GNU/Linux
and no error found in my /var/log/apache2/*log
I found this Localhost/phpmyadmin/ returns php code but didnt help.
so whats wrong with my server ?
EDIT 1 :
Like #Matt said in first comment. libapache2-mod-php5 is not installed, so I installing it with apt-get from repo.
apt-get install libapache2-mod-php5
but its return an error, like this.
dpkg: error processing libapache2-mod-php5 (--configure):
subprocess installed post-installation script returned error exit status 1
Errors were encountered while processing:
libapache2-mod-php5
E: Sub-process /usr/bin/dpkg returned an error code (1)
I open synaptic and search for libapache2-mod-php5 there are showing two package with that name libapache2-mod-php5filter and libapache2-mod-php5 , I check it all, and install it, success, no error found,
i restart apache2 and go to localhost/phpmyadmin and its work.
thanks for matt.
Try this
sudo apt-get install libapache2-mod-php7.0
This installs the library for apache2 to use php7.0
please check below things, have found for you from some diff links:
1. Make sure that PHP is installed. This sounds silly, but you never
know.
2. Make sure that the PHP module is listed and uncommented inside of your Apache's httpd.conf This should be something like
LoadModule php5_module "c:/php/php5apache2_2.dll" in the file.
Search for LoadModule php, and make sure that there is no comment
(;) in front of it.
3. Make sure that the http.conf file has the PHP MIME type in it. This should be something like AddType application/x-httpd-php
.php. This tells Apache to run .php files as PHP. Search for
AddType, and then make sure there is an entry for PHP, and that
it is uncommented.
4. Make sure your file has the .php extension on it, otherwise it will not be executed as PHP.
5. Make sure you are not using short tags in the PHP file (<?), these are deprecated, and usually disabled. Use <?php instead.
Actually run your file over said webserver using an URL like http://localhost/file.php not via local access
file://localhost/www/file.php
Or check http://php.net/install
thanks
I had the same problem with Debian 10 (buster) and PHP 7.3.19.1 and apache2 version 2.4.38 and phpmyadmin 5.02.
The file usr/share/phpmyadmin/index.php was not interpreted.
After verifying all the manual installation I ran the following commands:
apt-get update
apt-get install libapache2-mod-php7.3
systemctl restart apache2
and finally it worked. The module PHP for apache2 was not available.
sudo apt install php libapache2-mod-php
sudo apt install php7.0-mbstring
sudo a2dismod mpm_event
sudo a2enmod mpm_prefork
service apache2 restart
after that
gedit /etc/apache2/apache2.conf
add the following line
Include /etc/phpmyadmin/apache.conf
service apache2 restart
libapache2-mod-php server-side, HTML-embedded scripting language (Apache 2 module) so we have to add this
In my case this was due to that I installed apache2 after the fact and then proper php mods hadn't been linked and thus activated. What you need to do:
cd /etc/apache2/mods-enabled
sudo ln -s ../mods-available/php7.2.conf
sudo ln -s ../mods-available/php7.2.load
Then you just do a restart of the server by executing the following command:
sudo systemctl restart apache2
If all other PHP pages are working fine, then this is probably not a PHP related issue.
Since only the phpmyadmin login page is showing php code rather than the actual login page, chances are that your symbolic link in your apache web root directory /var/www/html/phpmyadmin is referencing the phpmyadmin index file /usr/share/phpmyadmin/index.php instead of the phpmyadmin directory /usr/share/phpmyadmin.
This is an incorrect symlink:
$ ll /var/www/html
lrwxrwxrwx 1 root root timestamp phpmyadmin -> /usr/share/phpmyadmin/index.php
This is a correct symlink:
$ ll /var/www/html
lrwxrwxrwx 1 root root timestamp phpmyadmin -> /usr/share/phpmyadmin/
If the symlink is incorrect, change it:
$ sudo ln -sfn /usr/share/phpmyadmin /var/www/html/phpmyadmin
(Or instead delete it and recreate it:)
$ sudo unlink /var/www/html/phpmyadmin
$ sudo ln -s /usr/share/phpmyadmin /var/www/html/phpmyadmin