phpinfo () does not work on my CentOS server

I have installed PHP on my CentOS server. However, when I run phpinfo () inside my script to check it, I get HTML, not the interpreted information.

I see folders for PHP. I even see php.ini in the etc folder, but PHP itself does not seem to work.

I mean my test.php file looks like this:

 <?php phpinfo(); ?> 

And the answer looks like this:

 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "DTD/xhtml1-transitional.dtd"> <html><head> <style type="text/css"> body {background-color: #ffffff; color: #000000;} body, td, th, h1, h2 {font-family: sans-serif;} pre {margin: 0px; font-family: monospace;} a:link {color: #000099; text-decoration: none; background-color: #ffffff;} ... 

and so on.

What is the problem and how can I solve it?

If I copy the returned HTML code, paste it into the HTML file and run it from there, I can see the formatted result, but without running test.php. I assume that PHP is not loaded somehow ... even if in the interpreted HTML I see:

 **Server API Apache 2.0 Handler Virtual Directory Support disabled Configuration File (php.ini) Path /etc/php.ini Scan this dir for additional .ini files /etc/php.d additional .ini files parsed /etc/php.d/dbase.ini, /etc/php.d/json.ini, /etc/php.d/mysql.ini, /etc/php.d/mysqli.ini, /etc/php.d/pdo.ini, /etc/php.d/pdo_mysql.ini, /etc/php.d/pdo_sqlite.ini PHP API 20041225 PHP Extension 20050922 Zend Extension 220051025 Debug Build no Thread Safety disabled Zend Memory Manager enabled IPv6 Support enabled Registered PHP Streams php, file, http, ftp, compress.bzip2, compress.zlib, https, ftps** 

and so on...

This system has three websites. Is this somehow related to this problem?

+12
source share
14 answers

It happened to me. The fix was to wrap it in HTML tags. Then I saved the file as /var/www/html/info.php and ran http: //localhost/info.php in the browser. It.

 <html> <body> <?php phpinfo(); ?> </body> </html> 
+16
source

Save page that contains

 <?php phpinfo(); ?> 

with the extension .php. Something like info.php , not info.html ...

+9
source

You need to update your Apache configuration to make sure that it displays php as text / HTML.

The code below should work, but some configurations are different.

 AddHandler php5-script .php AddType text/html .php 
+9
source

This did it for me (second answer): why are my PHP files displayed as plain text?

Just adding this didn't work out anymore.

 apt-get install libapache2-mod-php5 
+5
source

I had the same problem and found that the client disabled this function in its php.ini :

 ; This directive allows you to disable certain functions for security reasons. ; It receives a comma-delimited list of function names. This directive is ; *NOT* affected by whether Safe Mode is turned On or Off. disable_functions = phpinfo; 

Additional information: enabling and disabling phpinfo () for security reasons

+3
source

Try creating the php.ini in the root directory, php.ini following command and save it.

 disable_functions = 

Using this code activates the phpinfo () function if it is disabled by the global PHP configuration.

+1
source

Make sure the php tag is inserted into the code as follows:

? php phpinfo (); ?>

Not so :

? php phpinfo (); ?>

OR the server will consider it as (a normal word), so the server will not understand the language you write to deal with it, so it will be empty .

I know this is a stupid mistake ... but it happened ^ _ ^

+1
source

For people who do not have experience in creating websites (such as myself), I tried very hard just to find out that I did not use the .php extension, but the .html extension.

+1
source

I have the same problem.

The solution in my case was to set default_mimetype = "text / html" inside the php.ini file.

0
source

It happened to me. On a newly-prepared Red Hat Linux 7 server.

When I launch the PHP page, i.e. info.php, I could see simple PHP text scripts instead of executing them.

I just installed PHP:

 [ root@localhost ~]# yum install php 

And then restarted Apache HTTP Server:

 [ root@localhost ~]# systemctl restart httpd 
0
source

This may not work if you use localhost/info.php .

You may find the key to the error. Find the port number in the error message. For me it was 80. I changed the address as http: // localhost: 80 / info.php , and then it worked for me.

0
source

My solution was to uninstall and install the PHP instance (7.0 in my case) again:

 sudo apt-get purge php7.0 sudo apt-get install php7.0 

After that, you will need to restart the Apache service:

 sudo service apache2 restart 

Finally, check again in your browser with your local or IP address.

0
source

Another possible answer for Windows 10:

The httpd -k restart command does not work on my machine.

Try using the Windows 10 service to restart the corresponding service.

0
source

I accidentally set the wrong file permissions. After chmod 644 phpinfo.php information really appeared, as expected.

0
source

Source: https://habr.com/ru/post/949952/


All Articles