On Centos 7 I have installed HTTPD and PHP5.4 (I know it's old, but a package I am using needs PHP 5.4)
[root#devserver sites-enabled]# cat /etc/redhat-release
CentOS Linux release 7.5.1804 (Core)
[root#devserver sites-enabled]# httpd -v
Server version: Apache/2.4.6 (CentOS)
Server built: Jun 27 2018 13:48:59
[root#devserver sites-enabled]# php -v
PHP 5.4.16 (cli) (built: Apr 12 2018 19:02:01)
Copyright (c) 1997-2013 The PHP Group
Zend Engine v2.4.0, Copyright (c) 1998-2013 Zend Technologies
Apache runs fine and shows that php5 is loaded:
[root#devserver sites-enabled]# httpd -M | grep php
php5_module (shared)
I have httpd.conf set up to load the module via the 10-php.conf
# PHP is an HTML-embedded scripting language which attempts to make it
# easy for developers to write dynamically generated webpages.
#
<IfModule prefork.c>
LoadModule php5_module modules/libphp5.so
</IfModule>
[root#devserver modules]# ls /etc/httpd/modules/ |grep php
libphp5.so
However, when I try to load a basic phpinfo page, I only see
<?php
phpinfo();
?>
Instead of http processing the php. /var/www/html/error.log and /etc/httpd/logs/error.log are both clean. Actually, they're totally empty.
Anybody have any ideas what could be going on?
Related
I have installed PHP with homebrew, switch to PHP 8.0 but the browser phpinfo() is showing 7.4. I am on the latest version of Monterey.
brew services stop httpd is stopping the apache service.
% php -v
PHP 8.0.19 (cli) (built: May 12 2022 02:25:19) ( NTS )
Copyright (c) The PHP Group
Zend Engine v4.0.19, Copyright (c) Zend Technologies
with Zend OPcache v8.0.19, Copyright (c), by Zend Technologies
% which php
/opt/homebrew/bin/php
How would I get PHP 8.0 to work in the browser?
in your httpd config, you must hardwire the shipped php version (7.4), with apache, would look like this :
LoadModule php7_module /usr/local/opt/php#7.4/lib/httpd/modules/libphp7.so
Just change the httpd config to load the appropriate lib, and restart your httpd server. Also, php has multiple configs (cli, fpm) : make certain that you tailor the appropriate one in your configs , typically found in /usr/local/etc/php/8.N (monterey, brewed-in php)
I following this link to upgrade my php from 5.6 to 7.2
and its successfully installed
PHP 7.2.14 (cli) (built: Jan 8 2019 12:06:12) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies
with Zend OPcache v7.2.14, Copyright (c) 1999-2018, by Zend Technologies
here my httpd
Server version: Apache/2.4.6 (CentOS)
Server built: Nov 5 2018 01:47:09
after trying to phpinfo() I got apache doesn't works. Its produce php code rather than compiling.
I check my httpd.conf, there are no LoadModule for php7Module. So I add LoadModule as bellow
LoadModule php7_module modules/libphp7.so
<FilesMatch \.php$>
SetHandler application/x-httpd-php
</FilesMatch>
and checking libphp7.so and guess what, there are no libphp7.so at modules directory.
However, I still figuring out what I miss. I install bellow dependencies
php72 php72-php-fpm php72-php-mysqlnd php72-php-opcache php72-php-xml
php72-php-xmlrpc php72-php-gd php72-php-mbstring php72-php-json
Ps. I running CentOS Linux release 7.6.1810 (Core)
Update 1
getsebool -a | egrep 'cgi|builtin_scriptin'
httpd_builtin_scripting --> on
httpd_enable_cgi --> on
I think that PHP isn't enabled in Apache. How to make it works?
Try to restart/start apache2
sudo systemctl restart httpd.service
If still issue persists, then
sudo systemctl status httpd.service
I am trying for days to enable php on my server. The web server is up, but php is not parsed.
First things first: the server is a CentOS 7 running apache2 and php 7.
Everythign seems to be correctly installed:
OS: uname -a
Linux rafiki 3.10.0-327.10.1.el7.x86_64 #1 SMP Tue Feb 16 17:03:50 UTC 2016 x86_64 x86_64 x86_64 GNU/Linux
and :cat /etc/redhat-release
CentOS Linux release 7.2.1511 (Core)
apache: httpd -v
Server version: Apache/2.4.6 (CentOS)
Server built: Jul 18 2016 15:30:14
PHP: php -v
PHP 7.0.10 (cli) (built: Aug 20 2016 07:47:25) ( NTS )
Copyright (c) 1997-2016 The PHP Group
Zend Engine v3.0.0, Copyright (c) 1998-2016 Zend Technologies
with Zend OPcache v7.0.10, Copyright (c) 1999-2016, by Zend Technologies
Then, in /etc/httpd/conf/httpd.conf there is this line:
Include conf.modules.d/*.conf
And in /etc/httpd/conf.modules.d/:
10-php.conf 00-base.conf 00-dav.conf 00-lua.conf 00-mpm.conf 00-proxy.conf 00-systemd.conf 01-cgi.conf
10-php.conf content:
<IfModule prefork.c>
LoadModule php7_module modules/libphp7.so
</IfModule>
<IfModule !prefork.c>
LoadModule php7_module modules/libphp7-zts.so
</IfModule>
Here is output for ls /etc/httpd/modules/ | grep php
libphp7.so
libphp7-zts.so
In /var/www/, there is a test.php file, which content is:
<?php phpinfo(); ?>
When I try http://[myserver.domain]/test.php, apache serves the raw file, without parsing php code.
I went through a lot of researches including StackOverflow, but none of the results had a solution working for me.
Can someone please help me to get php run properly? Is there something I am doing wrong ?
Solution:
As pointed out by #kyshel, a simple reboot worked.
Try rebooting the server (as others have already suggested). It worked for me.
I have an installation of Fedora20. I have the Apache server and php packages installed using yum. When i run the command line:
php -version i get:
[root#host ~]# php -version
PHP 5.5.20 (cli) (built: Dec 18 2014 05:55:32)
Copyright (c) 1997-2014 The PHP Group
Zend Engine v2.5.0, Copyright (c) 1998-2014 Zend Technologies
[root#host ~]#
however when i go to
http://host/phpinfo.php I get the following version:
PHP logo
PHP Version 5.5.10
I have run an md5 sum on libphp5.so and libphp5-zts.so.
[root#host modules]# md5sum libphp5.so
05687868a52f9f20960e8471fd10ebce libphp5.so
[root#host modules]# md5sum libphp5-zts.so
4a16156ba70db7e13cd6722618332c46 libphp5-zts.so
[root#host modules]#
I have compared them to an install that works fine and reports the version as the same for both apache and command line.
[root#host modules]# cd /etc/httpd/conf.modules.d/
[root#host conf.modules.d]# ls
00-base.conf 00-lua.conf 00-proxy.conf 00-systemd.conf 10-php.conf
00-dav.conf 00-mpm.conf 00-ssl.conf 01-cgi.conf README
[root#host conf.modules.d]# more 10-php.conf
#
# PHP is an HTML-embedded scripting language which attempts to make it
# easy for developers to write dynamically generated webpages.
#
<IfModule prefork.c>
LoadModule php5_module modules/libphp5.so
</IfModule>
<IfModule !prefork.c>
LoadModule php5_module modules/libphp5-zts.so
</IfModule>
[root#host conf.modules.d]#
I have the run yum update as well.
I am at a complete loss as to where to look next. What am I missing? Any help would be greatly appreciated.
Here is an update: ran yum info php-cli
[root#host ~]# yum info php-cli
Loaded plugins: langpacks, refresh-packagekit
Installed Packages
Name : php-cli
Arch : x86_64
Version : 5.5.20
Release : 2.fc20
Size : 13 M
Repo : installed
From repo : updates
Summary : Command-line interface for PHP
URL : http://www.php.net/
License : PHP and Zend and BSD
Description : The php-cli package contains the command-line interface
: executing PHP scripts, /usr/bin/php, and the CGI interface.
It appears to be 5.5.20
There is a yum package called php-cli which is different from the standard php package apache uses.
Try $ yum info php-cli and see what it says. You may need to uninstall that and force install the desired version.
I recently installed PHP54 on a RHEL 6.5 server from the RHN Software Collection 1.1
The package has successfully been installed, and it needs to be mentioned there is an existing previous installed PHP version (5.3.3) on the servers which is the current enabled version.
I have checked several sites/forums/blogs and the suggestions are always the same, enable via scl (Setup and run software from Software Collection environment) and/or sourcing the file "/opt/rh/php54/enable". This seems to be a proper workaround to enable PHP54 as can be seen in the commands below.
But it is not permanent, as soon as I exit the shell the user who enabled PHP the changes are discarded.
NOTE: the commands has been run as "root" with the exact same behaviour shown in the following commands.
I've found references to add the source workaround into the ".bash_profile" of the user(s), but does not seems to be the best solution for me, I am wondering if someone else have already faced this problem and how it was solved.
Any suggestions?
[mithrandir#mordor ~]# scl enable php54 "php -v"
PHP 5.4.16 (cli) (built: Feb 4 2014 08:10:51)
Copyright (c) 1997-2013 The PHP Group
Zend Engine v2.4.0, Copyright (c) 1998-2013 Zend Technologies
[mithrandir#mordor ~]# php -v
PHP 5.3.3 (cli) (built: Jul 15 2014 08:48:08)
Copyright (c) 1997-2010 The PHP Group
Zend Engine v2.3.0, Copyright (c) 1998-2010 Zend Technologies
[mithrandir#mordor ~]# source /opt/rh/php54/enable
[mithrandir#mordor ~]# php -v
PHP 5.4.16 (cli) (built: Feb 4 2014 08:10:51)
Copyright (c) 1997-2013 The PHP Group
Zend Engine v2.4.0, Copyright (c) 1998-2013 Zend Technologies
[mithrandir#mordor ~]# date
Fri Aug 29 12:29:35 MDT 2014
[mithrandir#mordor ~]# exit
logout
[me#mordor ~]$ sudo su -
[sudo] password for me:
[mithrandir#mordor ~]# php -v
PHP 5.3.3 (cli) (built: Jul 15 2014 08:48:08)
Copyright (c) 1997-2010 The PHP Group
Zend Engine v2.3.0, Copyright (c) 1998-2010 Zend Technologies
[mithrandir#mordor ~]# date
Fri Aug 29 12:29:57 MDT 2014
It seems that in order to enable a package from the RH Software Collection the only way is by adding a script under "/etc/profile.d" and including the "source /opt/rh/php54/enable" command.
This is a link to RH devs blog, showing the solution. Be aware that it is for python33 but this workaround applies for software included on RHSC such as PHP54.
Permanently Enable a Software Collection
I implemented the solution and it is working. I hope this helps someone else.
Open a command shell window and check the PHP rpm package which is installed.
# rpm -qa | grep php
There should be an Apache php module. You need to download a rpm file which adds PHP to your Apache web server.
Use the website http://blog.famillecollet.com/post/2013/06/16/Red-Hat-will-provide-PHP-5.4-for-RHEL-6.
Here you find the hints how to permanently install PHP 5.4.:
# source /opt/rh/php54/enable
# php -v
PHP 5.4.14 (cli) (built: May 23 2013 07:42:19)
Copyright (c) 1997-2013 The PHP Group
Zend Engine v2.4.0, Copyright (c) 1998-2013 Zend Technologies
If you want PHP 5.4 permanently enabled and your /etc/conf.d/ directory has the conf file for PHP 5.4 (possibly php54-php.conf) in it, you can comment out the lines in /etc/conf.d/php.conf that load the PHP 5.3 modules:
<IfModule prefork.c>
LoadModule php5_module modules/libphp5.so
</IfModule>
<IfModule worker.c>
LoadModule php5_module modules/libphp5-zts.so
</IfModule>
You can also delete /etc/conf.d/php.conf or rename the file to remove the .conf extension so that it isn't loaded by /etc/conf/httpd.conf. After doing either of these, restart Apache to load PHP 5.4.