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!
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
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.
I am new apache and php. I installed Apache server in C drive, C:\Apache24. then I installed the services in CMD using this command
httpd -k install. then I go to Windows Service. I can start and stop Apache2.4, it is working fine. I want to run php project. Now I installed php in C:\php7.
PHP version:
PHP 7.3.0RC3 (cli) (built: Oct 10 2018 01:23:45) ( NTS MSVC15 (Visual C++ 2017) x64 ),
Copyright (c) 1997-2018, The PHP Group
Zend Engine v3.3.0-dev, Copyright (c) 1998-2018 Zend Technologies
Then I open Apache httpd.conf file (C:/Apache24/conf/httpd.conf).
PHPIniDir "C:/php7"
AddHandler application/x-httpd-php .php
LoadModule php7_module "C:/php7/php7apache2_4.dll" [this is line no 550]
I added the above line in httpd.conf. Then start Apache with this command httpd -k start or another I can start it in Windows Services.
Thus, I am getting this error. Why I do not know.
C:\Apache24\bin>httpd -k start
httpd: Syntax error on line 550 of C:/Apache24/conf/httpd.conf: Cannot load c:/php7/php7apache2.dll into server: The specified module could not be found.
I figured it out myself. I installed thread safe version. Please do not install non thread safe version.
The thread safe version is VC15 x64 Thread Safe (2018-Oct-10 19:19:47)
I added this line in Apache httpd.conf file.
AddHandler application/x-httpd-php .php
AddType application/x-httpd-php .php .html
LoadModule php7_module "c:/php730rc3/php7apache2_4.dll"
PHPIniDir "c:/php730rc3"
I got this error too, after confirming this module exist in /modules/, I checked the httpd.conf and found that the SRVROOT was wrong.
Define SRVROOT "D:/Project/Apache24/bin" //wrong
Define SRVROOT "D:/Project/Apache24" //correct
You must have access cmd like administrator. I supposed that you have changed also httpd.conf and you have modify ${SRVROOT}.. with C:/localhost ( you must have folder localhost in C). ANd install thread safe version
Mac OSX preinstalled php version is 5.5.38, I have installed another version which is 7.0.14
I get php version from web page which is called phpinfo(), it shows 5.5.38
However, I open command window ,and I type the command below:
MacBook-AIR-Jerry:local sooglejay$ which php
/usr/local/bin/php
MacBook-AIR-Jerry:local sooglejay$ /usr/local/bin/php -v
PHP 7.0.14 (cli) (built: Dec 8 2016 23:34:17) ( NTS )
Copyright (c) 1997-2016 The PHP Group
Zend Engine v3.0.0, Copyright (c) 1998-2016 Zend Technologies
I know , the web page which is called phpinfo(), is powered by php5.5.38, which is the builded php version in my mac osx, and I also see apache http-conf, which reveals that apache loads libphp5.so
LoadModule php5_module libexec/apache2/libphp5.so
question is : How can I let apache know that, hey man, php versioin is 7 not 5 ?
Try this:
LoadModule php7_module libexec/apache2/libphp7.so
you should change libexec/apache2/libphp7.so to real path on your system.(might look like /usr/local/opt/php71/libexec/apache2/libphp7.so)
You probably have both versions installed. this is a good resource - even though it's on windows it tells you the configurations you need to change.
Look for Apache24\conf\httpd.conf and search for lines similar to these (you found 1!):
AddHandler application/x-httpd-php .php
AddType application/x-httpd-php .php .html
LoadModule php7_module "path/to/php7/php7apache2_4.dll"
PHPIniDir "c:/php7"
You will have these with php5, except maybe the first two which would be similar/same. Change the versions as needed.
php -v returns
PHP 5.5.20 (cli) (built: Feb 25 2015 23:30:53)
Copyright (c) 1997-2014 The PHP Group
Zend Engine v2.5.0, Copyright (c) 1998-2014 Zend Technologies
I had PHP working a few days ago. Today I have not been able to get it to work. I noticed in the httpd.conf file that the PHP module had been commented out. I removed the # and restarted Apache and still nothing. Apache seems to be running and MySQL also seems to be working fine.
What would have made changes to my httpd.conf file?
What can I do to get it working again?
If you are using a package like MAMP; MAMP will overwrite the default configuration files with its own.
First, verify the LoadModule directive for PHP in the apache configuration is pointing to the correct path. Next, try to confirm Apache has loaded the PHP module:
# apache2ctl –M
After you've verified Apache has loaded mod_php5, bring up your PHP file in a browser. Check the file is named with the .php extension, and that this extension is associated with an Apache handler in your httpd.conf:
AddHandler application/x-httpd-php .php
If you're still seeing nothing, check your Apache error log:
# tail -f /var/log/apache2/error_log