简体   繁体   中英

Run Python Script from PHP Docker

I am running a Docker. Here is my docker file.

FROM php:5.6-apache

RUN apt-get update && apt-get install -my wget gnupg
RUN apt-key adv \
        --keyserver hkp://keyserver.ubuntu.com:80 \
        --recv 7F0CEB10
RUN echo "deb http://repo.mongodb.org/apt/ubuntu trusty/mongodb-org/3.0 multiverse" | tee /etc/apt/sources.list.d/mongodb-org-3.0.list
RUN apt-get update
RUN apt-get update && apt-get install -y \
        libfreetype6-dev \
        libmcrypt-dev \
        libssl-dev 
RUN apt-get install -y libmariadbclient-dev
RUN docker-php-ext-install iconv mcrypt mysqli pdo_mysql mysql zip mbstring
RUN pecl install mongo
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/bin --filename=composer
RUN sed -i 's/^ServerSignature/#ServerSignature/g' /etc/apache2/conf-enabled/security.conf; \
    sed -i 's/^ServerTokens/#ServerTokens/g' /etc/apache2/conf-enabled/security.conf; \
    echo "ServerSignature Off" >> /etc/apache2/conf-enabled/security.conf; \
    echo "ServerTokens Prod" >> /etc/apache2/conf-enabled/security.conf; \
    a2enmod ssl; \
    a2enmod headers; \
    echo "SSLProtocol ALL -SSLv2 -SSLv3" >> /etc/apache2/apache2.conf
RUN apt-get install -y vim
RUN apt-get update && apt-get install -y python3 python3-pip
RUN pip3 install numpy
RUN pip3 install scipy
RUN pip3 install image_match
RUN pip3 install opencv-python
RUN pip3 install pytube
RUN pip3 install ez_setup
RUN pip3 install moviepy
RUN pip3 install requests
RUN pip3 install ffmpeg-python
RUN apt update && apt install -y libsm6 libxext6
RUN apt-get install -y libxrender-dev
RUN apt-get update
COPY config/mongo.ini /usr/local/etc/php/conf.d/

ENV VERSION 8
ENV UPDATE 91
ENV BUILD 14

In one my PHP Page, I want to Run a python script. for eg

$command = escapeshellcmd('python integrateFinal.py');
$joutput = shell_exec($command);
$output=json_decode($joutput);

The python script works fine with the command line as 'docker-compose exec web python3 integrateFinal.py'. It works and gives the output but when I run it from PHP page mentioned above It gives me error as permission denied.

So How should I run this PYTHON script?

在运行python文件之前授予权限

exec("chmod 777 integrateFinal.py")

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM