Run PHP script after Azure Web app deployment

Mulansky, Ralf 21 Reputation points
2022-01-17T10:51:56.91+00:00

Hi,
I am having an Azure app Service and I want to upload/deploy an .php file to it an run it right after the upload. I managed to upload it via curl and also start a post deployment script. Unfortunately I can not use the command "php ..." in it because I get an error like: "/opt/Kudu/Scripts/starter.sh: line 2: exec: php: not found\n" in the logs.
The same occurs if I use the "/api/command" endpoint with the same command. I get the same kind of error in the response.
It seems like the php executable is not known in that environment.
Is there any way to run a php script via the command API or in a post deployment script?

Thanks in advance

Azure App Service
Azure App Service
Azure App Service is a service used to create and deploy scalable, mission-critical web apps.
7,408 questions
{count} votes

Accepted answer
  1. Andriy Bilous 11,176 Reputation points MVP
    2022-01-19T11:53:33.837+00:00

    Hello @Mulansky, Ralf

    Here is a simplified diagram of App Service on Linux (almost certain to contain some inaccuracies):
    166391-image.png

    As the architecture diagram above shows, each container has its /home directory mounted from the file share. This means while the container has everything we need to run the application, the actual application itself is located outside of the container. This allows the Kudu container to also see the application folder. It also allows continuous deployment to deploy to the shared folder and the application is automatically updated without restarting the container.
    https://anthonychu.ca/post/jekyll-azure-app-service-linux/

    When you create a new App Service on Linux, you choose from pre-defined runtime containers - PHP8. However when you push the code to repository and it gets deployed to ASL, the PHP8 container is not going to be the container where the application gets built or custom scripts executed. It is actually going to be in the Kudu container.

    Unfortunately there is no PHP in Kudu container.
    166381-image.png

    As an option you may use your custom Docker image and add any startup commands you want there

    FROM tiangolo/uwsgi-nginx-flask:python3.6  
      
    RUN mkdir /code  
    WORKDIR /code  
    ADD requirements.txt /code/  
    RUN pip install -r requirements.txt --no-cache-dir  
    ADD . /code/  
      
    # ssh  
    ENV SSH_PASSWD "root:Docker!"  
    RUN apt-get update \  
            && apt-get install -y --no-install-recommends dialog \  
            && apt-get update \  
    	&& apt-get install -y --no-install-recommends openssh-server \  
    	&& echo "$SSH_PASSWD" | chpasswd   
      
    COPY sshd_config /etc/ssh/  
    COPY init.sh /usr/local/bin/  
      
    RUN chmod u+x /usr/local/bin/init.sh  
    EXPOSE 8000 2222  
      
    #CMD ["python", "/code/manage.py", "runserver", "0.0.0.0:8000"]  
    ENTRYPOINT ["init.sh"]  
    

    ENTRYPOINT ["init.sh"], invokes init.sh to start the SSH service and Python server. You can add your deployment script into init.sh

    https://learn.microsoft.com/en-us/azure/app-service/tutorial-custom-container?pivots=container-linux

    0 comments No comments

0 additional answers

Sort by: Most helpful