LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 05-19-2015, 11:53 PM   #1
Huamin
Member
 
Registered: May 2011
Posts: 562

Rep: Reputation: 12
Run PHP file


Hi,
Is there one example to run PHP page on RedHat?
 
Old 05-20-2015, 02:30 AM   #2
j-ray
Senior Member
 
Registered: Jan 2002
Location: germany
Distribution: ubuntu, mint, suse
Posts: 1,591

Rep: Reputation: 145Reputation: 145
There must be a webserver like apache running and it has to be setup with php.

I can give you an example page:

//Start of file
<?php

phpinfo();

?>
//End of file

Save this as
info.php
in the directory where the webserver looks for files (the DocumentRoot) and call in your browser

http://localhost/info.php

You can find the DocumentRoot of your server in the config file of the server. If that is apache2 then look at
/etc/apache2/httpd.conf
or
/etc/apache2/apache2.conf

or similar.
 
Old 05-20-2015, 02:40 AM   #3
Huamin
Member
 
Registered: May 2011
Posts: 562

Original Poster
Rep: Reputation: 12
Hi,
I do not see 2 .conf files within

/etc/apache2/
 
Old 05-20-2015, 06:26 AM   #4
j-ray
Senior Member
 
Registered: Jan 2002
Location: germany
Distribution: ubuntu, mint, suse
Posts: 1,591

Rep: Reputation: 145Reputation: 145
If you see 1 of them take it.
 
Old 05-22-2015, 06:16 AM   #5
Huamin
Member
 
Registered: May 2011
Posts: 562

Original Poster
Rep: Reputation: 12
Thanks. How to resolve this?
[root@CentOS65x64 ~]# cd /etc/apache2
-bash: cd: /etc/apache2: No such file or directory
[root@CentOS65x64 ~]#
 
Old 05-22-2015, 06:24 AM   #6
michaelk
Moderator
 
Registered: Aug 2002
Posts: 25,702

Rep: Reputation: 5896Reputation: 5896Reputation: 5896Reputation: 5896Reputation: 5896Reputation: 5896Reputation: 5896Reputation: 5896Reputation: 5896Reputation: 5896Reputation: 5896
CentOS document root is /var/www/html. If you installed apache and php using yum then no need to mess with the config files to test your file.
 
Old 05-22-2015, 09:11 AM   #7
Huamin
Member
 
Registered: May 2011
Posts: 562

Original Poster
Rep: Reputation: 12
Thanks. Where should I save the .php file, to be able to further refer to it like

http://localhost/info.php

?
 
Old 05-22-2015, 09:14 AM   #8
michaelk
Moderator
 
Registered: Aug 2002
Posts: 25,702

Rep: Reputation: 5896Reputation: 5896Reputation: 5896Reputation: 5896Reputation: 5896Reputation: 5896Reputation: 5896Reputation: 5896Reputation: 5896Reputation: 5896Reputation: 5896
Save the file to /var/www/html. Permissions should be set to 644.
 
Old 05-22-2015, 09:19 AM   #9
Habitual
LQ Veteran
 
Registered: Jan 2011
Location: Abingdon, VA
Distribution: Catalina
Posts: 9,374
Blog Entries: 37

Rep: Reputation: Disabled
Code:
vi /var/www/html/info.php
and add
PHP Code:
<?php

phpinfo
();

?>
save and exit or exit with save.
Perms:
Code:
chmod 644 /var/www/html/info.php
run it:
Code:
php -f info.php
or http://localhost/info.php
 
Old 05-22-2015, 10:49 AM   #10
Doug G
Member
 
Registered: Jul 2013
Posts: 749

Rep: Reputation: Disabled
Also, apache installed from yum on centos puts the configuration files in /etc/httpd, not /etc/apache2
 
Old 05-22-2015, 10:58 AM   #11
schneidz
LQ Guru
 
Registered: May 2005
Location: boston, usa
Distribution: fedora-35
Posts: 5,313

Rep: Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918
is apache running ?:
Code:
sudo service httpd status
 
Old 05-22-2015, 10:07 PM   #12
Huamin
Member
 
Registered: May 2011
Posts: 562

Original Poster
Rep: Reputation: 12
Many thanks all.

Sorry, what do I get this
[root@CentOS65x64 ~]# php -f info.php
PHP Fatal error: Class 'mysqli' not found in /root/info.php on line 7
[root@CentOS65x64 ~]#

due to the last line of these codes

<?php
$servername = "localhost";
$username = "user1";
$password = "????";
$dbname = "db1";

// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
...

why?
 
Old 05-23-2015, 05:11 AM   #13
j-ray
Senior Member
 
Registered: Jan 2002
Location: germany
Distribution: ubuntu, mint, suse
Posts: 1,591

Rep: Reputation: 145Reputation: 145
Hope this helps
yum install php-pdo php-mysqli

+ restart the server
 
1 members found this post helpful.
  


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
[SOLVED] problems with PHP, showing code trying to "run" a php file? michaelinux Slackware 1 12-29-2010 10:21 PM
how to install php5.3.0 & run any php file in web browser in linux 5.0 anmol1986 Linux - General 4 11-09-2009 07:22 AM
php file not run Arjun123 Linux - Software 6 08-20-2009 01:03 AM
php cli can't run php file outside its path asiandude Programming 4 12-11-2008 02:50 PM
Can I run localhost/file.php with CRON function kondor5 Linux - General 1 03-28-2004 06:44 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 08: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