Download php file instead of executing with nginx and docker - php

I'm using docker
and This my Dockerfile contains:
FROM nginx:latest
RUN apt-get update && apt-get install -y \
php \
php-fpm \
nano
so as you see, we use nginx's latest version image and then run some of these bash command which you can see.
base on these configuration I'm trying to execute a php file to show phpinfo()
so I create a file in /usr/share/nginx/html called index.php
and when I try to use index.php like this http://localhost:8000/index.php, the php file start downloading immediately.
What should I do?
I know that this is a possible duplicate but I've tried something like this link:
Nginx - Downloading PHP instead of executing
but nothing well happened.

Related

Run php command inside bash script inside Docker container with ubuntu image

I have a bash script and a php script.
--------EDIT--------
I SOLVED IT, I AM JUST STUPID, I WROTE MY ANSWER BELOW.
(I can put code screenshots if you want.)
MY DOCKERFILE:
ARG VERSION=latest
FROM ubuntu:bionic
RUN apt-get -y update && apt-get -y upgrade
COPY ./resources/ start.sh /sandbox/
WORKDIR /sandbox/
ENTRYPOINT ["sh","start.sh"]
I want to execute them in a docker container as i said in the title.
The 'entry point' of the docker container is the bash script.
Inside the bash script i have a line
php PHP_SCRIPT.php
But when i execute, it gives me the error:
PHP_SCRIPT.php: php: not found
or something like that
i saw that the php command usually resides in '/usr/bin/php',
but i tried to run the command 'which php' in the docker container and the result was '/usr/local/bin/php'
Maybe i am calling the php command wrong?
But the result that i want is to run a php script INSIDE a bash script that starts when i start the docker container.
You are using the docker image FROM ubuntu:bionic which does not have PHP installed by default. Try FROM php (or one of the many tags available) instead.
the problem is that PHP is not installed in your container
To do this, you can use your official PHP image
https://hub.docker.com/_/php
FROM php:7.4-cli
ARG VERSION=latest
RUN apt-get -y update && apt-get -y upgrade
COPY ./resources/ start.sh /sandbox/
WORKDIR /sandbox/
ENTRYPOINT ["sh","start.sh"]
And i would get the "php not found error" because i didnt install php to the docker container.
So, I tried writing in the dockerfile
RUN apt-get php-cli (i also tried with php:cli and seemed to have same effect),
to try to install php to container, but when i would start container it would seem like it would freeze and not do anything.
Apparenty, it doesnt 'freeze', but i only had to wait for the php to update in the container. :D

ORA-28547 with php-fpm in docker container

I got a working php-fpm docker container acting as the php backend to a nginx frontend. What I mean by working, is that it renders phpinfo output in the browser as expected.
My php-fpm container was produced by php-fpm-7.4 prod of the devilbox docker repo. It has OCI8 enable.
The issue: I keep getting ORA-28547 when trying oci_connect
What I have done:
1--add /usr/lib/oracle/client64/lib to a file inside ld.so.conf.d and run ldconfig -v
2--restart docker container.
3-- Now phpinfo shows ORACLE_HOME=/usr/lib/oracle/client64/lib
4--Add tnsnames.ora to /usr/lib/oracle/client6/lib/network/admin (there is a README.md file inside that folder that even tells you to do that)
5--Restart docker container again.
6-oci_connect still fails with the same error.
What I am missing?
Thank you very much for any pointers, I think I have browsed to the end of the internet and back without finding a solution yet.
----SOLUTION: reinstall instantclient, relink libraries (ldconfig) to use new instantclient libraries. Create modified dockerfile to do it when container is created.
I modified the Dockerfile file of the php-fpm to add new instant client files and not the one that were provided by the original file. I was not able to make it work with them. I have tried a few times rebuilding the image (docker-compose up --build) and this is the file that does the trick:
FROM devilbox/php-fpm:7.4-work
#instantclient.conf content: /opt/instantclient
RUN echo "/opt/instantclient" >/etc/ld.so.conf.d/instantclient.conf
WORKDIR /opt
RUN wget https://download.oracle.com/otn_software/linux/instantclient/19800/instantclient-sdk-linux.x64-19.8.0.0.0dbru.zip
RUN wget https://download.oracle.com/otn_software/linux/instantclient/19800/instantclient-sqlplus-linux.x64-19.8.0.0.0dbru.zip
RUN wget https://download.oracle.com/otn_software/linux/instantclient/19800/instantclient-basic-linux.x64-19.8.0.0.0dbru.zip
RUN unzip instantclient-sdk-linux.x64-19.8.0.0.0dbru.zip
RUN unzip instantclient-sqlplus-linux.x64-19.8.0.0.0dbru.zip
RUN unzip instantclient-basic-linux.x64-19.8.0.0.0dbru.zip
RUN mv instantclient_19_8 instantclient
ADD tnsnames.ora /opt/instantclient/network/admin
RUN ldconfig -v
CMD ["php-fpm"]
expose 9000
# Insert following to .bash_profile or .profile of the User starting the php-fpm
export ORACLE_HOME=/usr/lib/oracle/client64
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$ORACLE_HOME/lib
export PATH=$PATH:$ORACLE_HOME/bin
export TNS_ADMIN=$ORACLE_HOME/network/admin
# Test to Ping Remote Db to be connected by PHP
tnsping <tns-name of remote DB - i.e. db12c.world>
# restart here the php Engine
Can you please check
https://github.com/caffeinalab/php-fpm-oci8/blob/master/Dockerfile
which seems to create a p-fpm-oci8 docker image
the "wget" for
wget -qO- https://raw.githubusercontent.com/caffeinalab/php-fpm-oci8/master/oracle/instantclient-basic-linux.x64-12.2.0.1.0.zip | bsdtar -xvf- -C /usr/local &&
wget -qO- https://raw.githubusercontent.com/caffeinalab/php-fpm-oci8/master/oracle/instantclient-sdk-linux.x64-12.2.0.1.0.zip | bsdtar -xvf- -C /usr/local &&
wget -qO- https://raw.githubusercontent.com/caffeinalab/php-fpm-oci8/master/oracle/instantclient-sqlplus-linux.x64-12.2.0.1.0.zip | bsdtar -xvf- -C /usr/local && \
can be dropped when you place downloaded instant client files into local host dir
/usr/local
and extract them - resulting in
/usr/local/instantcient_12_2
or 18, 19c equivalents
the 4 "ln" commands have to be adjusted to reflect the local host instantclient dir
the tnsnames.ora for instantclient is available from host by VOLUME command
-------------FINAL SOLUTION------------(it was not network related, I had done a couple of changes to the files, and also tried a different database, all at the same time, so it made me think that it was the different database what fixed the issue)
After many trial and errors, I came up with a Dockerfile that creates the correct configuration of files and connects without any issues to the database:
--Dockerfile: (to build php-fpm 7.4 using devilbox image)
Final solution:
I modified the Dockerfile file of the php-fpm to add new instant client files and not the one that were provided by the original file. I was not able to make it work with them. I have tried a few times rebuilding the image (docker-compose up --build) and this is the file that does the trick:
FROM devilbox/php-fpm:7.4-work
ADD instantclient.conf /etc/ld.so.conf.d/
WORKDIR /opt
RUN wget https://download.oracle.com/otn_software/linux/instantclient/19800/instantclient-sdk-linux.x64-19.8.0.0.0dbru.zip
RUN wget https://download.oracle.com/otn_software/linux/instantclient/19800/instantclient-sqlplus-linux.x64-19.8.0.0.0dbru.zip
RUN wget https://download.oracle.com/otn_software/linux/instantclient/19800/instantclient-basic-linux.x64-19.8.0.0.0dbru.zip
RUN unzip instantclient-sdk-linux.x64-19.8.0.0.0dbru.zip
RUN unzip instantclient-sqlplus-linux.x64-19.8.0.0.0dbru.zip
RUN unzip instantclient-basic-linux.x64-19.8.0.0.0dbru.zip
RUN mv instantclient_19_8 instantclient
ADD tnsnames.ora /opt/instantclient/network/admin
RUN ldconfig -v
CMD ["php-fpm"]
expose 9000
That's why I have suggested to use tnsping - unfortunaly it is not included in any of the instant client files which is a pity - so you have to pick it up from regular client with matching OS, bitsize and Oracle release. As workaround you could place SQL*Plus package files into container and try to connect with a foo user like
sqlplus foo/foo#\<ip>:\<port>/\<dbname>
which should generate an error - if
user/password not matching - ORA-1017 i.e. DB & listener running
listener running - ORA-1034 i.e. DB down
listener down (no return, or TNS-Errors)
I got it!. It was a firewall issue. I launched a tcpdump capture
session and there was nothing wrong with php-fpm, oci8 and
instantclient libraries. The traffic was initiated but there was no
response from the database. I made it work against a different
database where this box has no firewall issues.
I now will try rebuilding the docker image so I can see what I have to
manually add if any.
That was incorrect (the firewall as the origin of the problem). Rebuilding the docker file showed me where I had it wrong. See original question for solution.

