PHP won't parse on Apache2 - CentOS 7 - php

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.

Related

Install PHP 7.2 on Centos 7

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

PHP won't process on new install

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?

Apache does not compile php

I just installed a fresh ubuntu system from here (mini.iso)
I choosed no extras at all during the installation process.
These are all the commands which I have executed this far:
(Ignore 4 - 8)
Now I wrote a simple PHP test script (/var/www/html/index.php)
<?php
echo "Hello World";
?>
However, after calling this page from another computer, I literally get the output from the file, instead of the compiled php.
Output:
<?php
echo "Hello World";
?>
I have already restarted apache2, no change.
Apache version:
Server version: Apache/2.4.7 (Ubuntu)
Server built: Jul 15 2016 15:32:47
PHP version:
PHP 7.0.16-4+deb.sury.org~trusty+1 (cli) (built: Mar 2 2017 13:50:00) ( NTS )
Copyright (c) 1997-2017 The PHP Group
Zend Engine v3.0.0, Copyright (c) 1998-2017 Zend Technologies
with Zend OPcache v7.0.16-4+deb.sury.org~trusty+1, Copyright (c) 1999-2017, by Zend Technologies
Linux version:
Linux linux 3.13.0-110-generic #157-Ubuntu SMP Mon Feb 20 11:55:25 UTC 2017 i686 i686 i686 GNU/Linux
I already searched the internet, some other user sayed to check if the PHP module is loaded by checking the file httpd.conf, but there is no such file. I searched it by using find / -name "httpd.conf" which gave no results.
You need to install PHP apache2 module to work with PHP. You can install libapache2-mod-php from your terminal by typing the command
sudo apt-get install libapache2-mod-php
After that restart your apache. It will solve your problem.

Apache; Invalid command 'DavLockDB'

Just learning about PHP and MySQL. Attempting to enable PHP on Mac Mini. I've followed several thread regarding this, but have not found a solution.
Terminal Output:
Jessicas-Mac-mini:~ jessicaclark$ php -v
PHP 5.5.14 (cli) (built: Sep 9 2014 19:09:25)
Copyright (c) 1997-2014 The PHP Group
Zend Engine v2.5.0, Copyright (c) 1998-2014 Zend Technologies
Jessicas-Mac-mini:~ jessicaclark$ cd /etc/apache2/
Jessicas-Mac-mini:apache2 jessicaclark$ sudo nano httpd.conf
Password:
Jessicas-Mac-mini:apache2 jessicaclark$ sudo apachectl restart
Password:
Jessicas-Mac-mini:apache2 jessicaclark$ httpd -v
Server version: Apache/2.4.9 (Unix)
Server built: Sep 9 2014 14:48:20
Jessicas-Mac-mini:apache2 jessicaclark$ apachectl configtest
AH00526: Syntax error on line 15 of /private/etc/apache2/extra/httpd-dav.conf:
Invalid command 'DavLockDB', perhaps misspelled or defined by a module not included in the server configuration
Supposed to be able to open http://localhost/
with 'It works!'...Any feedback appreciated!

How to permanent enable PHP 5.4 on RHEL? (PHP 5.3.3 also installed on the system)

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.

Categories