PHP not working on Apple OS X(10.10.3) - php

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

Related

PHP not running on MacOS Monterey 12.4

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

C:/Apache24/conf/httpd.conf: Cannot load c:/php7/php7apache2.dll into server: The specified module could not be found

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

Unable to get php to work in /home/user/public_html

I am configuring my own web server in AWS AMI Linux. I configured httpd to run in /home/user/public_html but PHP won't work in it. May I know what are the configurations to any conf files or php.ini which I need to change?
I installed php5.6 and apache2.4 on AWS Linux AMI. I can run php -v and it shows
PHP 5.6.32 (cli) (built: Nov 13 2017 22:50:59)
Copyright (c) 1997-2016 The PHP Group
Zend Engine v2.6.0, Copyright (c) 1998-2016 Zend Technologies
I got it running in /var/www/html but when I changed the httpd.conf to use /home/user/public_html, PHP does not work. The .php files shows
<?php ....some php code.... ?>
The fact it is showing the code and not running the code means you have not loaded the PHP module into apache or you have not associated the .php extension with the module.
The lines you need to look for in your httpd.conf are things like:
AddType application/x-httpd-php .php
LoadModule php5_module modules/libphp5.so
Note that AddType sets up the association of .php with the mime type x-hhtpd-php which is what the module then looks to handle. Also note that they LoadModule can supply a complete path but usually on Lunix/Unix these modules would be installed under the Apache installation path in the modules directory (look for all the .so files that appear in LoadModule commands inside httpd.conf).

php version from function "phpinfo()" is inconsistent with the output from "which php" command

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 in Mac OS X : Shows up the PHP code when opening the page

PHP Source Code is being shown up when opening PHP page in my localhost. This looks strange to me. I'm using using PHP 5.3.1 on Mac OS X Snow Leopard.
$ php --version
PHP 5.3.1 (cli) (built: Feb 28 2010 15:02:51)
Copyright (c) 1997-2009 The PHP Group
Zend Engine v2.3.0, Copyright (c) 1998-2009 Zend Technologies
I'm running the default httpd webserver on my machine. The /etc/apache2/httpd.conf file has the following line to load php module:
LoadModule php5_module libexec/apache2/libphp5.so
The httpd.conf file Syntax is OK.
$ httpd -t
Syntax OK
am I missing something? Please suggest!
Thanks!
You need to add AddType to your server config:
AddType x-httpd-php .php
This can be added to the httpd.conf file, or even in an .htaccess file.
For OS X Yosemite 10.10 need to add:
AddType application/x-httpd-php .php
One possible reason why this is happening to you is because you're using short PHP tags <? instead of <?php
Either change that in all php files that are included or simply allow short PHP tags by adding short_open_tag=On in php.ini and then restart your apache server.

Categories