SitePoint Sponsor

User Tag List

Page 1 of 2 12 LastLast
Results 1 to 25 of 43
  1. #1
    SitePoint Zealot
    Join Date
    Jan 2013
    Posts
    110
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    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.

  2. #2
    . shoooo... silver trophy logic_earth's Avatar
    Join Date
    Oct 2005
    Location
    CA
    Posts
    9,013
    Mentioned
    8 Post(s)
    Tagged
    0 Thread(s)
    You cannot execute raw C source files, you must first compile it to an executable.
    Logic without the fatal effects.
    All code snippets are licensed under WTFPL.


  3. #3
    SitePoint Zealot
    Join Date
    Jan 2013
    Posts
    110
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by logic_earth View Post
    You cannot execute raw C source files, you must first compile it to an executable.
    Already and still cannot.

  4. #4
    Hosting Team Leader silver trophybronze trophy
    cpradio's Avatar
    Join Date
    Jun 2002
    Location
    Ohio
    Posts
    5,122
    Mentioned
    152 Post(s)
    Tagged
    0 Thread(s)
    Does the executable work, when you run it outside of PHP?

  5. #5
    SitePoint Zealot
    Join Date
    Jan 2013
    Posts
    110
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by cpradio View Post
    Does the executable work, when you run it outside of PHP?
    Yes.

  6. #6
    Hosting Team Leader silver trophybronze trophy
    cpradio's Avatar
    Join Date
    Jun 2002
    Location
    Ohio
    Posts
    5,122
    Mentioned
    152 Post(s)
    Tagged
    0 Thread(s)
    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"

  7. #7
    SitePoint Zealot
    Join Date
    Jan 2013
    Posts
    110
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by cpradio View Post
    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.

  8. #8
    Hosting Team Leader silver trophybronze trophy
    cpradio's Avatar
    Join Date
    Jun 2002
    Location
    Ohio
    Posts
    5,122
    Mentioned
    152 Post(s)
    Tagged
    0 Thread(s)
    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.

  9. #9
    SitePoint Zealot
    Join Date
    Jan 2013
    Posts
    110
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by cpradio View Post
    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?

  10. #10
    Hosting Team Leader silver trophybronze trophy
    cpradio's Avatar
    Join Date
    Jun 2002
    Location
    Ohio
    Posts
    5,122
    Mentioned
    152 Post(s)
    Tagged
    0 Thread(s)
    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?

  11. #11
    SitePoint Zealot
    Join Date
    Jan 2013
    Posts
    110
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by cpradio View Post
    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?

  12. #12
    Hosting Team Leader silver trophybronze trophy
    cpradio's Avatar
    Join Date
    Jun 2002
    Location
    Ohio
    Posts
    5,122
    Mentioned
    152 Post(s)
    Tagged
    0 Thread(s)
    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?

  13. #13
    SitePoint Zealot
    Join Date
    Jan 2013
    Posts
    110
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by cpradio View Post
    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

  14. #14
    Hosting Team Leader silver trophybronze trophy
    cpradio's Avatar
    Join Date
    Jun 2002
    Location
    Ohio
    Posts
    5,122
    Mentioned
    152 Post(s)
    Tagged
    0 Thread(s)
    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.

  15. #15
    SitePoint Zealot
    Join Date
    Jan 2013
    Posts
    110
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by cpradio View Post
    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! ^^

  16. #16
    Hosting Team Leader silver trophybronze trophy
    cpradio's Avatar
    Join Date
    Jun 2002
    Location
    Ohio
    Posts
    5,122
    Mentioned
    152 Post(s)
    Tagged
    0 Thread(s)
    Cool. Now to settle my curiosity, can you tell us about this project in a bit more detail? The hardware/software you are using?

  17. #17
    SitePoint Zealot
    Join Date
    Jan 2013
    Posts
    110
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by cpradio View Post
    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.

  18. #18
    Hosting Team Leader silver trophybronze trophy
    cpradio's Avatar
    Join Date
    Jun 2002
    Location
    Ohio
    Posts
    5,122
    Mentioned
    152 Post(s)
    Tagged
    0 Thread(s)
    Not a problem Thanks for the explanation, sounds like a neat project

  19. #19
    SitePoint Zealot
    Join Date
    Jan 2013
    Posts
    110
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by cpradio View Post
    Not a problem 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 ^^

  20. #20
    SitePoint Zealot
    Join Date
    Jan 2013
    Posts
    110
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by cpradio View Post
    Not a problem Thanks for the explanation, sounds like a neat project
    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?

  21. #21
    Hosting Team Leader silver trophybronze trophy
    cpradio's Avatar
    Join Date
    Jun 2002
    Location
    Ohio
    Posts
    5,122
    Mentioned
    152 Post(s)
    Tagged
    0 Thread(s)
    should be able to, it looks to be just ascii text.

    So you'd connect to the database, read the data, and use file_put_contents() to write the data to a file.

  22. #22
    SitePoint Zealot
    Join Date
    Jan 2013
    Posts
    110
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by cpradio View Post
    should be able to, it looks to be just ascii text.

    So you'd connect to the database, read the data, and use file_put_contents() to write the data to a file.
    Ok thanks! ^^

  23. #23
    SitePoint Zealot
    Join Date
    Jan 2013
    Posts
    110
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by cpradio View Post
    should be able to, it looks to be just ascii text.

    So you'd connect to the database, read the data, and use file_put_contents() to write the data to a file.
    Hello, another problem. When i compile my program using terminal, a txt file will be generated to store the output and it worked, but when i exc the c file in php, the txt file is not generated. why is that?

    p/s: i put all my file inside public_html

  24. #24
    Hosting Team Leader silver trophybronze trophy
    cpradio's Avatar
    Join Date
    Jun 2002
    Location
    Ohio
    Posts
    5,122
    Mentioned
    152 Post(s)
    Tagged
    0 Thread(s)
    what are the rights of the folder that needs to contain the output? Can www-data write to it? As that is what your C program will be running under so you may need to allow the folder to be writeable by that user

  25. #25
    SitePoint Zealot
    Join Date
    Jan 2013
    Posts
    110
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by cpradio View Post
    what are the rights of the folder that needs to contain the output? Can www-data write to it? As that is what your C program will be running under so you may need to allow the folder to be writeable by that user
    I only know that when i use terminal to execute it, it will work.
    "Can www-data write to it?", how to check this?
    "what are the rights of the folder that needs to contain the output?" , u mean the folder permission?


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •