Posts: 242
Joined: Wed Mar 07, 2012 8:35 am

Apache2/PHP problem

Fri Apr 26, 2013 5:40 pm

I've been trying to follow along with the LAMP tutorial in "Learn Raspberry Pi with Linux".

It works & produces the "PHP credits" page with
<?php phpinfo(); ?>
in index.php.

But at the next stage (logging in to the PHP database, code highlighted in the link above) there's HTTP error 500. (The mySQL username, pw, database name etc are as given, and I think the HTTP error implies Apache/PHP isn't even getting as far as logging in to the database. I've also tried with, the Hostname given in the 'PHP credits' page mentioned above.)

Any ideas what might be causing this? :?

Posts: 220
Joined: Tue Oct 09, 2012 8:13 pm

Re: Apache2/PHP problem

Sat Apr 27, 2013 9:21 pm

The 500 error is a general error - i.e. something went wrong, but not the usual expected errors.

It could be an error in the PHP script or accessing the database. Whatever it is, it is happening on the server, and you need to fix it on the server, not the browser

The Apache logs should contain more details about the error

Posts: 242
Joined: Wed Mar 07, 2012 8:35 am

Re: Apache2/PHP problem

Sun Apr 28, 2013 8:03 am

Ah - thanks. So that would be the PHP Fatal error then :oops:

Code: Select all

pi@rp1 /var/www $ tail -n 2 /var/log/apache2/error.log
[Sun Apr 28 07:30:43 2013] [error] [client] PHP Fatal error:  Class 'mysqli' not found in /var/www/index.php on line 10
[Sun Apr 28 07:30:44 2013] [error] [client] File does not exist: /var/www/favicon.ico
This is index.php, (line 10 starts with $mysqli) which I think is identical the the code from the book:

Code: Select all

<title>Much Todo!</title>
<h1>Todo List</h1>
$mysqli = new mysqli('localhost', 'pi', 'raspberry', 'pi');
if ($mysqli->connect_error) {
    die('Connect Error (' . $mysqli->connect_errorno . ') '
        . $mysqli->connect_error);
<th>Due Date</th>
$result = $mysqli->query("SELECT * FROM todolist");
while($row = $result->fetch_assoc()){
    print "<tr>";
    print "<td>".$row["description"]."</td>";
    print "<td>".$row["owner"]."</td>";
    print "<td>".$row["date"]."</td>";
    print "<td>".$row["location"]."</td>";
    print "<td>".$row["importance"]."</td>";
    print "<td>".$row["creator"]."</td>";
    print "</tr>";
I don't think it's a connection error, but I logged in to mysql manually to check:

Code: Select all

pi@rp1 /var/www $ mysql -upi -p
Enter password: <raspberry>[
Welcome to the MySQL monitor.  Commands end with ; or \g.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> SHOW databases;
| Database           |
| information_schema |
| [b]pi[/b]                 |
| test               |
3 rows in set (0.07 sec)

Return to “Networking and servers”