C file execution

Hello guys, i have a executable c file in desktop and i wanted to execute it through php, i tried to do exec(‘./Get_eigenvalue’); but nothing happened. Suppose it will light it up my bulb. help me pls.

You cannot execute raw C source files, you must first compile it to an executable.

Already and still cannot.

Does the executable work, when you run it outside of PHP?

Yes.

Does it require any type of permissions? As if you run it from PHP, it will run as the executing Apache user (assuming you run it from a webpage) who might not have the appropriate privileges to execute the commands the program is trying to issue.

Try running it from the command line:
php.exe -f “your_file.php”

Try run this "php.exe -f “your_file.php” " in the terminal? No php.exe command found.

No permission needed. I can run it with or without being root.

Ah, so you are on a linux machine? Okay, then it would be php -f “your_file.php”

Just because you are not root, doesn’t mean you don’t require specific permissions. Remember that apache will usually run under www-data and that is a VERY limited account.

It worked! but how do i execute in apache?

Okay, so first thing is to identify what user apache is running as.
ps aux | grep apache

Then you need to compare the groups your user is in, to the groups apache is in.
groups <your_username>
groups <apache_username>

One of those groups is likely required to be added to the apache username for this to work. Did you have to add yourself to a group to be able to run this program?

This is the result:
axmarvin@ubuntu:~/public_html/FYP$ ps aux | grep apache
root 1120 0.0 0.2 228164 9508 ? Ss Apr16 0:00 /usr/sbin/apache2 -k start
www-data 1138 0.0 0.1 228652 7612 ? S Apr16 0:00 /usr/sbin/apache2 -k start
www-data 1139 0.0 0.1 228188 5596 ? S Apr16 0:00 /usr/sbin/apache2 -k start
www-data 1140 0.0 0.1 228188 5596 ? S Apr16 0:00 /usr/sbin/apache2 -k start
www-data 1141 0.0 0.1 228188 5596 ? S Apr16 0:00 /usr/sbin/apache2 -k start
www-data 1142 0.0 0.1 228188 5596 ? S Apr16 0:00 /usr/sbin/apache2 -k start
www-data 3804 0.0 0.1 228188 5596 ? S Apr16 0:00 /usr/sbin/apache2 -k start

But, how do i add myself to a group that you mention above?

okay, so www-data is definitely the user that apache runs under.

Did you run the two groups statements?
groups <your_username_here>
groups www-data

what is the output of each of those?

axmarvin@ubuntu:~/public_html/FYP$ groups axmarvin
axmarvin : axmarvin adm dialout cdrom sudo dip plugdev lpadmin sambashare
axmarvin@ubuntu:~/public_html/FYP$ groups www-data
www-data : www-data

okay, if I had to guess, dialout may be the group www-data needs (as that group is required for serial ports, ppp, and isdn).

so sudo usermod -a -G dialout www-data

Then you need to restart apache.

IT WORKS! now i can execute the file in apache! Thanks alot cpradio! ^^

Cool. Now to settle my curiosity, can you tell us about this project in a bit more detail? The hardware/software you are using?

The hardware i’m using is a Fingerprint UART and the software that i used to communicate is Cutecom (linux), but i also use C code to communicate with the hardware and i need to make a GUI using php. That’s why i need to execute some of the executable C file in the PHP. ^^, Thanks alot with your help.

Not a problem :slight_smile: Thanks for the explanation, sounds like a neat project

This is just a small part of it. ^^, anyway, i’ll update here if there’s any problem i faced. Now i know where to find a pro. peace ^^

Hello bro, now i’ve encounter new problem, i have a data in database(mysql) which looks like below:

f5 00 00 00 29 05 15 52 41 07 a3 d4 21 0d b6 19 61 10 31 40 81 17 12 e8 c1 19 b1 99 21 1a a1 29 c1 29 32 da e1 2a 91 d1 e1 2e 08 e7 21 2f 35 43 61 32 94 27 c1 3a 99 93 21 3c a8 16 01 3e af c2 41 3f bd 87 61 4b 2b 19 c1 50 89 24 61 54 a7 1a 41 59 22 26 21 5a a9 5f a1 5c 25 e5 61 62 a5 e4 61 65 35 21 21 6f 2d e3 01 7b 1d 29 21 13 1b e9 a2 17 15 52 42 1c 99 53 22 1d 09 51 e2 2b a8 d5 62 39 0c 90 82 40 36 5d 82 47 9b e7 62 56 13 8e c2 57 99 50 c2 62 aa 21 c2 65 0c e3 22 6a 91 20 82 79 95 d5 02 7f 94 c7 62 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 27 f5

and now i need to put the data into .txt file using php. is that possible?