Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I have Ubuntu-9.04 and am using XAMPP-1.7.2 to develop a web application. The problem is that when I try to view a PHP file I wrote by visiting localhost/folder/file.php, Firefox offers me to download it instead of showing me the file as a web page. If I do download it and open it in my favorite text editor, I get an empty file with nothing in it...

UPDATE: Works on another server Well, I uploaded the page to another server, and I can see it fine! So the problem is not with Firefox. Nor is it with the code itself. My server or its configuration must be the problem. Does that give any of you a clue as to what's happening?

UPDATE: Isolating the problem Firefox offers to download only the first of these three files:

test1.php is offered as a download

<?php
    mysql_connect("localhost","root","");
    mysql_close();
?>

test2.php outputs: Warning: mysql_close(): no MySQL-Link resource supplied in /opt/lampp/htdocs/test.php on line 3

<?php
    //mysql_connect("localhost","root","");
    mysql_close();
?>

test3.php outputs a blank page

<?php
    mysql_connect("localhost","root","");
    //mysql_close();
?>

I know that my server is up and running and it tells me that PHP5 is on, and running as well.

Here is what I get in the XAMPP error log when the problem occurs (truncated and formatted for clarity):

[notice] child pid 7338 exit signal Segmentation fault (11)

Oh, and firefox can see the file without a problem on my other computer (windows XP SP3 and easyPHP as server) Does anyone know what I can do to solve this problem?

UPDATE: using error_log()

Here is my try at using error_log(): test4.php

<?php
    error_log("Start of file reached by PHP");
    mysql_connect("localhost","root","");
    error_log("mysql_connect executed");
    mysql_close();
    error_log("mysql_close executed");
?>

This is what it produces in the XAMPP error log (trucated for clarity):

[error] [client 127.0.0.1] Start of file reached by PHP
[error] [client 127.0.0.1] mysql_connect executed
[notice] child pid 5338 exit signal Segmentation fault (11)
share|improve this question
    
I am not sure if error_log enforces synchronous log files: messages from multiple sources might not appear in the exact order in which the messages are generated. So, though not likely, the actual error might have occurred before error_log was executed. (And though the download that Firefox tries is not your problem, you could try to see what HTTP headers are sent along with that file. Especially the Content-Type will probably tell you what the browser thinks it received. See, for example, the Net panel in Firebug: getfirebug.com/net.html) –  Arjan Sep 26 '09 at 22:07
3  
Shouldn't this be on Stack Overflow? –  Brian Ortiz Sep 28 '09 at 2:35
    
I tried looking at the HTTP headers, but when Firefox offers to download a page, nothing appears under the Net tab. So I can't even look at the headers... What does this mean about how firefox sees the file? –  Shawn Sep 30 '09 at 15:03

4 Answers 4

up vote 1 down vote accepted

Smells like your mysql install. Is mysql running as a service? Does your root account really have no password? What mysql extensions are loaded in php.ini? There's a php_mssql.dll which can easily be mistaken for php_msql.dll, but I'm fairly certain the php_mssql.dll is for windows only.

Have you edited your php.ini /opt/lampp/php/php.ini? These may help with debugging:

error_reporting  =  E_ALL & ~E_NOTICE
display_errors = On
display_startup_errors = On ;but you'll want to turn this off soon ;)
mysql.trace_mode = On

Also worth looking at, the port number used. Is $MYSQL_TCP_PORT set? How about the mysql-tcp entry in /etc/services?

Update: Have you tried checking the return value of the connect function? I'm wondering if you example is too minimal. Try making your test look like this:

<?php

$db = mysql_connect("localhost","root","myrootpassword");
if (!$db) {
    die('Could not connect: ' . mysql_error());
}
else {
    $result = mysql_query("show databases");
   print "
   <h1>Test executed from ". $_SERVER['SCRIPT_NAME']. "</h1>

    \n";
    print "Script name: ". $_SERVER['SCRIPT_FILENAME'] ." <hr>\n";
    while ($line = mysql_fetch_array($result))
    {
        print "$line[0]<br>\n";
    }
}       
mysql_close($db);

?>

This example ensure you send something back that looks like HTML whether your script fails or not. I was able to reproduce your symptoms with no root password set, so it's apparently not only good practice, but it's required to be non-empty.

I was able to turn your problem into a a solution by

  1. Setting the root password
  2. returning something from the script on connect

Instead of passing in "" as the root password, if it really is nothing, try using mysql.default_password as the password. The default value for mysql.default_password is NULL.

share|improve this answer
    
How can I tell if mysql is running as a service? I don't know if my root has a password or not, but I've tried the sample code with many different users, with and without passwords, to no avail. As for extensions, I haven't installed any since I first installed XAMPP. I can't find php_mssql.dll anywhere. I tried echo($MYSQL_TCP_PORT); here is what I get Notice: Undefined variable: MYSQL_TCP_PORT in /opt/lampp/htdocs/test.php on line 2 The other settings in php.ini change nothing to my problem. –  Shawn Sep 26 '09 at 1:38
    
Try looking at your XAMPP control panel: Applications -> Other -> XAMPP Control Panel. If you did not set the password, then it's blank by default. If you did set the password, the example you are using has a blank one, so the connect would fail (but I wouldn't expect a crash). You shouldn't find php_mssql.dll, it's a windows dll - however, if you inadvertently enabled that extension all sorts of bad things might happen. You should consider running /opt/lampp/lampp security –  DaveParillo Sep 26 '09 at 4:30
    
