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
Related
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
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).
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.
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