Php apache2 issues

  • (2 Pages)
  • +
  • 1
  • 2

22 Replies - 4531 Views - Last Post: 16 November 2012 - 11:32 AM

#1 khedron  Icon User is offline

  • D.I.C Head

Reputation: 2
  • View blog
  • Posts: 52
  • Joined: 20-October 12

Php apache2 issues

Posted 09 November 2012 - 01:18 AM

am installing an apache2 (lamp) server on ubuntu 12.04 and every thing worked out but am having problems with the .php extentiions not being able to be read. but only when there is both <html> and <?php in the file. the only time it works is when the only code in the file is <?php phpinfo(); ?> what do you guys think am missing ?
Is This A Good Question/Topic? 0
  • +

Replies To: Php apache2 issues

#2 Martyr2  Icon User is offline

  • Programming Theoretician
  • member icon

Reputation: 4361
  • View blog
  • Posts: 12,180
  • Joined: 18-April 07

Re: Php apache2 issues

Posted 10 November 2012 - 11:36 AM

So for clarification when you put both HTML and PHP into the same file and give it the .php extension it doesn't work, but when you put only PHP code into the file and give it the .php extension it works?
Was This Post Helpful? 0
  • +
  • -

#3 TheChefSLC  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 19-October 12

Re: Php apache2 issues

Posted 10 November 2012 - 07:46 PM

Sounds as if php has come to an exception some where. Default lamp install does not show php errors.

In your php file, place this code above the the DOCTYPE delclaration

<?php ini_set(display_errors , '1'); ?>

This will allow the document in question to show php related errors

Sent from my SAMSUNG-SGH-I747 using Tapatalk 2
Was This Post Helpful? 0
  • +
  • -

#4 khedron  Icon User is offline

  • D.I.C Head

Reputation: 2
  • View blog
  • Posts: 52
  • Joined: 20-October 12

Re: Php apache2 issues

Posted 10 November 2012 - 08:58 PM

well i found the problem, it was the quoteations i am reading php/mysql for dummies .....(i know .. no comments please .) and since ive never done any server side scripting i was coping and pasting and the quoteations in the ebook are diff than mine . mine " book”. even after changing them all apache can now read the .php extention but the code still doesn't work .

here it is (direct copy n paste )
<html>
<head><title>Test MySQL</title></head>
<body>
<!-- mysql_up.php -->
<?php
$host=”hostname”;
$user=”mysqlaccount”;
$password=”mysqlpassword”;
mysql_connect($host,$user,$password);
$sql=”show status”;
$result = mysql_query($sql);
if ($result == 0)
echo “<b>Error “ . mysql_errno() . “: “
. mysql_error() . “</b>”;
else
{
?>
<!-- Table that displays the results -->
<table border=”1”>
<tr><td><b>Variable_name</b></td><td><b>Value</b>
</td></tr>
<?php
for ($i = 0; $i < mysql_num_rows($result); $i++) {
echo “<TR>”;
$row_array = mysql_fetch_row($result);
for ($j = 0; $j < mysql_num_fields($result); $j++)
{
echo “<TD>” . $row_array[$j] . “</td>”;
}
echo “</tr>”;
}
?>
</table>
<?php } ?>
</body></html>



when i make the page am setting the host user and password like so
$host=”localhost”;
$user=””; <- mysql server dosn't have one yet
$password=”mysqlpassword”; < --  the password 


Was This Post Helpful? 0
  • +
  • -

#5 khedron  Icon User is offline

  • D.I.C Head

Reputation: 2
  • View blog
  • Posts: 52
  • Joined: 20-October 12

Re: Php apache2 issues

Posted 10 November 2012 - 10:58 PM

View PostTheChefSLC, on 10 November 2012 - 07:46 PM, said:

Sounds as if php has come to an exception some where. Default lamp install does not show php errors.

In your php file, place this code above the the DOCTYPE delclaration

<?php ini_set(display_errors , '1'); ?>

This will allow the document in question to show php related errors

Sent from my SAMSUNG-SGH-I747 using Tapatalk 2


i added that line to the file and corrected all the "s.
  <?php ini_set(display_errors , '1'); ?>


