Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

500 internal server error

48 views
Skip to first unread message

jans

unread,
Jun 4, 2015, 5:08:31 PM6/4/15
to
I can connect to mysql through mysql workbench but my php connection script doesn't work?
I get the 500 internal server error. It seems like it must be mysql error because php_info.php works.
Mysql workbench query worked: show databases;use conduit_earth;select * from users;
My...@127.0.0.1:3306
Why do I get a 500 error?
<?php

echo '<ul>';

$db_host = "localhost";
$db_user = "root";
$db_password ="root";
$db_name = "earth";
$db_port = "3306";

$db_link = mysqli_connect($db_host.":".$port, $db_user, $db_password, $db_name);
echo $db_link;
or die ("Unable to connect");

$sqlQuery = "SELECT username,fname FROM users";

$result = mysqli_query($db_link, $sqlQuery);


if($result)
{
while ($row=mysqli_fetch_assoc($result))
{
echo "<li>" . $row['username'] . "<br>" . $row['fname'] . "</li>\n\t\t<hr>";
}
}
else
{
echo '<p>error displaying resultset</p>';
}

mysqli_close($db_link);
echo '</ul>';



?>

jans

unread,
Jun 4, 2015, 5:14:00 PM6/4/15
to
On Thursday, June 4, 2015 at 2:08:31 PM UTC-7, jans wrote:
Does this mean that it isn't TCP/IP it is socket?
150604 13:01:15 [Note] /Applications/MAMP/Library/bin/mysqld: ready for connections.
Version: '5.5.42' socket: '/Applications/MAMP/tmp/mysql/mysql.sock' port: 3306 Source distribution
does

Richard Yates

unread,
Jun 4, 2015, 5:21:08 PM6/4/15
to
On Thu, 4 Jun 2015 14:06:42 -0700 (PDT), jans <janis...@gmail.com>
wrote:
$db_link is a resource. You cannot echo it. Delete that line.

'or die ("Unable to connect");' is not a valid php statement. Your
script is probably terminating there and giving you the 500 error.

Try (all one line):

$db_link = mysqli_connect($db_host.":".$port, $db_user, $db_password,
$db_name) or die ("Unable to connect");

Christoph M. Becker

unread,
Jun 4, 2015, 5:21:57 PM6/4/15
to
jans wrote:

> I can connect to mysql through mysql workbench but my php connection script doesn't work?
> I get the 500 internal server error. It seems like it must be mysql error because php_info.php works.
> Mysql workbench query worked: show databases;use conduit_earth;select * from users;
> My...@127.0.0.1:3306
> Why do I get a 500 error?

Check your error logs. (I'm assuming that PHP is configured to write
errors and warnings to a log file.)

> <?php
>
> echo '<ul>';
>
> $db_host = "localhost";
> $db_user = "root";
> $db_password ="root";
> $db_name = "earth";
> $db_port = "3306";
>
> $db_link = mysqli_connect($db_host.":".$port, $db_user, $db_password, $db_name);
> echo $db_link;
> or die ("Unable to connect");

This is a syntax error.

Also see <http://php.net/manual/en/>.

--
Christoph M. Becker

jans

