LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Server
User Name
Password
Linux - Server This forum is for the discussion of Linux Software used in a server related context.

Notices


Reply
  Search this Thread
Old 07-04-2016, 08:50 PM   #1
killingthemonkey
Member
 
Registered: Mar 2011
Location: Winston-Salem, NC
Distribution: Fedora, CentOS, Linux Mint
Posts: 259

Rep: Reputation: 24
Enable PHP on Centos 7


I followed the instructions on linode.com to install the LAMP stack. If I create a simple info .php and run phpinfo(), I get the return. As soon as I wrap it in an HTML page, my PHP will not execute.

My entire page is simply:
Code:
<html>
    <head>
        <title>A Simple PHP Page</title>
    </head>
    <body>
        <?php
            echo "<h1>Hello, world!</h1>";
        ?>
    </body>
</html>
The page is saved as index.html

All I get is:
Code:
    Hello, world"?>
 
Old 07-04-2016, 09:10 PM   #2
notKlaatu
Senior Member
 
Registered: Sep 2010
Location: Lawrence, New Zealand
Distribution: Slackware
Posts: 1,077

Rep: Reputation: 732Reputation: 732Reputation: 732Reputation: 732Reputation: 732Reputation: 732Reputation: 732
I'm guessing you need to configure Apache to recognise PHP.

This reviews what you need to do in your Apache conf file to "turn on" PHP (you have to load the PHP module into Apache, and make sure Apache knows to treat *.php files as PHP):

http://php.net/manual/en/install.unix.apache2.php
 
Old 07-04-2016, 09:45 PM   #3
Doug G
Member
 
Registered: Jul 2013
Posts: 749

Rep: Reputation: Disabled
Use the .php extension on the file to tell apache to use the php interpreter.
 
Old 07-04-2016, 10:24 PM   #4
killingthemonkey
Member
 
Registered: Mar 2011
Location: Winston-Salem, NC
Distribution: Fedora, CentOS, Linux Mint
Posts: 259

Original Poster
Rep: Reputation: 24
So, I've added the following line to my httpd.conf

Code:
LoadModule php5_module modules/libphp5.so
I confirmed that is where my PHP module lives.

I guess my question is, if I use PHP in a document, does it have to have the .php extension?

I thought you could have PHP embedded in an HTML document.
 
Old 07-05-2016, 08:10 AM   #5
achemete
LQ Newbie
 
Registered: May 2016
Posts: 3

Rep: Reputation: Disabled
Quote:
Originally Posted by killingthemonkey View Post
So, I've added the following line to my httpd.conf

Code:
LoadModule php5_module modules/libphp5.so
I confirmed that is where my PHP module lives.

I guess my question is, if I use PHP in a document, does it have to have the .php extension?

I thought you could have PHP embedded in an HTML document.
Hello killingthemonkey,

Yes, if the file contains php, you should end your file name with .php extension, otherwise you'll see a blank page or your page without the php elements.
 
Old 07-05-2016, 08:36 AM   #6
killingthemonkey
Member
 
Registered: Mar 2011
Location: Winston-Salem, NC
Distribution: Fedora, CentOS, Linux Mint
Posts: 259

Original Poster
Rep: Reputation: 24
Smile

Thank you, achemete, and thank the rest of you for your replies and assistance.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
LXer: How To Use Multiple PHP Versions (PHP-FPM & FastCGI) With ISPConfig 3 (CentOS 6.3) (Copy) LXer Syndicated Linux News 1 03-30-2015 03:14 PM
yum update PHP on CentOS - missing dependency php-common AndyMillne Linux - Server 7 05-21-2013 06:34 AM
LXer: Using Multiple PHP Versions (PHP-FPM & FastCGI) With ISPConfig 3 (CentOS 6.3) LXer Syndicated Linux News 0 03-14-2013 08:10 PM
CentOS, PHP how to enable dom. sblantipodi Linux - Server 1 05-17-2009 10:12 PM
enable gd support php in CentOs mitesh.ever Linux - Newbie 2 12-14-2008 11:22 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Server

All times are GMT -5. The time now is 09:39 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration