I'm trying to run a python script from php and it gives me this error
sh: 1: python3: not found
The php code is
exec('python3 ./myscript.py data.json 2>&1', $output);
It runs ok from the terminal, I even tried running python3 from terminal as www-data and it works
$ sudo -u www-data python3 -V
Python 3.5.3
Executing with the full path exec('/usr/local/bin/python3 ./myscript.py data.json 2>&1', $output); gives the same result.
Server SO is Debian GNU/Linux 8 (jessie) and I'm using nginx
This worked for me in an Ubuntu + apache2 environment but I don't know what I'm missing here.
I've read this but it doesn't have a solution, and also this, but all the ways to do an exec gives me the same problem.
Also the exec returns error code 127 command not found, shebang is #!/usr/bin/env python3, and if I do exec('echo $PATH') it shows /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
I need to execute the script from php or from any user interface because the user needs to upload a file and then the script executes and returns the file modified. I need that a dozen of users have access to do this without having to install an execute a python script locally.
Output of ls -l /usr/bin | grep python
lrwxrwxrwx. 1 root root 26 Jan 25 2017 dh_pypy -> ../share/dh-python/dh_pypy
-rwxr-xr-x. 1 root root 1056 Jan 24 2017 dh_python2
lrwxrwxrwx. 1 root root 29 Jan 25 2017 dh_python3 -> ../share/dh-python/dh_python3
lrwxrwxrwx. 1 root root 23 Sep 26 2018 pdb2.7 -> ../lib/python2.7/pdb.py
lrwxrwxrwx. 1 root root 23 Sep 27 2018 pdb3.5 -> ../lib/python3.5/pdb.py
lrwxrwxrwx. 1 root root 31 Jan 20 2017 py3versions -> ../share/python3/py3versions.py
lrwxrwxrwx. 1 root root 26 Jan 25 2017 pybuild -> ../share/dh-python/pybuild
lrwxrwxrwx. 1 root root 9 Jan 24 2017 python -> python2.7
lrwxrwxrwx. 1 root root 9 Jan 24 2017 python2 -> python2.7
-rwxr-xr-x. 1 root root 3779512 Sep 26 2018 python2.7
lrwxrwxrwx. 1 root root 9 Jan 20 2017 python3 -> python3.5
lrwxrwxrwx. 1 root root 16 Jan 20 2017 python3-config -> python3.5-config
-rwxrwxrwx. 2 www-data www-data 4751184 Sep 27 2018 python3.5
lrwxrwxrwx. 1 root root 33 Sep 27 2018 python3.5-config -> x86_64-linux-gnu-python3.5-config
-rwxrwxrwx. 2 www-data www-data 4751184 Sep 27 2018 python3.5m
lrwxrwxrwx. 1 root root 34 Sep 27 2018 python3.5m-config -> x86_64-linux-gnu-python3.5m-config
lrwxrwxrwx. 1 root root 10 Jan 20 2017 python3m -> python3.5m
lrwxrwxrwx. 1 root root 17 Jan 20 2017 python3m-config -> python3.5m-config
lrwxrwxrwx. 1 root root 29 Jan 24 2017 pyversions -> ../share/python/pyversions.py
lrwxrwxrwx. 1 root root 33 Jan 20 2017 x86_64-linux-gnu-python3-config -> x86_64-linux-gnu-python3.5-config
lrwxrwxrwx. 1 root root 34 Sep 27 2018 x86_64-linux-gnu-python3.5-config -> x86_64-linux-gnu-python3.5m-config
-rwxr-xr-x. 1 root root 3229 Sep 27 2018 x86_64-linux-gnu-python3.5m-config
lrwxrwxrwx. 1 root root 34 Jan 20 2017 x86_64-linux-gnu-python3m-config -> x86_64-linux-gnu-python3.5m-config
I have a fresh server installed with httpd web server and php as CLI. I am able to execute any PHP script in console but when I put the same in a file and call it in browser, it outputs PHP script as it is.
Basically httpd is not parsing PHP script since the extension or module like mod_php is not available. I do not see any files with .so extension in the /etc/httpd/conf.modules.d
/etc/php.d is empty
and
/etc/httpd/conf.modules.d has
[root#ip-10-227-85-145 conf.modules.d]# ll
total 32
-rw-r--r-- 1 root root 3739 Jun 22 2018 00-base.conf
-rw-r--r-- 1 root root 139 Jun 22 2018 00-dav.conf
-rw-r--r-- 1 root root 41 Jun 22 2018 00-lua.conf
-rw-r--r-- 1 root root 742 Jun 22 2018 00-mpm.conf
-rw-r--r-- 1 root root 957 Jun 22 2018 00-proxy.conf
-rw-r--r-- 1 root root 88 Jun 22 2018 00-systemd.conf
-rw-r--r-- 1 root root 451 Jun 22 2018 01-cgi.conf
-rw-r--r-- 1 root root 59 Mar 31 2016 10-auth_openidc.conf
I am clueless what to do. yum install php5-mcrypt is not working.It gave me some error.
RHEL dosen't support mod_php. It uses fsm/fcgi - this is mentioned here - https://aws.amazon.com/premiumsupport/knowledge-center/ec2-php56-apache-rhel72/
I have an ubuntu server (16.04.4 LTS) with apache2 running php7.0 (Apache 2.0 Handler) and php7.2 (FPM/FastCGI).
PHP7.2 works fine, except that there are no extensions loaded - like json or anything else. See my phpinfo():
System Linux srvindkdif 4.4.0-62-generic #83-Ubuntu SMP Wed Jan 18 14:10:15 UTC 2017 x86_64
Build Date Jun 22 2018 08:44:50
Server API FPM/FastCGI
Virtual Directory Support disabled
Configuration File (php.ini) Path /etc/php/7.2/fpm
Loaded Configuration File /etc/php/7.2/fpm/php.ini
Scan this dir for additional .ini files /etc/php/7.2/fpm/conf.d
Additional .ini files parsed (none)
PHP API 20170718
PHP Extension 20170718
Zend Extension 320170718
Zend Extension Build API320170718,NTS
PHP Extension Build API20170718,NTS
Debug Build no
Thread Safety disabled
Zend Signal Handling enabled
Zend Memory Manager enabled
Zend Multibyte Support disabled
IPv6 Support enabled
DTrace Support available, disabled
Registered PHP Streams https, ftps, compress.zlib, php, file, glob, data, http, ftp
Registered Stream Socket Transports tcp, udp, unix, udg, ssl, tls, tlsv1.0, tlsv1.1, tlsv1.2
Registered Stream Filters zlib.*, string.rot13, string.toupper, string.tolower, string.strip_tags, convert.*, consumed, dechunk
I guess the problem is, that no additional .ini files are parsed. But phpinfo says it scans the directory /etc/php/7.2/fpm/conf.d for additional .ini files.
Here's the directory list:
/etc/php/7.2/fpm/conf.d> ll
insgesamt 8
drwxr-xr-x 2 root root 4096 Jun 25 16:07 ./
drwxr-xr-x 4 root root 4096 Jun 26 09:10 ../
lrwxrwxrwx 1 root root 39 Jun 25 16:06 10-mysqlnd.ini -> /etc/php/7.2/mods-available/mysqlnd.ini
lrwxrwxrwx 1 root root 39 Jun 25 16:06 10-opcache.ini -> /etc/php/7.2/mods-available/opcache.ini
lrwxrwxrwx 1 root root 35 Jun 25 16:06 10-pdo.ini -> /etc/php/7.2/mods-available/pdo.ini
lrwxrwxrwx 1 root root 35 Jun 25 16:06 15-xml.ini -> /etc/php/7.2/mods-available/xml.ini
lrwxrwxrwx 1 root root 40 Jun 25 16:06 20-calendar.ini -> /etc/php/7.2/mods-available/calendar.ini
lrwxrwxrwx 1 root root 37 Jun 25 16:06 20-ctype.ini -> /etc/php/7.2/mods-available/ctype.ini
lrwxrwxrwx 1 root root 36 Jun 25 16:06 20-curl.ini -> /etc/php/7.2/mods-available/curl.ini
lrwxrwxrwx 1 root root 35 Jun 25 16:06 20-dom.ini -> /etc/php/7.2/mods-available/dom.ini
lrwxrwxrwx 1 root root 36 Jun 25 16:06 20-exif.ini -> /etc/php/7.2/mods-available/exif.ini
lrwxrwxrwx 1 root root 40 Jun 25 16:06 20-fileinfo.ini -> /etc/php/7.2/mods-available/fileinfo.ini
lrwxrwxrwx 1 root root 35 Jun 25 16:06 20-ftp.ini -> /etc/php/7.2/mods-available/ftp.ini
lrwxrwxrwx 1 root root 34 Jun 25 16:06 20-gd.ini -> /etc/php/7.2/mods-available/gd.ini
lrwxrwxrwx 1 root root 39 Jun 25 16:06 20-gettext.ini -> /etc/php/7.2/mods-available/gettext.ini
lrwxrwxrwx 1 root root 37 Jun 25 16:02 20-iconv.ini -> /etc/php/7.2/mods-available/iconv.ini
lrwxrwxrwx 1 root root 36 Jun 25 15:55 20-json.ini -> /etc/php/7.2/mods-available/json.ini
lrwxrwxrwx 1 root root 40 Jun 25 16:03 20-mbstring.ini -> /etc/php/7.2/mods-available/mbstring.ini
lrwxrwxrwx 1 root root 38 Jun 25 16:06 20-mysqli.ini -> /etc/php/7.2/mods-available/mysqli.ini
lrwxrwxrwx 1 root root 41 Jun 25 16:06 20-pdo_mysql.ini -> /etc/php/7.2/mods-available/pdo_mysql.ini
lrwxrwxrwx 1 root root 36 Jun 25 16:06 20-phar.ini -> /etc/php/7.2/mods-available/phar.ini
lrwxrwxrwx 1 root root 37 Jun 25 16:06 20-posix.ini -> /etc/php/7.2/mods-available/posix.ini
lrwxrwxrwx 1 root root 40 Jun 25 16:06 20-readline.ini -> /etc/php/7.2/mods-available/readline.ini
lrwxrwxrwx 1 root root 37 Jun 25 16:06 20-shmop.ini -> /etc/php/7.2/mods-available/shmop.ini
lrwxrwxrwx 1 root root 41 Jun 25 16:06 20-simplexml.ini -> /etc/php/7.2/mods-available/simplexml.ini
lrwxrwxrwx 1 root root 39 Jun 25 16:06 20-sockets.ini -> /etc/php/7.2/mods-available/sockets.ini
lrwxrwxrwx 1 root root 39 Jun 25 16:06 20-sysvmsg.ini -> /etc/php/7.2/mods-available/sysvmsg.ini
lrwxrwxrwx 1 root root 39 Jun 25 16:06 20-sysvsem.ini -> /etc/php/7.2/mods-available/sysvsem.ini
lrwxrwxrwx 1 root root 39 Jun 25 16:06 20-sysvshm.ini -> /etc/php/7.2/mods-available/sysvshm.ini
lrwxrwxrwx 1 root root 41 Jun 25 16:06 20-tokenizer.ini -> /etc/php/7.2/mods-available/tokenizer.ini
lrwxrwxrwx 1 root root 36 Jun 25 16:06 20-wddx.ini -> /etc/php/7.2/mods-available/wddx.ini
lrwxrwxrwx 1 root root 41 Jun 25 16:06 20-xmlreader.ini -> /etc/php/7.2/mods-available/xmlreader.ini
lrwxrwxrwx 1 root root 41 Jun 25 16:06 20-xmlwriter.ini -> /etc/php/7.2/mods-available/xmlwriter.ini
lrwxrwxrwx 1 root root 35 Jun 25 16:06 20-xsl.ini -> /etc/php/7.2/mods-available/xsl.ini
lrwxrwxrwx 1 root root 35 Jun 25 16:06 20-zip.ini -> /etc/php/7.2/mods-available/zip.ini
I have restarted apache2 server with no effect.
How can I tell my php-fpm to use those extensions?
As well as restarting apache, did you also restart fpm?
for some reason my php installation refuses to load the config for the APC Op-Cache. But looking at phpinfo() every other config file in this directory is getting loaded. Permissions seem ok. below is a look at the directories and the config file itself. And i can confirm that apcu.so exists in the extensions directory as it should. Any ideas here? im stumped.
root#friends:/etc/php5/fpm/conf.d# ls -l
total 24
lrwxrwxrwx 1 root root 32 Apr 7 2014 05-opcache.ini -> ../../mods-available/opcache.ini
lrwxrwxrwx 1 root root 28 Apr 7 2014 10-pdo.ini -> ../../mods-available/pdo.ini
lrwxrwxrwx 1 root root 29 Aug 6 13:45 20-apcu.ini -> ../../mods-available/apcu.ini
lrwxrwxrwx 1 root root 29 Apr 9 2014 20-curl.ini -> ../../mods-available/curl.ini
lrwxrwxrwx 1 root root 27 Aug 6 2014 20-gd.ini -> ../../mods-available/gd.ini
lrwxrwxrwx 1 root root 29 Apr 8 2014 20-json.ini -> ../../mods-available/json.ini
lrwxrwxrwx 1 root root 31 Aug 6 2014 20-mcrypt.ini -> ../../mods-available/mcrypt.ini
lrwxrwxrwx 1 root root 34 Feb 2 2015 20-memcached.ini -> ../../mods-available/memcached.ini
lrwxrwxrwx 1 root root 30 Aug 6 2014 20-mssql.ini -> ../../mods-available/mssql.ini
lrwxrwxrwx 1 root root 31 Apr 7 2014 20-mysqli.ini -> ../../mods-available/mysqli.ini
lrwxrwxrwx 1 root root 30 Apr 7 2014 20-mysql.ini -> ../../mods-available/mysql.ini
lrwxrwxrwx 1 root root 34 Aug 6 2014 20-pdo_dblib.ini -> ../../mods-available/pdo_dblib.ini
lrwxrwxrwx 1 root root 34 Apr 7 2014 20-pdo_mysql.ini -> ../../mods-available/pdo_mysql.ini
lrwxrwxrwx 1 root root 33 Apr 7 2014 20-readline.ini -> ../../mods-available/readline.ini
-rw-r--r-- 1 root root 22661 Apr 22 15:11 newrelic.ini
root#friends:/etc/php5/fpm/conf.d# ls -l ../../mods-available/
total 56
-rw-r--r-- 1 root root 119 Aug 6 13:47 apcu.ini
-rw-r--r-- 1 root root 68 Apr 3 2014 curl.ini
-rw-r--r-- 1 root root 64 Jul 7 2014 gd.ini
-rw-r--r-- 1 root root 68 Aug 8 2013 json.ini
-rw-r--r-- 1 root root 58 Aug 6 2014 mcrypt.ini
-rw-r--r-- 1 root root 70 Dec 19 2012 memcached.ini
-rw-r--r-- 1 root root 71 Jul 7 2014 mssql.ini
-rw-r--r-- 1 root root 71 Apr 3 2014 mysqli.ini
-rw-r--r-- 1 root root 70 Apr 3 2014 mysql.ini
-rw-r--r-- 1 root root 83 May 2 2014 opcache.ini
-rw-r--r-- 1 root root 75 Jul 7 2014 pdo_dblib.ini
-rw-r--r-- 1 root root 66 Apr 3 2014 pdo.ini
-rw-r--r-- 1 root root 74 Apr 3 2014 pdo_mysql.ini
-rw-r--r-- 1 root root 76 Apr 3 2014 readline.ini
root#friends:/etc/php5/fpm/conf.d# cat ../../mods-available/apcu.ini
extension=apcu.so
apc.enabled=1
apc.shm_size=128M
apc.ttl=3600
apc.user_ttl=7200
apc.gc_ttl=3600
apc.max_file_size=1M
I am trying to run the zf.sh (Zend tool) script to create a new Zend project but I get this error:
PHP Warning: PHP Startup: Unable to load dynamic library '/usr/lib/php5/20090626/php_curl.iso' - /usr/lib/php5/20090626/php_curl.iso: cannot open shared object file: No such file or directory in Unknown on line 0
I ran an ls -la of that directory and have:
16:31.57 [00h00m00s] root#vps:/usr/lib/php5/20090626# ls -la
total 752
drwxr-xr-x 2 root root 4096 Sep 11 15:00 .
drwxr-xr-x 4 root root 4096 Sep 3 10:34 ..
-rw-r--r-- 1 root root 67936 Aug 23 15:16 curl.so <---- Curl installed
-rw-r--r-- 1 root root 116856 Aug 23 15:16 gd.so
-rw-r--r-- 1 root root 47280 Aug 23 15:16 mcrypt.so
-rw-r--r-- 1 root root 135864 Aug 23 15:16 mysqli.so
-rw-r--r-- 1 root root 55424 Aug 23 15:16 mysql.so
-rw-r--r-- 1 root root 31120 Aug 23 15:16 pdo_mysql.so
-rw-r--r-- 1 root root 100776 Aug 23 15:16 pdo.so
-rw-r--r-- 1 root root 166496 Aug 19 2010 suhosin.so
in my PHP ini file (/etc/php5/apache2/php.ini)
I have:
extension=curl.so
Why am I getting the above error. I am running a Debian server :)