unread,
Jun 4, 2015, 5:37:48 PM6/4/15
to
On Thursday, June 4, 2015 at 2:08:31 PM UTC-7, jans wrote:
Okay thanks, I see the syntax error, Sorry for the trouble now I think it is an internal configuration error I am still getting a blank web page but now I know everything appears to be working except my code I guess :-(.

jans

unread,
Jun 4, 2015, 5:43:08 PM6/4/15
to
On Thursday, June 4, 2015 at 2:37:48 PM UTC-7, jans wrote:

does this mean something in apache?

[Thu Jun 04 13:01:14 2015] [notice] Digest: done
[Thu Jun 04 13:01:14 2015] [notice] FastCGI: process manager initialized (pid 26829)
[Thu Jun 04 13:01:14 2015] [notice] Apache/2.2.29 (Unix) mod_wsgi/3.4 Python/2.7.8 PHP/5.3.14 mod_ssl/2.2.29 OpenSSL/0.9.8za DAV/2 mod_fastcgi/2.4.6 mod_perl/2.0.8 Perl/v5.20.0 configured -- resuming normal operations
[Thu Jun 04 14:16:45 2015] [notice] caught SIGTERM, shutting down
[Thu Jun 04 14:24:03 2015] [notice] Digest: generating secret for digest authentication ...
[Thu Jun 04 14:24:03 2015] [notice] Digest: done
[Thu Jun 04 14:24:03 2015] [notice] FastCGI: process manager initialized (pid 29315)
[Thu Jun 04 14:24:04 2015] [notice] Apache/2.2.29 (Unix) mod_wsgi/3.4 Python/2.7.8 PHP/5.3.14 mod_ssl/2.2.29 OpenSSL/0.9.8za DAV/2 mod_fastcgi/2.4.6 mod_perl/2.0.8 Perl/v5.20.0 configured -- resuming normal operations

jans

unread,
Jun 4, 2015, 5:44:10 PM6/4/15
to
On Thursday, June 4, 2015 at 2:43:08 PM UTC-7, jans wrote:

this is my mysql log:
150604 14:16:45 mysqld_safe mysqld from pid file /Applications/MAMP/tmp/mysql/mysql.pid ended
150604 14:23:53 mysqld_safe Starting mysqld daemon with databases from /Library/Application Support/appsolute/MAMP PRO/db/mysql
150604 14:23:53 [Warning] Using unique option prefix key_buffer instead of key_buffer_size is deprecated and will be removed in a future release. Please use the full name instead.
150604 14:23:53 [Warning] Setting lower_case_table_names=2 because file system for /Library/Application Support/appsolute/MAMP PRO/db/mysql/ is case insensitive
150604 14:23:54 [Note] Plugin 'FEDERATED' is disabled.
150604 14:23:54 InnoDB: The InnoDB memory heap is disabled
150604 14:23:54 InnoDB: Mutexes and rw_locks use GCC atomic builtins
150604 14:23:54 InnoDB: Compressed tables use zlib 1.2.3
150604 14:23:54 InnoDB: Initializing buffer pool, size = 128.0M
150604 14:23:54 InnoDB: Completed initialization of buffer pool
150604 14:23:55 InnoDB: highest supported file format is Barracuda.
150604 14:23:57 InnoDB: Waiting for the background threads to start
150604 14:23:58 InnoDB: 5.5.42 started; log sequence number 1595675
150604 14:23:58 [Note] Server hostname (bind-address): '0.0.0.0'; port: 3306
150604 14:23:58 [Note] - '0.0.0.0' resolves to '0.0.0.0';
150604 14:23:58 [Note] Server socket created on IP: '0.0.0.0'.
150604 14:24:00 [Note] Event Scheduler: Loaded 0 events
150604 14:24:00 [Note] /Applications/MAMP/Library/bin/mysqld: ready for connections.
Version: '5.5.42' socket: '/Applications/MAMP/tmp/mysql/mysql.sock' port: 3306 Source distribution

jans

unread,
Jun 4, 2015, 6:04:06 PM6/4/15
to
On Thursday, June 4, 2015 at 2:21:57 PM UTC-7, Christoph M. Becker wrote:
It must be something simple because I can hit the page. I just get a blank page. It says 500 internal server error, because I am able to correct error messages in scripts from looking in the php log directly.

jans

unread,
Jun 4, 2015, 6:05:37 PM6/4/15
to
but I'm hitting my database and there is configurations in xml so maybe that is what is wrong .

Richard Yates

unread,
Jun 4, 2015, 7:03:57 PM6/4/15
to
Two people have told you that there is a php syntax error in the code
you posted.
Have you corrected that error?
If you have corrected it, post the corrected code.

On Thu, 4 Jun 2015 15:04:02 -0700 (PDT), jans <janis...@gmail.com>
wrote:

jans

unread,
Jun 4, 2015, 7:17:54 PM6/4/15
to
On Thursday, June 4, 2015 at 4:03:57 PM UTC-7, Richard Yates wrote:
<?php

echo '<ul>';

$db_host = "localhost";
$db_user = "root";
$db_password ="root";
$db_name = "conduit_earth";
$db_port = "3306";

$db_link = mysqli_connect($db_host, $db_user, $db_password, $db_name) or die ("Unable to connect") . mysqli_error($link);


$sqlQuery = "SELECT username,fname FROM users";

$result = mysqli_query($db_link, $sqlQuery);


if($result)
{
while ($row=mysqli_fetch_assoc($result))
{
echo "<li>" . $row['username'] . "<br>" . $row['fname'] . "</li>\n\t\t<hr>";
}
}
else
{
echo '<p>error displaying resultset</p>';
}

mysqli_close($db_link);
echo '</ul>';



?>

it works,

Christoph M. Becker

unread,
Jun 4, 2015, 7:45:01 PM6/4/15
to
jans wrote:

Please do not top-post. That makes it hard to follow the discussion,
and even harder to reply sensibly.

> $db_link = mysqli_connect($db_host, $db_user, $db_password, $db_name) or die ("Unable to connect") . mysqli_error($link);

> it works,

Lucky you. If it didn't work, you would get no error messages from
mysqli_error(), because this function will never be called. Hint: in
PHP there is no life after dying.

--
Christoph M. Becker

Christoph M. Becker

unread,
Jun 4, 2015, 7:55:30 PM6/4/15
to
jans wrote:

> but I'm hitting my database and there is configurations in xml so
> maybe that is what is wrong .

Maybe. But what's definitely wrong, is your approach to programming.
Learning by doing is fine to a certain degree, but you need to learn
some basics by reading available documentation. And it is important to
apply analytic skills instead of guessing.

Otherwise you might finally come up with a working solution, but most
certainly that will take much longer than necessary, and you run the
risk that the solution is way more complex than necessary.

Reading and understanding
<http://stackoverflow.com/questions/845021/how-to-get-useful-error-messages-in-php>
might be helpful, for a start.

--
Christoph M. Becker

jans

unread,
Jun 5, 2015, 9:31:20 PM6/5/15
to
thanks, I did have it on but had to reinstall the server and it was left off. Thanks for the links. Question:
my log seems to have died at 4:00. I think I was getting too many repeated errors so I turned on ignore_repeated_errors = On
I also turned on ignore_repeated_source= ON
Turning them back Off hasn't restored the log.

All of my error settings in php.ini
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; Error handling and logging ;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

; error_reporting is a bit-field. Or each number up to get desired error
; reporting level
; E_ALL - All errors and warnings
; E_ERROR - fatal run-time errors
; E_WARNING - run-time warnings (non-fatal errors)
; E_PARSE - compile-time parse errors
; E_NOTICE - run-time notices (these are warnings which often result
; from a bug in your code, but it's possible that it was
; intentional (e.g., using an uninitialized variable and
; relying on the fact it's automatically initialized to an
; empty string)
; E_CORE_ERROR - fatal errors that occur during PHP's initial startup
; E_CORE_WARNING - warnings (non-fatal errors) that occur during PHP's
; initial startup
; E_COMPILE_ERROR - fatal compile-time errors
; E_COMPILE_WARNING - compile-time warnings (non-fatal errors)
; E_USER_ERROR - user-generated error message
; E_USER_WARNING - user-generated warning message
; E_USER_NOTICE - user-generated notice message
;
; Examples:
;
; - Show all errors, except for notices
;
error_reporting = E_ALL & ~E_NOTICE
;
; - Show only errors
;
;error_reporting = E_COMPILE_ERROR|E_ERROR|E_CORE_ERROR
;
; - Show all errors except for notices
;
error_reporting = MAMP_error_reporting_MAMP

; Print out errors (as a part of the output). For production web sites,
; you're strongly encouraged to turn this feature off, and use error logging
; instead (see below). Keeping display_errors enabled on a production web site
; may reveal security information to end users, such as file paths on your Web
; server, your database schema or other information.
display_errors = MAMP_display_errors_MAMP

; Even when display_errors is on, errors that occur during PHP's startup
; sequence are not displayed. It's strongly recommended to keep
; display_startup_errors off, except for when debugging.
display_startup_errors = MAMP_display_startup_errors_MAMP

; Log errors into a log file (server-specific log, stderr, or error_log (below))
; As stated above, you're strongly advised to use error logging in place of
; error displaying on production web sites.
log_errors = MAMP_php_log_errors_MAMP

; Set maximum length of log_errors. In error_log information about the source is
; added. The default is 1024 and 0 allows to not apply any maximum length at all.
log_errors_max_len = 1024

; Do not log repeated messages. Repeated errors must occur in same file on same
; line until ignore_repeated_source is set true.
ignore_repeated_errors = Off

; Ignore source of message when ignoring repeated messages. When this setting
; is On you will not log errors with repeated messages from different files or
; sourcelines.
ignore_repeated_source = Off


Also in Mamp Pro is set

What to log: Display statup error
All other errors
then I even tried logging the other options errors warnings and notices still nothing.

did I miss a setting or how can I get the log back? Its on a mac. Thanks,

J.O. Aho

unread,
Jun 6, 2015, 3:33:27 AM6/6/15
to
You overwrite the settings, remove the one you have added and use the
'E_ALL & ~E_NOTICE' only.


> display_errors = MAMP_display_errors_MAMP
> display_startup_errors = MAMP_display_startup_errors_MAMP
> log_errors = MAMP_php_log_errors_MAMP

Use 'On' or 'Off' as option

jans

unread,
Jun 6, 2015, 3:54:36 AM6/6/15
to
I don't understand you. Are you saying to turn off the mamp related error display settings? It does make it really confusing.
I dont' think I am getting any errors right now because I just commented out a required file in the index page and I didn't get any errors displayed? I also read in the manual that if a script switches users then
it will not write to the error log. I deleted the error log and created another one. That has a different user. The permissions to the diredtory are 777.


; error_reporting is a bit-field. Or each number up to get desired error
; reporting level
;E_ALL - All errors and warnings
; E_ERROR - fatal run-time errors
; E_WARNING - run-time warnings (non-fatal errors)
; E_PARSE - compile-time parse errors
; E_NOTICE - run-time notices (these are warnings which often result
; from a bug in your code, but it's possible that it was
; intentional (e.g., using an uninitialized variable and
; relying on the fact it's automatically initialized to an
; empty string)
; E_CORE_ERROR - fatal errors that occur during PHP's initial startup
; E_CORE_WARNING - warnings (non-fatal errors) that occur during PHP's
; initial startup
; E_COMPILE_ERROR - fatal compile-time errors
; E_COMPILE_WARNING - compile-time warnings (non-fatal errors)
; E_USER_ERROR - user-generated error message
; E_USER_WARNING - user-generated warning message
; E_USER_NOTICE - user-generated notice message
;
; Examples:
;
; - Show all errors, except for notices
;
error_reporting = E_ALL & ~E_NOTICE & ~E_STRICT & ~E_DEPRECATED
;
; - Show only errors
;
;error_reporting = E_COMPILE_ERROR|E_ERROR|E_CORE_ERROR
;
; - Show all errors except for notices
;
error_reporting = MAMP_error_reporting_MAMP

; Print out errors (as a part of the output). For production web sites,
; you're strongly encouraged to turn this feature off, and use error logging
; instead (see below). Keeping display_errors enabled on a production web site
; may reveal security information to end users, such as file paths on your Web
; server, your database schema or other information.
display_errors = MAMP_display_errors_MAMP

; Even when display_errors is on, errors that occur during PHP's startup
; sequence are not displayed. It's strongly recommended to keep
; display_startup_errors off, except for when debugging.
display_startup_errors = MAMP_display_startup_errors_MAMP

; Log errors into a log file (server-specific log, stderr, or error_log (below))
; As stated above, you're strongly advised to use error logging in place of
; error displaying on production web sites.
log_errors = MAMP_php_log_errors_MAMP

; Set maximum length of log_errors. In error_log information about the source is
; added. The default is 1024 and 0 allows to not apply any maximum length at all.
log_errors_max_len = 1024

; Do not log repeated messages. Repeated errors must occur in same file on same
; line until ignore_repeated_source is set true.
ignore_repeated_errors = Off

; Ignore source of message when ignoring repeated messages. When this setting
; is On you will not log errors with repeated messages from different files or
; sourcelines.
ignore_repeated_source = Off

; If this parameter is set to Off, then memory leaks will not be shown (on
; stdout or in the log). This has only effect in a debug compile, and if
; error reporting includes E_WARNING in the allowed list
report_memleaks = On

; Store the last error/warning message in $php_errormsg (boolean).
track_errors = On

jans

unread,
Jun 6, 2015, 3:59:15 AM6/6/15
to
On Saturday, June 6, 2015 at 12:33:27 AM UTC-7, J.O. Aho wrote:
Is this what you meant?
Its still not working. I dont' want to hose my Mamp Pro.

; error_reporting is a bit-field. Or each number up to get desired error
; reporting level
;E_ALL - All errors and warnings
; E_ERROR - fatal run-time errors
; E_WARNING - run-time warnings (non-fatal errors)
; E_PARSE - compile-time parse errors
; E_NOTICE - run-time notices (these are warnings which often result
; from a bug in your code, but it's possible that it was
; intentional (e.g., using an uninitialized variable and
; relying on the fact it's automatically initialized to an
; empty string)
; E_CORE_ERROR - fatal errors that occur during PHP's initial startup
; E_CORE_WARNING - warnings (non-fatal errors) that occur during PHP's
; initial startup
; E_COMPILE_ERROR - fatal compile-time errors
; E_COMPILE_WARNING - compile-time warnings (non-fatal errors)
; E_USER_ERROR - user-generated error message
; E_USER_WARNING - user-generated warning message
; E_USER_NOTICE - user-generated notice message
;
; Examples:
;
; - Show all errors, except for notices
;
error_reporting = E_ALL & ~E_NOTICE & ~E_STRICT & ~E_DEPRECATED
;
; - Show only errors
;
;error_reporting = E_COMPILE_ERROR|E_ERROR|E_CORE_ERROR
;
; - Show all errors except for notices
;
error_reporting = On

; Print out errors (as a part of the output). For production web sites,
; you're strongly encouraged to turn this feature off, and use error logging
; instead (see below). Keeping display_errors enabled on a production web site
; may reveal security information to end users, such as file paths on your Web
; server, your database schema or other information.
display_errors = On

; Even when display_errors is on, errors that occur during PHP's startup
; sequence are not displayed. It's strongly recommended to keep
; display_startup_errors off, except for when debugging.
display_startup_errors = On

; Log errors into a log file (server-specific log, stderr, or error_log (below))
; As stated above, you're strongly advised to use error logging in place of
; error displaying on production web sites.
log_errors = On

; Set maximum length of log_errors. In error_log information about the source is
; added. The default is 1024 and 0 allows to not apply any maximum length at all.
log_errors_max_len = 1024

; Do not log repeated messages. Repeated errors must occur in same file on same
; line until ignore_repeated_source is set true.
ignore_repeated_errors = Off

; Ignore source of message when ignoring repeated messages. When this setting
; is On you will not log errors with repeated messages from different files or
; sourcelines.
ignore_repeated_source = Off

; If this parameter is set to Off, then memory leaks will not be shown (on
; stdout or in the log). This has only effect in a debug compile, and if
; error reporting includes E_WARNING in the allowed list
report_memleaks = On

; Store the last error/warning message in $php_errormsg (boolean).
track_errors = On

; Disable the inclusion of HTML tags in error messages.
;html_errors = Off

J.O. Aho

unread,
Jun 6, 2015, 10:13:28 AM6/6/15
to
On 06/06/15 09:59, jans wrote:

> Is this what you meant?

Yes

> Its still not working.


Did you restart the web server service after you changed?

Are you sure you are editing the php.ini which is used?

jans

unread,
Jun 6, 2015, 10:20:49 AM6/6/15
to
Hey good morning thanks I was going to reinstall mamp then I just tried reinstall the mamp php version i need didn't help the log. THen I was going to uninstall mamp pro but it suggested I just revert back to factory settings. I tried that and it worked. I was reading in the manual and I think what happened is when you write to the log from another user then it never writes to the log again. Not sure how I changed users but I think that is what happened. It would not write to the log or display errors.
It could be a setting was off but I had them all turned on. In any case it works now.

jans

unread,
Jun 6, 2015, 10:21:23 AM6/6/15
to
yes I edited both php.ini's .

jans

unread,
Jun 6, 2015, 10:21:57 AM6/6/15
to
handy feature in Mamp pro. Worth the 60.00.

J.O. Aho

unread,
Jun 6, 2015, 4:45:23 PM6/6/15
to
Writing is always done as the user as the service is run and in Unix you
usually have a service start/stop script, using the script will tend to
see to that you don't run the service as the wrong user.

--

//Aho

0 new messages