Jump to content

Problem With Cgi Executable Using Mysql C Api


Recommended Posts

Hello, Everyone.

 

I'm having problems with my CGI executable on my site. It gives HTTP 500 Internal Server Error while I have no access to any detailed logs to be able to troubleshoot the problem. It works well on my computer.

 

The permissions of the file are set correctly (755). And another "Hello, World!" CGI program works perfectly on the server. It seems to me that this is a linking issue.

 

Here are the details of the executable:

 

 

The executable is linked with the following libraries:

Statically:

libmysqlclient.a - Version 5.6.12

 

Dynamically:

linux-vdso.so.1 => (0x00007fffde5ff000)

libdl.so.2 => /lib64/libdl.so.2 (0x0000003b48200000)

libpthread.so.0 => /lib64/libpthread.so.0 (0x0000003b48600000)

librt.so.1 => /lib64/librt.so.1 (0x0000003b48a00000)

libstdc++.so.6 => /lib64/libstdc++.so.6 (0x0000003b54600000)

libm.so.6 => /lib64/libm.so.6 (0x0000003b48e00000)

libgcc_s.so.1 => /lib64/libgcc_s.so.1 (0x0000003b4c600000)

libc.so.6 => /lib64/libc.so.6 (0x0000003b47e00000)

/lib64/ld-linux-x86-64.so.2 (0x0000003b47a00000)

 

Source Code:

#include <iostream>
#include <mysql.h>
using namespace std;

const string CRLF = "\r\n";

int main()
{
cout << "Content-Type: text/plain" << CRLF << CRLF;
cout << "Hello, World!" << CRLF;

try
{
 cout << "MySQL Client Version: " << mysql_get_client_info() << CRLF;
}

catch(exception& ex)
{
 cout << "ERROR: " << ex.what() << CRLF;
}

return 0;
}

 

Compiled Using: gcc 4.7 with the following specifications:

COLLECT_GCC=g++

COLLECT_LTO_WRAPPER=/usr/libexec/gcc/x86_64-redhat-linux/4.7.0/lto-wrapper

Target: x86_64-redhat-linux

Configured with: ../configure --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --with-bugurl=http://bugzilla.redhat.com/bugzilla --enable-bootstrap --enable-shared --enable-threads=posix --enable-checking=release --disable-build-with-cxx --disable-build-poststage1-with-cxx --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-gnu-unique-object --enable-linker-build-id --with-linker-hash-style=gnu --enable-languages=c,c++,objc,obj-c++,java,fortran,ada,go,lto --enable-plugin --enable-initfini-array --enable-java-awt=gtk --disable-dssi --with-java-home=/usr/lib/jvm/java-1.5.0-gcj-1.5.0.0/jre --enable-libgcj-multifile --enable-java-maintainer-mode --with-ecj-jar=/usr/share/java/eclipse-ecj.jar --disable-libjava-multilib --with-ppl --with-cloog --with-tune=generic --with-arch_32=i686 --build=x86_64-redhat-linux

Thread model: posix

gcc version 4.7.0 20120507 (Red Hat 4.7.0-5) (GCC)

 

Makefile:

#Variables:
INCLUDE_DIR = -I/usr/local/mysql/include
LIBS_DIR = -L/usr/local/lib64
STATIC_LIBS = -lmysqlclient
DYNAMIC_LIBS = -ldl -lpthread -lrt

STATIC_LINK_FLAG = -Wl,-Bstatic
DYNAMIC_LINK_FLAG = -Wl,-Bdynamic

LD_FLAGS = $(LIBS_DIR) $(STATIC_LINK_FLAG) $(STATIC_LIBS) $(DYNAMIC_LINK_FLAG) $(DYNAMIC_LIBS)

#Rules:
test.cgi: test.cpp
g++ test.cpp $(INCLUDE_DIR) $(LD_FLAGS) -o test.cgi

Link to comment
Share on other sites

I see you have java enabled in your configuration command. You'll need to have a Java-enabled account on Johnny to use Java. Since you aren't using it in your script, try configuring without any Java options enabled.

Link to comment
Share on other sites

I see you have java enabled in your configuration command. You'll need to have a Java-enabled account on Johnny to use Java. Since you aren't using it in your script, try configuring without any Java options enabled.

 

This has nothing to do with Java. It shows the configuration used when building GCC. I wrote it here so you know that the compiler target is x86_64-redhat-linux. The CGI application is a native executable file and not a JAR or Java Bytecode file.

Link to comment
Share on other sites

HelioHost provides minimal logging to reduce server load. Unfortunately, we do not provide anything beyond what is available in cPanel and any error_log files you may find in your script directories. The best way to get meaningful logs is by testing locally.

Link to comment
Share on other sites

Try to do the following which may resolve your issue:

1.Reload the web page.

2. Please clear your web cache.

If there's a problem with the cached version of the page you're viewing, it could be causing HTTP 500 issues

.

 

Try to do the following which may resolve your issue (Contd.):

3.

Troubleshoot as a

504 Gateway Timeout

error instead.

Link to comment
Share on other sites

Try using this as a source file:

 

#include <iostream>
#include <mysql/mysql.h>
using namespace std;

int main()
{
cout << "Content-Type: text/plain\n\n";
cout << "Hello, World!\n";

try
{
 cout << "MySQL Client Version: " << mysql_get_client_info() << endl ;
}

catch(exception& ex)
{
 cout << "ERROR: " << ex.what() << endl;
}

return 0;
}

 

and compile it on the server using a cronjob with the command:

 

g++ -o /home/<user>/public_html/cgi-bin/test.cgi /home/<user>/path/to/test.cpp -lmysqlclient

 

Be sure to set the cronjob to run only once a day and then delete it, also make sure it's set to run several minutes into the future and set using PDT as a guide since that's the server's time zone.

  • Like 1
Link to comment
Share on other sites

Try using this as a source file:

 

#include <iostream>
#include <mysql/mysql.h>
using namespace std;

int main()
{
cout << "Content-Type: text/plain\n\n";
cout << "Hello, World!\n";

try
{
 cout << "MySQL Client Version: " << mysql_get_client_info() << endl ;
}

catch(exception& ex)
{
 cout << "ERROR: " << ex.what() << endl;
}

return 0;
}

 

and compile it on the server using a cronjob with the command:

 

g++ -o /home/<user>/public_html/cgi-bin/test.cgi /home/<user>/path/to/test.cpp -lmysqlclient

 

Be sure to set the cronjob to run only once a day and then delete it, also make sure it's set to run several minutes into the future and set using PDT as a guide since that's the server's time zone.

 

Thanks Shinryuu. It worked. So when I first linked it "dynamically" against libmysqlclient it didn't work on your servers because I have MySQL Client Version 5.5.32 while you have MySQL Client Version 5.1.56?

 

Is there any option to install additional shared libraries on my site if I want to?

Link to comment
Share on other sites

No, your main problem was you were using the wrong line endings, that's a common issue with CGI, also if you want to do executables it's best to compile it on the server so you can rule out compilation issues. Just remember cron is limited in use per day. You could probably add shared libraries if you tried adding them using the full path, I haven't tried it though. Another thing to point out is that on our servers

#include <mysql.h>

broke because

/usr/lib/mysql/*

isn't in the compiler's search path, which is why I changed that to

#include <mysql/mysql.h>

.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...