<html>
	<head><title>Test MySQL</title></head>
	<body>
	<!-- mysql_up.php -->
	<?php
	$host="localhost";
	$user="";
	$password="*******";
	mysql_connect($host,$user,$password);
	$sql="show status";
	$result = mysql_query($sql);
	if ($result == 0)
	echo "<b>Error " . mysql_errno() . ": "
	. mysql_error() . "</b>";
	else
	{
	?>
	<!-- Table that displays the results -->
	<table border="1">
	<tr><td><b>Variable_name</b></td><td><b>Value</b>
	</td></tr>
	<?php
	for ($i = 0; $i < mysql_num_rows($result); $i++) {
	echo "<TR>";
	$row_array = mysql_fetch_row($result);
	for ($j = 0; $j < mysql_num_fields($result); $j++)
	{
	echo "<TD>" . $row_array[$j] . "</td>";
	}
	echo "</tr>";
	}
	?>
	</table>
	<?php } ?>
	</body></html>
. (i am putting the password not * :D/> )
am getting this when i load the page.
Fatal error: Call to undefined function mysql_connect() in /var/www/tam.php on line 12
Was This Post Helpful? 0
  • +
  • -

#6 TheChefSLC  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 19-October 12

Re: Php apache2 issues

Posted 11 November 2012 - 11:56 AM

Looking at your code and errors, we have an issue on line 12 or above.

I believe that your issue is located with the MySQL connection.

in order to query your database, you need to log in with a username and password. Due to your script calling the MySQL connection, it has a fatal call due to not being able to actually connect to the server.

when you setup your LAMP server in Ubuntu, it prompts to you enter in a password. This is for your root user. You should put root for the username and then your password for that account.

Due to the security risk involved with that, you will want to ensure you have a separate account on the MySQL server for any public pages. I would do this now myself just to ensure that my root account does not become compromised.

View Postkhedron, on 10 November 2012 - 10:58 PM, said:

  <?php ini_set(display_errors , '1'); ?>


<html>
	<head><title>Test MySQL</title></head>
	<body>
	<!-- mysql_up.php -->
	<?php
	$host="localhost";
	$user="";
	$password="*******";
	mysql_connect($host,$user,$password);
	$sql="show status";
	$result = mysql_query($sql);
	if ($result == 0)
	echo "<b>Error " . mysql_errno() . ": "
	. mysql_error() . "</b>";
	
. (i am putting the password not * :D/>/> )
am getting this when i load the page.
Fatal error: Call to undefined function mysql_connect() in /var/www/tam.php on line 12

Was This Post Helpful? 0
  • +
  • -

#7 khedron  Icon User is offline

  • D.I.C Head

Reputation: 2
  • View blog
  • Posts: 52
  • Joined: 20-October 12

Re: Php apache2 issues

Posted 11 November 2012 - 10:44 PM

wow, i did do all that, i also din't download lamp as one i individually got php , apache and mysql . i have been making the mistake of not putting in the pass,


 
<?php ini_set(display_errors , '1'); ?>


<html>
	<head><title>Test MySQL</title></head>
	<body>
	<!-- mysql_up.php -->
	<?php
	$host="localhost";
	$user="root";
	$password="*******";
	mysql_connect($host,$user,$password);
	$sql="show status";
	$result = mysql_query($sql);
	if ($result == 0)
	echo "<b>Error " . mysql_errno() . ": "
	. mysql_error() . "</b>";
	else
	{
	?>
	<!-- Table that displays the results -->
	<table border="1">
	<tr><td><b>Variable_name</b></td><td><b>Value</b>
	</td></tr>
	<?php
	for ($i = 0; $i < mysql_num_rows($result); $i++) {
	echo "<TR>";
	$row_array = mysql_fetch_row($result);
	for ($j = 0; $j < mysql_num_fields($result); $j++)
	{
	echo "<TD>" . $row_array[$j] . "</td>";
	}
	echo "</tr>";
	}
	?>
	</table>
	<?php } ?>
	</body></html>



changed it to this , still getting the same error ,
and in gedit this is coming up as line 12
should i change values in that line as well ?
 	mysql_connect($host,$user,$password);



its ok for me to have security issues, am building the site on a desktop with a desktop os, using a usb modem for connection . the site will be live on a secure server much later . i don't even have a domain am using the ip address . which changes every time i restart the conection >< .. its kind of annoying

i can't find how to edit my posts 0-0

View Postkhedron, on 12 November 2012 - 05:39 AM, said:

i have been making the mistake of not putting in the pass,

i ment user not pass here .
Was This Post Helpful? 0
  • +
  • -

#8 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 6078
  • View blog
  • Posts: 23,549
  • Joined: 23-August 08

Re: Php apache2 issues

Posted 12 November 2012 - 04:54 AM

Quote

its ok for me to have security issues, am building the site on a desktop with a desktop os, using a usb modem for connection . the site will be live on a secure server much later . i don't even have a domain am using the ip address . which changes every time i restart the conection


NO! You start with security FROM THE VERY BEGINNING!!! It's MUCH harder to make code you've ALREADY WRITTEN (poorly) secure.
Was This Post Helpful? 1
  • +
  • -

#9 khedron  Icon User is offline

  • D.I.C Head

Reputation: 2
  • View blog
  • Posts: 52
  • Joined: 20-October 12

Re: Php apache2 issues

Posted 12 November 2012 - 07:56 AM

the code will be as secure as i can make it , but when its moved the mysql server will be diff and i can use the non root user on that server then . but am actually learning php so there really will not be any thing that required much security on the site . .. am not a genius . one step at a time
Was This Post Helpful? 0
  • +
  • -

#10 TheChefSLC  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 19-October 12

Re: Php apache2 issues

Posted 12 November 2012 - 06:30 PM

I copied your code exactly and was able to get the specified results. There is nothing wrong with the code. I believe it is an issue with the configuration on of your mysql or php configuration.

Create a file called test.php and insert the following code. If this loads a blank page without errors, you should be fine. Also if you have any "$" in your password, you will end up having errors as php will think its a variable.

<?php
ini_set(display_errors , '1'); // enabled php error reporting in the browser window
$host="localhost";
$user="root"; // very insecure to use. please create a new test account
$password="*******"; // change to whatever your password is
mysql_connect($host,$user,$password); 


If this work, Then load phpinfo() and scroll down to mysql to ensure that it is enabled for your php configuration.
Was This Post Helpful? 0
  • +
  • -

#11 khedron  Icon User is offline

  • D.I.C Head

Reputation: 2
  • View blog
  • Posts: 52
  • Joined: 20-October 12

Re: Php apache2 issues

Posted 13 November 2012 - 02:12 AM

i got back a clear page,
then i loaded php info . and i can't find a mysql or sql section . the only refrence to sql in the whole page is the line with thw red bloch in the attached file . and its under "core" i can access mysql via terminal tho ....??

does this mean my php is fine but mysql is misconfigured or ?????

Attached image(s)

  • Attached Image

Was This Post Helpful? 0
  • +
  • -

#12 TheChefSLC  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 19-October 12

Re: Php apache2 issues

Posted 13 November 2012 - 08:53 AM

Getting the blank page is.good. however not having a mysql section is bad. Maybe you could easily fix this by installing phpmyadmin

From the terminal type

Sudo apt-get install phpmyadmin

Thos should get and install any of the missing default php apache and mysql dependancies and configuration files

Sent from my SAMSUNG-SGH-I747 using Tapatalk 2
Was This Post Helpful? 0
  • +
  • -

#13 no2pencil  Icon User is offline

  • Admiral Fancy Pants
  • member icon

Reputation: 5364
  • View blog
  • Posts: 27,325
  • Joined: 10-May 07

Re: Php apache2 issues

Posted 13 November 2012 - 08:55 AM

Did you allow port 3306 on your firewall? This is required even for local traffic. If it isn't open, mysql can't bind the port, & it also can't run.

Also, seeing 'root' in the config file, I'll assume this is a *nix environment? Issue ps aux | grep sql & see if mysql is running.
Was This Post Helpful? 0
  • +
  • -

#14 khedron  Icon User is offline

  • D.I.C Head

Reputation: 2
  • View blog
  • Posts: 52
  • Joined: 20-October 12

Re: Php apache2 issues

Posted 13 November 2012 - 11:09 AM

$ ps aux | grep sql
mysql      953  0.0  0.2 317456  1056 ?        Ssl  13:05   0:14 /usr/sbin/mysqld
heen      7032  0.0  0.1   4372   812 pts/1    S+   20:59   0:00 grep --color=auto sql



thats what i got for "ps aux | grep sql"
. about port 3306 .does it have to be open for mysql to work on localhost. ?
Was This Post Helpful? 0
  • +
  • -

#15 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 6078
  • View blog
  • Posts: 23,549
  • Joined: 23-August 08

Re: Php apache2 issues

Posted 13 November 2012 - 11:16 AM

What does

telnet localhost 3306


do?
Was This Post Helpful? 0
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2