That's interesting. I had always been wondering why there is no entry for XAMPP in the applications tab. Indeed, I can't find the Others link which you speak of. In applications, I have only Accessories, Games, Graphics, Internet, Office, Programming, Sound & Video, System tools and Add/Remove... And I can't find anything XAMPP-related. I just start XAMPP with sudo /opt/lampp/lampp start –  Shawn Sep 26 '09 at 17:42
    
Quick security check... Your XAMPP pages are NOT secured by a password. Do you want to set a password? [yes] no MySQL is accessable via network. Normaly that's not recommended. Do you want me to turn it off? [yes] yes ... The MySQL/phpMyAdmin user pma has no password set!!! Do you want to set a password? [yes] yes ... Setting new MySQL pma password. Setting phpMyAdmin's pma password to the new one. MySQL has no root passwort set!!! Do you want to set a password? [yes] no The FTP password for user 'nobody' is still set to 'lampp'. Do you want to change the password? [yes] no Done. that good? –  Shawn Sep 26 '09 at 17:49
    
Can you connect using phpMyAdmin? –  DaveParillo Sep 27 '09 at 0:31

This could be a hardware problem or an Apache/PHP configuration problem. I've usually seen Signal 11 with memory problems. Look at your configs to make sure that the PHP memory limit isn't higher than the Apache memory limit or similar.

It sounds like your php_mod is crashing mid-program, so Apache is just tossing the php file at you with a non-html content-type header, which makes your browser treat it as a download. That's just a guess, though. You need to gather some more information.

Add some error_log() calls to your PHP program so that you can isolate when the crash actually occurs in your code. If that doesn't help narrow it down, set up Apache to create a core dump and use gdb to figure out where the segfault starts. My bet is mod_php.so.

share|improve this answer
    
I tried using error_log by adding <?php error_log("Start of file reached by PHP\n", 3, "/opt/lampp/htdocs/webÉchange/SiteWeb_V5/errorLog.txt"); ?> at the very beggining of one of the faulty files, but errorLog.txt remains blank. I also tried using <?php error_log("End of file reached by PHP", 1, "shawninder@gmail.com", "From: shawninder@gmail.com"); ?>, shawninder@gmail.com being my own e-mail, but still, nothing happens. As for setting up Apache, I can't seem to find how to do this. Actually, I'm finding very little information about setting anything in XAMPP... –  Shawn Sep 25 '09 at 0:05
    
I read up on the core dump, and frankly, I can't understand it. I know I can break my system if I do too many things I don't understand in the command line, so I am hesitant to go on this particular journy. I have edited my question above because I have managed to isolate where the problem occurs. Could you check it out and tell me if the core dump really is what I need? Thanks –  Shawn Sep 25 '09 at 1:07
    
I'd guess that there's a permissions problem with creating errorLog.txt. Why not drop the second and third arguments? Then your message will be added to your default error_log file. If you're not comfortable doing the core dump, then you probably shouldn't. My next question is: what shows up in the test1.php file after you download it? –  mikedub Sep 26 '09 at 6:27
    
I tried error_log with only one argument and it worked. I edited my original post, adding the results of my try. As for what's in the downloaded file: nothing. I download it and open it in gedit, and I get a blank file (0 bytes, btw). That too was edited in my original post. As you can see, it executes everything up to mysql_close(); then it crashes. Yet, the file is blank upon download.. What does this mean? Thanks very much for your help up to now. –  Shawn Sep 26 '09 at 17:38
    
Well, it isolates the problem to the MySQL client in PHP. I'd try the code from Example #1 on the mysql_close man page[us.php.net/mysql_close] to see if your connection actually gets created or whether the mysql_close call is causing the segfault. –  mikedub Sep 29 '09 at 0:42

You say it's all up and running and that simple files are showing up okay. But then some files are prompting you to save the PHP file. This means you'll have to look at the code of those pages where it's breaking and asking you to save.

It's more than likely you have a line in the code that is killing the server or just making it give up parsing the PHP.

This could be a particular extension that's being used by that page or it could be another killbot function that hobbles the server into just sitting there with its arms crossed.

Your error logs show that the last thing to happen before it shoves the save dialog in your face is a connect to the database. Follow the code back to that and make sure that's solid before moving onto the next possible troubleshooting breadcrumb that may or may not arise.

Since you can see the file with no problem on another set up, in this case easyPHP, the problem is very much on the XAMPP set up and a configuration that is being tripped up by the code.

share|improve this answer
    
So how do I determine what's wrong in the XAMPP set up and configuration? Or how do I determine what's wrong in my code that messes up XAMPP? –  Shawn Sep 24 '09 at 16:18
2  
@Shawn, what about fixing that Access denied for user 'user'@'localhost' in your MySQL set up...? –  Arjan Sep 24 '09 at 16:34
    
@Shawn Arjan is right, start debugging from the line where it says you can't log into the database. Your settings are probably not the same between XAMPP and easyPHP and this includes database setup. –  random Sep 24 '09 at 22:23
    
Well, I solved the Access denied problem, now I only get the Segmentation fault (I edited my question) –  Shawn Sep 24 '09 at 23:44

I've encountered the exact same error. Make sure the mysql user privileges are set correctly.

Log in on the command line and confirm you are able to login, switch to the concerning database and view tables and records. Just login with command: 'mysql -u user -p' and fire off some queries.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.