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 |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
|
|
05-20-2015, 12:53 AM
|
#1
|
Member
Registered: May 2011
Posts: 562
Rep:
|
Run PHP file
Hi,
Is there one example to run PHP page on RedHat?
|
|
|
05-20-2015, 03:30 AM
|
#2
|
Senior Member
Registered: Jan 2002
Location: germany
Distribution: ubuntu, mint, suse
Posts: 1,591
Rep:
|
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.
|
|
|
05-20-2015, 03:40 AM
|
#3
|
Member
Registered: May 2011
Posts: 562
Original Poster
Rep:
|
Hi,
I do not see 2 .conf files within
/etc/apache2/
|
|
|
05-20-2015, 07:26 AM
|
#4
|
Senior Member
Registered: Jan 2002
Location: germany
Distribution: ubuntu, mint, suse
Posts: 1,591
Rep:
|
If you see 1 of them take it.
|
|
|
05-22-2015, 07:16 AM
|
#5
|
Member
Registered: May 2011
Posts: 562
Original Poster
Rep:
|
Thanks. How to resolve this?
[root@CentOS65x64 ~]# cd /etc/apache2
-bash: cd: /etc/apache2: No such file or directory
[root@CentOS65x64 ~]#
|
|
|
05-22-2015, 07:24 AM
|
#6
|
Moderator
Registered: Aug 2002
Posts: 26,341
|
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.
|
|
|
05-22-2015, 10:11 AM
|
#7
|
Member
Registered: May 2011
Posts: 562
Original Poster
Rep:
|
Thanks. Where should I save the .php file, to be able to further refer to it like
http://localhost/info.php
?
|
|
|
05-22-2015, 10:14 AM
|
#8
|
Moderator
Registered: Aug 2002
Posts: 26,341
|
Save the file to /var/www/html. Permissions should be set to 644.
|
|
|
05-22-2015, 10:19 AM
|
#9
|
LQ Veteran
Registered: Jan 2011
Location: Abingdon, VA
Distribution: Catalina
Posts: 9,374
Rep:
|
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:
or http://localhost/info.php
|
|
|
05-22-2015, 11:49 AM
|
#10
|
Member
Registered: Jul 2013
Posts: 749
Rep:
|
Also, apache installed from yum on centos puts the configuration files in /etc/httpd, not /etc/apache2
|
|
|
05-22-2015, 11:58 AM
|
#11
|
LQ Guru
Registered: May 2005
Location: boston, usa
Distribution: fedora-35
Posts: 5,326
|
is apache running ?:
Code:
sudo service httpd status
|
|
|
05-22-2015, 11:07 PM
|
#12
|
Member
Registered: May 2011
Posts: 562
Original Poster
Rep:
|
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?
|
|
|
05-23-2015, 06:11 AM
|
#13
|
Senior Member
Registered: Jan 2002
Location: germany
Distribution: ubuntu, mint, suse
Posts: 1,591
Rep:
|
Hope this helps
yum install php-pdo php-mysqli
+ restart the server
|
|
1 members found this post helpful.
|
All times are GMT -5. The time now is 07:25 PM.
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|