Welcome to the most active Linux Forum on the web.
Go Back > Forums > Linux Forums > Linux - Software
User Name
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.


  Search this Thread
Old 02-07-2005, 03:01 PM   #1
LQ Newbie
Registered: Jun 2004
Location: Boise ID
Posts: 4

Rep: Reputation: 0
Executing C program within PHP to Acces low level I/O

I am using a Embedded System form Technologic. It is a 586 micro with Compact Flash memory and some Diigital I/O. The OS is Linux and it has a Apache Server running on it. My goal is to write some C code that controls the Digital I/O on the card. To control the I/O on the card the outb commands must be used. I want the C program to be launched by the Web Server in some PHP code. Then I can control the Digital I/O through a web page.

Here is a summary of what I have done.

I wrote a simple C program that takes some command line arguments and
based on the arguments it prints some text. I placed the C exe in the PHP
passthru function. It works great!

I then add the ioperm function so that I can get access the the low level address so that I can write to the digital port. I ran the program again and I had no erorrs.

I then put in outb command and ran it again. The message I got from PHP
was "Error getting access 255"

(rnningthe program outside PHP does not cause any errors)

I do not know what this means and I have searched for day. I found some reference to the Web server.

I then looked ath the Apache Error_Log file and found the following message.

Timestamp... [Warn} pid file /var/www/logs/ overwritten
Unclean shutdown of previous apache run?

Timestamp... [Notice] Apache / 1.3.24 (Unix) PHP / 4.1.2 resuming normal operation

Timestamp... [Accept] mutex : sysvsem Default : Sysvem

It appears my outb is making the server reboot?

The C program runns fine when it is not on the passthru functions so I feel the C program is good.

My next troubleshooting step is to change the Apache Server config file to log errors with the debug ditrective and see what it might say.

Any ideas would be helpful.

Thank you,
Old 02-08-2005, 01:45 PM   #2
LQ Newbie
Registered: Jun 2004
Location: Boise ID
Posts: 4

Original Poster
Rep: Reputation: 0
Here is some additional information, C program, PHP program and my Makefile

You were right about the server rebooting. I did some testing last night and determined that an error does not occur in the error_log file when I run my exe. In fact the data I sent you was the normal logging that occurs when the server boots up. I checked the time stamps and they match the time I started the system.


#Make file for helloweb.c
helloweb.o: helloweb.c
gcc -O -march=i386 -mcpu=i386 helloweb.c

C - File = hiweb.c

//Rob's Linux System Version 1.0
//Serial Based System with Ethernet Interface and Control

#include "sys/io.h" //Used for low level io
#include "stdio.h" //
#include "stdlib.h" //
#include "string.h" //
#include "strings.h" //

void show_args( char *arguments);

int main(int argc, char *argv[])
int Test;
int count;

//int iarg;
int result;

//Get permission to use the low level io
printf("Error getting access\n");
return -1;

//Write to port

printf("Rob's Linux System! Ver. 1.0\n");
printf("Web Based Test!\n");

printf("How many? %d\n",argc);

char *cmd1 = argv[1];
char *cmd2 = argv[2];

//Process the first argument
if(cmd1[0] == 'S')
printf("Found the Set Command!\n");
if(cmd1[0] == 'C')
printf("Found the Clear Command!\n");

//Process the second argument
if(cmd2[0] == '1')
printf("Found the Bit1!\n");

return 3;

} //End of main

void show_args( char *argument)
printf( "%s\n",argument );

**********PHP File calls hiweb.exe

<TITLE>Robs Technologic Systems' Embedded Web Server</TITLE>

echo '<table border="2"> <trd> <td> Robs Web Page System </td> <td> Server Addr
ess is ';
echo $SERVER_ADDR .'</td> </table>'; //$SERVER_ADDR is a special variable ref
ering to the server's addy
echo '<br> <br>';
echo "<br> <br>";
echo "The time is: ";
echo date('h:i:s');
echo '<br>';
echo "$unixtime";

echo '<br>';

echo "Running external file";
echo '<br>';

echo passthru('./hiweb.exe s 1',$passval);
echo $passval;

echo '<br>';
echo '<br>';
$result = exec('./ffile.exe');
echo $result;

//read file
$whattoread=@fopen($file1,"r") or die("Could not read file");
echo $filecontains;

echo '<a href="ps.php"> Link to another php file

//let's do some logic stuff
if ($see_stuff == "No" OR "Yes")
//see, we can also use printf ()
printf ("<form action=\"%s\" method=\"post\">", $PHP_SELF );
//special system variable, refering to self

//or we can stick to using echo..enclosing strings with either " or with '
echo "Would you like to set bit one high?";
echo '<input type="submit" name="see_stuff" value="Yes">';
echo '<input type="submit" name="see_stuff" value="No">';

if ($see_stuff == "No")

if ($see_stuff == "Yes")


Old 02-16-2005, 12:26 PM   #3
LQ Newbie
Registered: Jun 2004
Location: Boise ID
Posts: 4

Original Poster
Rep: Reputation: 0
Additional testing and some answers!

Here is an update.

The problem is related to the ioperm function. It is falling because the
Apache Server is logged as "nobody". The ioperm requires root privileges!

I did some research on the net and found that I needed to change the httpid.conf
file in Apache to have the root loggin.

I found the file and changed the user from nobody to root. I had to restart Apache
to reload the config file. Now the browser can not connect to the Apache server. I
am getting an Alert Message of "The connecton was refused when attempting to connect"

Well, I will have to figure out what else needs to be changed in Apache to allow it
to run as root. It is not as easy as changing the Directive user to root.

Thank you
Old 02-28-2005, 12:26 PM   #4
LQ Newbie
Registered: Jun 2004
Location: Boise ID
Posts: 4

Original Poster
Rep: Reputation: 0
A solution has been found!

After many hours of research I found the solution. If I use the Chmod command on the executable with the +s option the Apache Server can call the file without any problems.

I now can call any executable using the passthru function as long as I chmod +s the file first. I learned not to mess with the Apache's configuration file to allow the user "nobody" full root access rights.

It is great when things work.

Thank you

Rob Cohen


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
How executing c program with php? payal_shah Programming 6 04-08-2005 11:44 PM
low level languages devit Programming 2 05-07-2004 12:16 PM
Low level formatting.... Santorres Linux - General 1 02-02-2004 08:50 AM
low level formating sanjith11 Linux - Hardware 3 12-30-2003 08:31 AM
low level formatting? hyperpimp Linux - Newbie 16 04-13-2002 01:35 AM > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 01:31 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration