Senin, 29 Oktober 2018

How to fix php httpd cannot read php file

  Tidak ada komentar
Some day i install httpd with php, when i try to testing the webserver using curl, the result just a plain text, php file not execute properly, it just like we open the php file with text editor

[root@WebApps html]# curl localhost/testing.php
<?php

// Show all information, defaults to INFO_ALL
phpinfo();

?>
[root@WebApps html]#
Php info file
[root@WebApps html]# cat /var/www/html/testing.php
<?php

// Show all information, defaults to INFO_ALL
phpinfo();

?>
[root@WebApps html]#
Open the httpd configuration

[root@WebApps html]# vi /etc/httpd/conf/httpd.conf
[root@WebApps html]#
Make sure libphp load properly
#
# Dynamic Shared Object (DSO) Support
#
# To be able to use the functionality of a module which was built as a DSO you
# have to place corresponding `LoadModule' lines at this location so the
# directives contained in it are actually available _before_ they are used.
# Statically compiled modules (those listed by `httpd -l') do not need
# to be loaded here.
#
# Example:
# LoadModule foo_module modules/mod_foo.so
LoadModule php5_module        /usr/lib64/httpd/modules/libphp5.so
#
Include conf.modules.d/*.conf

#

Add the php to mime type
<IfModule mime_module>
    #
    # TypesConfig points to the file containing the list of mappings from
    # filename extension to MIME-type.
    #
    TypesConfig /etc/mime.types

    #
    # AddType allows you to add to or override the MIME configuration
    # file specified in TypesConfig for specific file types.
    #
    #AddType application/x-gzip .tgz
    #
    # AddEncoding allows you to have certain browsers uncompress
    # information on the fly. Note: Not all browsers support this.
    #
    #AddEncoding x-compress .Z
    #AddEncoding x-gzip .gz .tgz
    #
    # If the AddEncoding directives above are commented-out, then you
    # probably should define those extensions to indicate media types:
    #
    AddType application/x-compress .Z
    AddType application/x-gzip .gz .tgz
    AddType application/x-httpd-php .php
    #
    # AddHandler allows you to map certain file extensions to "handlers":
    # actions unrelated to filetype. These can be either built into the server
    # or added with the Action directive (see below)
    #

Restart the httpd service
[root@WebApps html]# service httpd restart
Redirecting to /bin/systemctl restart httpd.service
[root@WebApps html]# service httpd status
Redirecting to /bin/systemctl status httpd.service
● httpd.service - The Apache HTTP Server
   Loaded: loaded (/usr/lib/systemd/system/httpd.service; enabled; vendor preset: disabled)
   Active: active (running) since Tue 2018-10-30 08:08:54 WIB; 48s ago
     Docs: man:httpd(8)
           man:apachectl(8)
  Process: 2706 ExecStop=/bin/kill -WINCH ${MAINPID} (code=exited, status=0/SUCCESS)
 Main PID: 2713 (httpd)
   Status: "Total requests: 0; Current requests/sec: 0; Current traffic:   0 B/sec"
    Tasks: 6
   CGroup: /system.slice/httpd.service
           ├─2713 /usr/sbin/httpd -DFOREGROUND
           ├─2717 /usr/sbin/httpd -DFOREGROUND
           ├─2718 /usr/sbin/httpd -DFOREGROUND
           ├─2719 /usr/sbin/httpd -DFOREGROUND
           ├─2720 /usr/sbin/httpd -DFOREGROUND
           └─2721 /usr/sbin/httpd -DFOREGROUND

Oct 30 08:08:50 WebApps systemd[1]: Starting The Apache HTTP Server...
Oct 30 08:08:54 WebApps httpd[2713]: AH00558: httpd: Could not reliably determine the server's fully qualified domain name, ...message
Oct 30 08:08:54 WebApps systemd[1]: Started The Apache HTTP Server.
Hint: Some lines were ellipsized, use -l to show in full.
[root@WebApps html]#

Perform curl again of localhost with php info file path
[root@WebApps html]# curl localhost/info.php
The result was ok not just i plain text
[root@WebApps html]# curl localhost/info.php | less
l//EN" "DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"><head>
<style type="text/css">
body {background-color: #fff; color: #222; font-family: sans-serif;}
pre {margin: 0; font-family: monospace;}
a:link {color: #009; text-decoration: none; background-color: #fff;}
a:hover {text-decoration: underline;}
table {border-collapse: collapse; border: 0; width: 934px; box-shadow: 1px 2px 3px #ccc;}
.center {text-align: center;}
.center table {margin: 1em auto; text-align: left;}
.center th {text-align: center !important;}
td, th {border: 1px solid #666; font-size: 75%; vertical-align: baseline; padding: 4px 5px;}
h1 {font-size: 150%;}
h2 {font-size: 125%;}
.p {text-align: left;}
.e {background-color: #ccf; width: 300px; font-weight: bold;}
.h {background-color: #99c; font-weight: bold;}
.v {background-color: #ddd; max-width: 300px; overflow-x: auto;}
.v i {color: #999;}
img {float: right; border: 0;}
hr {width: 934px; background-color: #ccc; border: 0; height: 1px;}
</style>
<title>phpinfo()</title><meta name="ROBOTS" content="NOINDEX,NOFOLLOW,NOARCHIVE" /></head>
<body><div class="center">
<table>
<tr class="h"><td>
<a href="http://www.php.net/"><img border="0" src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAHkAAABACAYAAAA+j9gsAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAD4BJREFUeNrsnXtwXFUdx8/dBGihmE21QCrQDY6oZZykon/gY5qizjgM2KQMfzFAOioOA5KEh+j4R9oZH7zT6MAMKrNphZFSQreKHRgZmspLHSCJ2Co6tBtJk7Zps7tJs5t95F5/33PvWU4293F29ybdlPzaM3df2XPv+Zzf4/zOuWc1tkjl+T0HQ3SQC6SBSlD6WKN4rusGm9F1ps/o5mPriOf8dd0YoNfi0nt4ntB1PT4zYwzQkf3kR9/sW4xtpS0CmE0SyPUFUJXFMIxZcM0jAZ4xrKMudQT7963HBF0n6EaUjkP0vI9K9OEHWqJLkNW1s8mC2WgVTwGAqWTafJzTWTKZmQuZ/k1MpAi2+eys6mpWfV

Tidak ada komentar :

Posting Komentar