sh: 1: python3: not found when running from php - php

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

Related

RHEL 7.4 not loading php extension for httpd and unable to configure it also

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/

php7.1-mbstring won't be loaded even though it's installed

For some reason, I can install pretty much any PHP extension, except for mbstring. I have installed php7.1.14 via sudo apt-get install php7.1 and then installed all my required extensions with sudo apt-get install php7.1-mysql php7.1-json... etc. I did the same for php7.1-mbstring but for some reason it won't get loaded:
forge#staging:~/test$ php -m
[PHP Modules]
Core
ctype
date
dom
fileinfo
filter
hash
iconv
json
libxml
openssl
pcre
PDO
pdo_sqlite
Phar
posix
Reflection
session
SimpleXML
SPL
sqlite3
standard
tokenizer
xml
xmlreader
xmlwriter
[Zend Modules]
I've already tried adding extension=mbstring and extension=mbstring.so to my /etc/php/7.1/fpm/php.ini and /etc/php/7.1/cli/php.ini but no succes. mbstring.ini also exists in /etc/php/7.1/mods-available:
forge#staging:~/test$ ls -l /etc/php/7.1/mods-available/
total 200
-rw-r--r-- 1 root root 72 Feb 18 2017 bcmath.ini
-rw-r--r-- 1 root root 66 Feb 9 10:41 bz2.ini
-rw-r--r-- 1 root root 74 Feb 18 2017 calendar.ini
-rw-r--r-- 1 root root 71 Feb 18 2017 ctype.ini
-rw-r--r-- 1 root root 68 Feb 18 2017 curl.ini
-rw-r--r-- 1 root root 66 Feb 9 10:41 dba.ini
-rw-r--r-- 1 root root 66 Feb 18 2017 dom.ini
-rw-r--r-- 1 root root 70 Feb 18 2017 exif.ini
-rw-r--r-- 1 root root 74 Feb 18 2017 fileinfo.ini
-rw-r--r-- 1 root root 69 Feb 18 2017 ftp.ini
-rw-r--r-- 1 root root 64 Feb 18 2017 gd.ini
-rw-r--r-- 1 root root 73 Feb 18 2017 gettext.ini
-rw-r--r-- 1 root root 66 Feb 9 10:41 gmp.ini
-rw-r--r-- 1 root root 71 Feb 18 2017 iconv.ini
-rw-r--r-- 1 root root 364 Dec 19 2016 igbinary.ini
-rw-r--r-- 1 root root 68 Feb 18 2017 imap.ini
-rw-r--r-- 1 root root 68 Feb 18 2017 intl.ini
-rw-r--r-- 1 root root 68 Feb 18 2017 json.ini
-rw-r--r-- 1 root root 68 Feb 9 10:41 ldap.ini
-rw-r--r-- 1 root root 76 Feb 18 2017 mbstring.ini
-rw-r--r-- 1 root root 72 Feb 18 2017 mcrypt.ini
-rw-r--r-- 1 root root 176 Feb 12 2017 memcached.ini
-rw-r--r-- 1 root root 74 Dec 7 2016 msgpack.ini
-rw-r--r-- 1 root root 71 Feb 18 2017 mysqli.ini
-rw-r--r-- 1 root root 72 Feb 18 2017 mysqlnd.ini
-rw-r--r-- 1 root root 79 Feb 18 2017 opcache.ini
-rw-r--r-- 1 root root 69 Feb 18 2017 pdo.ini
-rw-r--r-- 1 root root 74 Feb 18 2017 pdo_mysql.ini
-rw-r--r-- 1 root root 74 Feb 18 2017 pdo_pgsql.ini
-rw-r--r-- 1 root root 77 Feb 18 2017 pdo_sqlite.ini
-rw-r--r-- 1 root root 70 Feb 18 2017 pgsql.ini
-rw-r--r-- 1 root root 70 Feb 18 2017 phar.ini
-rw-r--r-- 1 root root 71 Feb 18 2017 posix.ini
-rw-r--r-- 1 root root 76 Feb 18 2017 readline.ini
-rw-r--r-- 1 root root 71 Feb 18 2017 shmop.ini
-rw-r--r-- 1 root root 72 Feb 18 2017 simplexml.ini
-rw-r--r-- 1 root root 68 Feb 18 2017 soap.ini
-rw-r--r-- 1 root root 73 Feb 18 2017 sockets.ini
-rw-r--r-- 1 root root 74 Feb 18 2017 sqlite3.ini
-rw-r--r-- 1 root root 73 Feb 18 2017 sysvmsg.ini
-rw-r--r-- 1 root root 73 Feb 18 2017 sysvsem.ini
-rw-r--r-- 1 root root 73 Feb 18 2017 sysvshm.ini
-rw-r--r-- 1 root root 68 Feb 9 10:41 tidy.ini
-rw-r--r-- 1 root root 75 Feb 18 2017 tokenizer.ini
-rw-r--r-- 1 root root 67 Feb 18 2017 wddx.ini
-rw-r--r-- 1 root root 66 Feb 18 2017 xml.ini
-rw-r--r-- 1 root root 72 Feb 18 2017 xmlreader.ini
-rw-r--r-- 1 root root 72 Feb 18 2017 xmlwriter.ini
-rw-r--r-- 1 root root 66 Feb 18 2017 xsl.ini
-rw-r--r-- 1 root root 66 Feb 18 2017 zip.ini
What could be the issue here?!

PHP7.0-FPM with Docker : Unable to load dynamic library OCI8

I have created a Docker Image with PHP7.0-FPM and Apache 2.4. I have installed InstantClient 12.2 (basic + sdk) and I have installed oci8 like this :
RUN echo "instantclient,/usr/lib/oracle/12.2/instantclient"| pecl install oci8 && \
echo "extension=oci8.so" > /etc/php/7.0/mods-available/oci8.ini && \
ln -s /etc/php/7.0/mods-available/oci8.ini /etc/php/7.0/fpm/conf.d/20-oci8.ini
I don't know why, but I am getting this warning when I (re)start php7.0-fpm :
# service php7.0-fpm restart
* Restarting PHP 7.0 FastCGI Process Manager php-fpm7.0
Warning: PHP Startup: Unable to load dynamic library '/usr/lib/php/20151012/oci8.so' - libmql1.so: cannot open shared object file: No such file or directory in Unknown on line 0
Locations of oci8.so and libmql1.so seems to be ok :
# ll /usr/lib/oracle/12.2/instantclient/
total 216700
drwxrwxrwx 3 root www-data 4096 Dec 11 15:12 ./
drwxr-xr-x 4 root www-data 4096 Dec 12 08:24 ../
-rwxrwxrwx 1 root www-data 363 Jan 26 2017 BASIC_README*
-rwxrwxrwx 1 root www-data 44220 Jan 26 2017 adrci*
-rwxrwxrwx 1 root www-data 57272 Jan 26 2017 genezi*
lrwxrwxrwx 1 root www-data 52 Dec 11 15:02 libclntsh.so -> /usr/lib/oracl
e/12.2/instantclient/libclntsh.so.12.1*
-rwxrwxrwx 1 root www-data 71638263 Jan 26 2017 libclntsh.so.12.1*
-rwxrwxrwx 1 root www-data 8033199 Jan 26 2017 libclntshcore.so.12.1*
-rwxrwxrwx 1 root www-data 2981501 Jan 26 2017 libipc1.so*
-rwxrwxrwx 1 root www-data 539065 Jan 26 2017 libmql1.so*
-rwxrwxrwx 1 root www-data 6568149 Jan 26 2017 libnnz12.so*
lrwxrwxrwx 1 root root 50 Dec 11 15:12 libocci.so -> /usr/lib/oracle/
12.2/instantclient/libocci.so.12.1*
-rwxrwxrwx 1 root www-data 2218687 Jan 26 2017 libocci.so.12.1*
-rwxrwxrwx 1 root www-data 124771800 Jan 26 2017 libociei.so*
-rwxrwxrwx 1 root www-data 158543 Jan 26 2017 libocijdbc12.so*
-rwxrwxrwx 1 root www-data 380996 Jan 26 2017 libons.so*
-rwxrwxrwx 1 root www-data 116563 Jan 26 2017 liboramysql12.so*
-rwxrwxrwx 1 root www-data 4036257 Jan 26 2017 ojdbc8.jar*
drwxrwxrwx 5 root www-data 4096 Jan 26 2017 sdk/
-rwxrwxrwx 1 root www-data 240476 Jan 26 2017 uidrvci*
-rwxrwxrwx 1 root www-data 74230 Jan 26 2017 xstreams.jar*
I have added to /etc/php/7.0/fpm/pool.d/www.conf these 4 lines :
env[LD_LIBRARY_PATH] = /usr/lib/oracle/12.2/instantclient
env[TNS_ADMIN] = /etc/oracle
env[ORACLE_BASE] = /usr/lib/oracle/12.2/instantclient
env[ORACLE_HOME] = /usr/lib/oracle/12.2/instantclient
Would I've missed something?
Thanks
It's ok !
I was missing a .conf in /etc/ld.so.conf.d/oracle-instantclient.conf
RUN echo "instantclient,/usr/lib/oracle/12.2/instantclient"| pecl install oci8 && \
echo "extension=oci8.so" > /etc/php/7.0/mods-available/oci8.ini && \
ln -s /etc/php/7.0/mods-available/oci8.ini /etc/php/7.0/fpm/conf.d/20-oci8.ini && \
echo /usr/lib/oracle/12.2/instantclient > /etc/ld.so.conf.d/oracle-instantclient.conf && \
ldconfig
Try adding those env variable in /etc/apache2/envvars
add at end of the file, like
export LD_LIBRARY_PATH=/usr/lib/oracle/12.2/instantclient
export TNS_ADMIN=/etc/oracle
export ORACLE_BASE=/usr/lib/oracle/12.2/instantclient
export ORACLE_HOME=/usr/lib/oracle/12.2/instantclient
So that apache user will use those variable at runtime.
And also check for user/group permission it has to be www-data:www-data

Undefined offset: 0 in mail_queue.php | CentOS Web Panel

I am using Postfix. The mails are being sent and received properly but I am getting below PHP notice on CentOS Web Panel's mail queue page:
Notice: Undefined offset: 0 in
/usr/local/cwpsrv/htdocs/resources/admin/modules/mail_queue.php on
line 0
Notice: Undefined offset: 0 in
/usr/local/cwpsrv/htdocs/resources/admin/modules/mail_queue.php on
line 0
Below is the content of /usr/local/cwpsrv/htdocs/resources/admin/modules/mail_queue.php:
<?php //003ed
// Copyright CentOS WebPanel, Decoding is FORBIDDEN
// All Rights Reserved. www.centos-webpanel.com
if(!extension_loaded('ionCube Loader')){$__oc=strtolower(substr(php_uname(),0,3));$__ln='ioncube_loader_'.$__oc.'_'.substr(phpversion(),0,3).(($__oc=='win')?'.dll':'.so');if(function_exists('dl')){#dl($__ln);}if(function_exists('_il_exec')){return _il_exec();}$__ln='/ioncube/'.$__ln;$__oid=$__id=realpath(ini_get('extension_dir'));$__here=dirname(__FILE__);if(strlen($__id)>1&&$__id[1]==':'){$__id=str_replace('\\','/',substr($__id,2));$__here=str_replace('\\','/',substr($__here,2));}$__rd=str_repeat('/..',substr_count($__id,'/')).$__here.'/';$__i=strlen($__rd);while($__i--){if($__rd[$__i]=='/'){$__lp=substr($__rd,0,$__i).$__ln;if(file_exists($__oid.$__lp)){$__ln=$__lp;break;}}}if(function_exists('dl')){#dl($__ln);}}else{die('The file '.__FILE__." is corrupted.\n");}if(function_exists('_il_exec')){return _il_exec();}echo('No Loader is installed. Please contact support.');exit(199);
?>
some encryption key here
How can I resolve this?
So, sendmail was causing the issue in my case. Someone from CWP support fixed it by uninstalling it.
edit some symbolic links in /etc/alternatives
BEFORE:
lrwxrwxrwx 1 root root 18 ene 31 21:42 mta -> /opt/exim/bin/exim
lrwxrwxrwx 1 root root 18 ene 31 21:42 mta-mailq -> /opt/exim/bin/exim
lrwxrwxrwx 1 root root 18 ene 31 21:42 mta-newaliases -> /opt/exim/bin/exim
lrwxrwxrwx 1 root root 18 ene 31 21:42 mta-rmail -> /opt/exim/bin/exim
lrwxrwxrwx 1 root root 18 ene 31 21:42 mta-sendmail -> /opt/exim/bin/exim
AFTER:
lrwxrwxrwx 1 root root 26 feb 1 00:29 mta -> /usr/sbin/sendmail.postfix
lrwxrwxrwx 1 root root 22 feb 1 00:33 mta-mailq -> /usr/bin/mailq.postfix
lrwxrwxrwx 1 root root 27 feb 1 00:08 mta-newaliases -> /usr/bin/newaliases.postfix
lrwxrwxrwx 1 root root 43 feb 1 00:11 mta-newaliasesman -> /usr/share/man/man1/newaliases.postfix.1.gz
lrwxrwxrwx 1 root root 22 feb 1 00:31 mta-rmail -> /usr/bin/rmail.postfix
lrwxrwxrwx 1 root root 26 feb 1 00:30 mta-sendmail -> /usr/sbin/sendmail.postfix
EXAMPLE:
rename a symbolic link
mv mta mta_
create a new symbolic link
ln -s /usr/sbin/sendmail.postfix /etc/alternatives/
mv /etc/alternatives/sendmail.postfix /etc/alternatives/mta
ready. try using mailq

APC configuration not getting loaded by PHP-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

Categories