docker-php-ext-install running every build making new images and leaving <none>

My dockerfile looks like this:
FROM php:7.3.3-apache
COPY src/ /var/www/html
RUN docker-php-ext-install mysqli
EXPOSE 80
Every time I run the following command docker will build a new image, download the mysqli package again and leaves a : images, when I am just simply changing a line in the php file.
docker build -t php-server .
Is there a way to make docker not re download the package and just update the image that already exists?

Use Node JS from php Elastic Beanstalk enviroment

I am trying to use shell_exec to run a node app like that:
shell_exec(node app.js) ;
But I got an error:
sh: node: command not found
I have tried to install node js using confing file like that:
commands:
01_node_install:
# run this command from /tmp directory
cwd: /tmp
# don't run the command if node is already installed (file /usr/bin/node exists)
test: '[ ! -f /usr/bin/node ] && echo "node not installed"'
# install from epel repository
# flag -y for no-interaction installation
command: 'yum install -y nodejs --enablerepo=epel'
This was all of my env.config file but I don't see anything in the Elastic Beanstalk log related to that and the problem still exists.
How could I use Node JS from php environment !!
Your configuration file is fine. Just make sure that env.config is inside .ebextensions folder in the root directory of your project.

Nginx in Docker container won't run PHP

I'm beginner with Docker, and I'm trying to build my own image: Ubuntu + Nginx + PHP.
So, I have a directory called test. Inside directory two other directories, app and sites-enabled. Also, there's a Dockerfile, with content:
FROM ubuntu:trusty
RUN apt-get update && \
apt-get install -y nginx php5-fpm php5-mysql php-apc php5-imagick php5-imap php5-mcrypt php5-gd libssh2-php && \
apt-get clean && \
rm -rf /var/lib/apt/lists/*
RUN echo "daemon off;" >> /etc/nginx/nginx.conf
ADD sites-enabled/ /etc/nginx/sites-enabled/
ADD app/ /app/
EXPOSE 80
CMD ["php5-fpm", "-c", "/etc/php5/fpm"]
CMD ["/usr/sbin/nginx"]
I build this image successfully. Then I create container with docker run -d image_name. I get the ID, and then I run docker inspect -f "{{.NetworkSettings.IPAddress}}" ID in order to get the IP address of the container.
I need this IP address, because I also run HAProxy in another container, so I can configure it to point to the right localtion.
So, both HAProxy and container with PHP app are running OK. HAProxy is pointing at the right application. PHP application files are uploaded at the right location inside the container.
But, Nginx doesn't execute PHP. Instead, when I try to access the application, I just get a downloaded file with my index.php PHP code.
What could be the problem? Please help.
My first guess was that I'm doing something wrong in Dockerfile when I run php5-fpm. I've tried few different ways, but non of them seem to work.
One CMD only.
If you need "services", look into supervisord or runit.

Categories