Exec php not found

php shell_exec() permission on Linux Ubuntu

a blank page too. All these command if I type on terminal(user hu) will works. I have searched google for several hour, people says that because of permission. I don’t have experience on Linux. What do I have to do to execute my program in php?

6 Answers 6

The Apache’s user www-data need to be granted privileges to execute certain applications using sudo .

  1. Run the command sudo visudo . Actually we want to edit the file in etc/sudoers .To do that, by using sudo visudo in terminal ,it duplicate(temp) sudoers file to edit.
  2. At the end of the file, add the following ex:-if we want to use command for restart smokeping and php command for another action in your question,

www-data ALL=NOPASSWD: /etc/init.d/smokeping/restart, usr/bin/php

(This is assuming that you wish to run restart and php commands using super user (root) privileges.And you use php command in usr/bin/ path )

However, if you wish to run every application using super user privileges, then add the following instead of what’s above.You might not want to do that, not for ALL commands, very dangerous.

3.After edit the sudoers file(by visudo we edit the temp file of sudoers so save and quit temp file(visudo) to write in sudoers file.( wq! )

Читайте также:  Меню для программы python

4.That’s it, now use exec() or shell_exec in the following manner inside your xxx.php script.keep remember to use sudo before the command use in the php script.

exec ("sudo /etc/init.d/smokeping restart 2>&1"); 

So in your problem,add the commands that you wish to use in to the step no (2.) as I add and change your php script as what you want.

Try specifying the entire path to the php binary.. Eg, /usr/bin/php

If you don’t know it, find it using: which php

when you say ‘doesn’t work’ what do you get? Ie, any errors? Anything in your php/apache error logs? If the page is blank, view source give you anything to work with? Unfortunately the term ‘doesn’t work’ gives us nothing to work with.

You generally want to specify full paths to applications such as whoami , ls , and php . If you’re unsure what a program’s location is (full path) you can find out like so:

$ type php php is /usr/bin/php 

Then specify it like so in your script.

i run your command. type php => php is /usr/bin/php. but full path command still return me a blank page.

echo shell_exec(«/usr/bin/php index.php 2>&1») => /usr/bin/php: relocation error: /usr/bin/php: symbol X509_free, version OPENSSL_1.0.0 not defined in file libcrypto.so.1.0.0 with link time reference

OK, the web server (Apache) typically is running as another user, not hu . So you need to make sure that the script php is attempting to run is set like this: chmod 755 somescript.php . This will allow the user that Apache is running as, to be able to execute & read your .php file.

@ngoaho91 — everything should be fine now, that error tells me there is something wrong w/ your Apache/PHP setup. freetutorialssubmit.com/php-relocation-error/2221

Does your php.ini restrict the available command set ?

This is from my /etc/php5/php.ini

; When safe_mode is on, only executables located in the safe_mode_exec_dir ; will be allowed to be executed via the exec family of functions. ; http://php.net/safe-mode-exec-dir safe_mode_exec_dir = 

How to debug shell_exec issues

OK, here we have a problem: some thing works in terminal and does’t work in php’s shell_exec (or exec, spawn, whatever). Let’s think: what is the difference between You and php? Here are three:

PHP is executed from HTTP server rules

Indeed, Your terminal is running from yourname user and php is executed from www-data . So, first idea is to open terminal from www-data user and try same command. So.

  • Open /etc/passwd file, find line with www-data user and change it’s login shell (last one) from /bin/false (or whatever) to /bin/bash .
  • Open www-data ‘s terminal: su www-data
  • Try php -v or whatever You can’t execute from php. If it does not work — You’ll see nice logs and will be able to debug problem.
  • Do not forget to fix back /etc/passwd file while You’re done

PHP is executed from PHP.

PHP is paranoid enogh and there are a lot of options in apache/nginx and php.ini configuration which may break Your attempt.

This is a bit more complicated to debug. There are two options here:

  • Enable logs in browser and see the problem. Edit Your php.ini , turn on display_errors and all other flags to see errors in browser. They You can read and debug them.
  • Obtain www-data ‘s shell (see first section) and execute something like

which will execute same php code in console and You’ll be able to see errors and debug.

PHP is executed from SELinux/apparmor

Selinux and apparmor are security things which forbid applications to perform specific actions (for example, spawning other applications or some specific other applications). Maybe it’s enabled on Your server.

To check — disable selinux/apparmor and check if problem exists.

To fix — read appropriate manual and fix write permissive rules for Your case.

Источник

Cakephp console error cake: line 30: exec: php: not found

If you getting the cakephp console error «./cake/console/cake: line 30: exec: php: not found» its a fairly simple fix to get things going again. This error simply means that the shell console couldn’t find the PHP CLI (Command line interface), which can be installed to your Linux Debian or Ubuntu install with :-

0 Responses to “Cakephp console error cake: line 30: exec: php: not found”

Categories

Tags

Blog feed

  • Ajax (1)
  • Applet (3)
  • Bcb6 (2)
  • Bds2006 (2)
  • Borland (7)
  • C (9)
  • Cpp (16)
  • Croogo (1)
  • Css (3)
  • Debian (16)
  • Delphi (12)
  • Embarcadero (15)
  • Error (2)
  • Form (1)
  • Gimp (1)
  • Habtm (1)
  • Hardware (3)
  • Html (1)
  • Ifort (1)
  • Ionic (1)
  • Ios (2)
  • Jquery (1)
  • Mediatemple (2)
  • Mysql (3)
  • Network (1)
  • Os X (1)
  • Pagination (1)
  • Python (2)
  • Rad Studio (3)
  • Radstudio (2)
  • Redhat (3)
  • Rss (1)
  • Seo (4)
  • Setflash (1)
  • Shell (1)
  • Sitemap (1)
  • Ss (2)
  • Ubuntu (15)
  • Update2 (2)
  • Validation (1)
  • Win7 (2)
  • Xcode (1)
  • Xe (2)
  • Xe2 (4)
  • Xe5 (2)
  • Xe6 (1)
  • Xe7 (1)
  • Xe8 (8)
  • Xp (4)
  • Blog feed

Site Sections

Blog Categories

Latest

© 2008 Wilton Software Limited, designed by Brett Wilton,
dark by design wiltonsoftware.com, All rights reserved.

Источник

PHP shell_exec() Command not found

I need to execute a program using php, the file in question is ClustalW (clustalw2). My apache user is http using fish shell, so I moved clustalw2 to /srv/http/Clustal and added the dir to fish path.
If I log in into http using terminal and run clustalw2 -INFILE=input_file -OUTFILE=output_file everything works as expected.
But every time I run shell_exec(‘clustalw2 -INFILE=input_file -OUTFILE=output_file’); nothing happens and I get this error log: sh: line 1: clustalw2: command not found If I run:

"; echo "SHELL: ".shell_exec('echo "$SHELL"')."
"; echo "WHICH clustalw2: ".shell_exec('which clustalw2');

Output:
USER: http
SHELL: /usr/bin/fish
WHICH clustalw2:
If I run which clustalw2 in terminal using http user:

1 Answer 1

Your program can’t find clustalw2 because clustalw2 isn’t in the $PATH .

In your case, the easiest solution is to replace clustalw2 with the full path, /srv/http/Clustalw/clustalw2 as the first parameter to shell_exec .

You must log in to answer this question.

Hot Network Questions

Subscribe to RSS

To subscribe to this RSS feed, copy and paste this URL into your RSS reader.

Site design / logo © 2023 Stack Exchange Inc; user contributions licensed under CC BY-SA . rev 2023.7.24.43543

Linux is a registered trademark of Linus Torvalds. UNIX is a registered trademark of The Open Group.
This site is not affiliated with Linus Torvalds or The Open Group in any way.

By clicking “Accept all cookies”, you agree Stack Exchange can store cookies on your device and disclose information in accordance with our Cookie Policy.

Источник

Issue

Getting below error while running docker-compose up -d for laravel Project.

ERROR: for groshop_laravel-env_1 Cannot start service laravel-env: OCI runtime create failed: container_linux.go:370: starting container process caused: exec: "php-fpm": executable file not found in $PATH: unknown ERROR: for laravel-env Cannot start service laravel-env: OCI runtime create failed: container_linux.go:370: starting container process caused: exec: "php-fpm": executable file not found in $PATH: unknown ERROR: Encountered errors while bringing up the project. 
FROM centos:7 # Install some must-haves RUN yum -y install vim wget sendmail RUN yum -y install libtool make automake autoconf nasm libpng-static RUN yum -y install git RUN git --version # Install PHP 7.1 on CentOS RUN rpm -Uvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm \ && rpm -Uvh http://rpms.remirepo.net/enterprise/remi-release-7.rpm RUN yum install yum-utils RUN yum install epel-release RUN yum-config-manager --enable remi-php73 RUN yum --enablerepo=remi-php73 -y install php php-bcmath php-cli php-common php-gd php-intl php-ldap php-mbstring \ php-mysqlnd php-pear php-soap php-xml php-xmlrpc php-zip RUN php -v # Prepare PHP environment COPY config/php/php-fpm.conf /etc/php-fpm.conf COPY config/php/www.conf /etc/php-fpm.d/www.conf COPY config/php/php.ini /usr/local/etc/php/php.ini COPY config/php/xdebug.ini /usr/local/etc/php/conf.d/xdebug.ini # Install Composer RUN curl -sS https://getcomposer.org/installer | php RUN mv composer.phar /usr/bin/composer RUN composer --version # Install Node.js RUN curl -sL https://rpm.nodesource.com/setup_7.x | bash - RUN yum -y install nodejs RUN yum list installed nodejs RUN node -v # Final update and clean up RUN yum -y update --skip-broken RUN yum clean all # Define work directory WORKDIR /var/www/laravel-boilerplate # Expose ports EXPOSE 9000 # CMD ["php-fpm", "-F", "-O"] CMD ["php-fpm", "-F"] 

Also i have php files under config. have tried CMD line with changes but no luck. Any idea? Also one other observation i looked at is, i couldnt see those php-fpm.* files under /etc but only supervisord.conf file with below content.

[supervisord] nodaemon=true [program:php-fpm] command=/usr/sbin/php-fpm -F -R user = root autostart = true stdout_logfile=/dev/stdout stdout_logfile_maxbytes=0 stderr_logfile=/dev/stderr stderr_logfile_maxbytes=0

Solution

I cannot spot the php-fpm package being installed.

RUN yum --enablerepo=remi-php73 -y install php php-bcmath php-cli php-common php-gd php-intl php-ldap php-mbstring \ php-mysqlnd php-pear php-soap php-xml php-xmlrpc php-zip php-fpm 

Источник

Оцените статью