Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Configure Apache and PHP in Red Hat 8 1

Status
Not open for further replies.

conjurer111

Programmer
Aug 11, 2002
76
IN
Hi,

Where can I get detailed info regarding how to configure and use Apache along with PHP. I have Red Hat 8.0 and have installed Apache Server and PHP thats available in the packages. Also are there any GUI tools available to configure them or do I need to edit files and if so which files are those.

MySQL is already configured and I am able to use it.

Thanks.
 
Most of what you need to know is in the Apache Forum FAQ's, see: faq65-0
 
For a pretty good GUI configuration aid download and install webmin. It's a browser based configuration tool that aleviates you from having to know what and where all the config files are located.
 
There was nothing in your faq link
Welcome to the new Apache Group: Apache FAQ. There currently aren't any FAQs posted, so feel free to start the ball rolling by writing one now.


What is the correct link?
 
Yeah! strange that, because if you then click the FAQ tab it appears ok ..... did you not try that?

All I done was copy the link from the url bar and it (the forum), modifies it to a like this ..
faq65-0 It still does it unless I take off the http:// .... try this:
Laurie.
 
Hello,

I had made two php pages - namely test.php and tes1.php with the following codes -

Test.php

<?
phpinfo();
?>


Test1.php

<?php
phpinfo();
?>

I had placed them in the folder /var/
Now when i type the url
I get a blank page and when I execute I get the detailed info regarding PHP. Why is this so. What other configurations do I need ? Please suggest.

Thanks.
 
Edit your /etc/php.ini (or wherever php.ini is ) and change the setting that mentions shorthand something ..... hang on .......

; Allow the <? tag. Otherwise, only <?php and <script> tags are recognized.
short_open_tag = On


There you go ... no need to restart anything .. should just work

Good Luck
Laurie.
 
Hi,

okay that worked like a charm. Now this is what I have to fix.

I got a simple site made in PHP and MySQL and is running perfect. I have hosted it locally in Win 98 using PHPTriad. Now when I take the same to the Linux, I get the main page displayed. However when I try to login, nothing happens. I get no errors either.

How do I check whether my PHP is configured for MySQL or not ?

PS. kindly note that I had installed Apache, PHP and MySQL as available in the packages from the installation disks during the setup itself. I haven't compiled them myself. MySQL is working fine, I say this because I can login to it and create databases and tables.

Thanks.
 
Ok ...
1) Have you looked at /var/log/httpd/error.log on the linux box for errors ?

(with a terminal/console window open on the Linux server (as root) do: tail -f /var/log/httpd/error.log
then access your page and see if an error is written into the tail of log .....) OH! CTRL+C to kill the tail -f

2) I dont know your authentication method that you are using to log in with is this code within PHPTriad if so I dont know that package so I can't help there.

Try (1) above and see what you are getting ... you could also tail -f /var/log/httpd/access.log ... and see your requests comming in also....

Good Luck,
Laurie.

 
Hi there,

the above command gives me this output -

tail : tail -f /var/log/httpd/error.log: no such file or directory
tail: no files remaining


Now where do I proceed ?


Also since I had installed MySQL, Apache and PHP from the Red Hat 8 installation CD's and they all seem to work individually but not as in a combined manner as in a PHP page trying to access MySQL. What would be the best way to configure them so that they work ?

Also rpm -qa | grep php-mysql didnt give any results.

Or is it better if I uninstall them and then reinstall them again so that they work. Will I need to download the setup files or can I obtain them from the files present in the CD's ( the ISO files ). Please suggest.

Thanks.
 
Ok ... first of all as root use the command: locate to find files example: locate error <CR>
Right ..
Lets assume that all three applications are on your Linux box .. thats Apache, MySQL and PHP.

We can test that each work in the following manner:

To see that Apache is running and serving a page we can first do from a telnet (or ssh) terminal, ps -ef | grep httpd ... you should see something like this as the output ....

ps -ef | grep httpd
root 7975 1 0 May19 ? 00:00:00 /usr/sbin/httpd -DHAVE_PROXY -DH
apache 21150 7975 0 04:02 ? 00:00:00 /usr/sbin/httpd -DHAVE_PROXY -DH
apache 21151 7975 0 04:02 ? 00:00:00 /usr/sbin/httpd -DHAVE_PROXY -DH
apache 21152 7975 0 04:02 ? 00:00:00 /usr/sbin/httpd -DHAVE_PROXY -DH
apache 21153 7975 0 04:02 ? 00:00:00 /usr/sbin/httpd -DHAVE_PROXY -DH
apache 21154 7975 0 04:02 ? 00:00:00 /usr/sbin/httpd -DHAVE_PROXY -DH
apache 21155 7975 0 04:02 ? 00:00:00 /usr/sbin/httpd -DHAVE_PROXY -DH
apache 21156 7975 0 04:02 ? 00:00:00 /usr/sbin/httpd -DHAVE_PROXY -DH
apache 21165 7975 0 04:02 ? 00:00:00 /usr/sbin/httpd -DHAVE_PROXY -DH

Therefore we can see that apache has one initital process started by root (who then passes control to apache) and eight child process running by apache. ..... thats good
If you only see your grep and no httpd processes then Apache is not running.

Ok so we have a running apache server .. now from that same terminal window do the following: telnet localhost 80 <CR> (where <CR> is pressing the enter key) ... you should be presented with something like the following:
[admin@esl2000 admin]$ telnet localhost 80
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.

Now just type:
GET <CR>

you should get the contents (in html code) of index.htm spooled out to your terminal ?
That would indicate that Apache is serving a page ok.

Now for PHP ... ok there are a number of things we can do to check and then prove php is working under Apache ....

First: check that /etc/httpd/conf/httpd.conf (apache's config file) is aware that we want to use something.php as a valid file suffix (I think you have got to this point anyway but bear with me) .... so in httpd.conf we need to be sure that somewhere the following lines are included (by that I mean allready there):

DirectoryIndex index.html index.htm index.shtml index.php index.php4 index.php3 index.cgi

AND

# AddType: allows you to tweak mime.types without actually editing it, or to
# make certain files to be certain types.
#
# The following is for PHP4 (conficts with PHP/FI, below):
<IfModule mod_php4.c>
AddType application/x-httpd-php .php4 .php3 .phtml .php
AddType application/x-httpd-php-source .phps
</IfModule>

Now lets assume that they are there (if not we need to look at why your install failed to configure correctly).

So on to testing php inside Apache:
now we write a file in the DocumentRoot of our webserver and call it test.php place just the following in that file:
<? echo phpinfo(); ?>
save and close the file now we can test php works go to your browser (on your Linux machine if you like ) and do (or from another machines browser)
And you should see something like this:

Ok php works.

Now to the difficult bit MySQL:
Ok now cut and paste the following (from just after <CUT> down to above the next <CUT>) into a file called test.sql and place it in /tmp on your linux server:

<CUT>
# MySQL dump 8.14
# Table structure for table 'entries'
CREATE TABLE mytest (
id int(11) NOT NULL auto_increment,
title varchar(60) default NULL,
text blob,
date datetime default NULL,
PRIMARY KEY (id)
) TYPE=MyISAM;
# Dumping data for table 'entries'
INSERT INTO mytest VALUES (1,'paper','Cuts stone','2002-04-01 10:23:31');
INSERT INTO mytest VALUES (2,'Linux and Apache','I have discovered that Linux and Apache are shining examples of Open Source projects.','2002-04-03 11:03:52');
INSERT INTO mytest VALUES (3,'Perl','Perl is great','2002-04-05 16:13:22');
INSERT INTO mytest VALUES (4,'CGI and mod_perl','Way to go!.','2002-04-08 12:43:26');
INSERT INTO mytest VALUES (5,'PHP is cool!','Learning PHP is the best thing that I did today.','2002-04-16 08:19:28');
<CUT>

Ok now on your linux server do the following: cd /tmp; mysql
you should now have the mysql> prompt ?

So now at that prompt do: mysql>use test <CR> .. this will say database changed .... now do: source /tmp/test.sql <CR>

this should create a table in test called mytest and populate it for you .... now check this with mysql>show tables;
if its there do: mysql>SELECT * FROM mytest; .... see teh contents?

I hope so ....
Ok lets speed things up now ... create an fred.php file and add this as its contents:
Again after and before <CUT> ....
<CUT>
<?
// connect to the mysql server on localhost
$mysql = mysql_connect(&quot;localhost&quot;, &quot;apache&quot;, &quot;&quot;)
or die(&quot;could not connect to mysql&quot;);

// execute the MySQL query, grab the result in $result
$result = mysql_db_query(&quot;test&quot;, &quot;SELECT * FROM mytest&quot;)
or die(&quot;query failed - &quot; . mysql_errno() . &quot;: &quot; . mysql_error());

?>
<html>
<head>
<title>PHP and MySQL TEST</title>
</head>
<body bgcolor=&quot;#ffffff&quot;>
We executed: <b>SELECT * FROM mytest</b>
<hr>
We found <b><? echo mysql_num_rows($result); ?></b> rows.

<h3>Query result</h3>

<?
//loop through each row
while ($array = mysql_fetch_row($result)) {
// foreach column in the row
foreach ($array as $f) {
print &quot;$f :: &quot;;
}
print &quot;<hr>&quot;;
}
?>
</body>
</html>
<?
// we are all done, so close the MySQL connection
mysql_close($mysql);
?>

Now try it from your browser http:// your ip address/fred.php you should get the following:


Good Luck,
21:12 time for shower
Laurie.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top