XP-rience

Something that I'd like to share with you!

Showing posts with label php. Show all posts

Sunday, April 19, 2020

Minimal PHP/Apache Docker setup

No comments :

Why Docker?

The portability of the containers, can be deployed anywhere
Efficient system resource usage compare to VM

How to Dockerize your php application?

Assuming your OS already have a good and working Docker installation
Let us use single page PHP applications below, index.php inside a webfolder directory
index.php content;

<?php
phpinfo();
?>

[root@localhost php_docker]# tree .
.
└── webfolder
└── index.php

Create a Dockerfile

Dockerfile in a list of instruction/command call to assemble the image

[root@localhost php_docker]# tree .
.
├── Dockerfile
└── webfolder
└── index.php

Content of the Dockerfile;

FROM php:7.4-apache
COPY webfolder/ /var/www/html/
EXPOSE 80

Explanation for each line

FROM php:7.4-apache
  • php:7.4-apache based image selection
COPY webfolder/ /var/www/html/
  • copy webfolder content into container /var/www/html/
  • Apache2 default web directory
EXPOSE 80
  • expose port 80 to the host
Next lets build the docker image

[root@localhost php_docker]# docker build --rm -t myphpdocker .

docker build [OPTIONS] PATH | URL | -
--rm = Remove intermediate containers after a successful build
-t = Name and optionally a tag in the 'name:tag' format
myphpdocker = docker container name
. (single dot) = build path

Check the built image

[root@localhost php_docker]# docker image ls

REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
myphpdocker         latest              0c1fe5b1aa9e        47 minutes ago      414 MB

Next is to run the docker

docker run [OPTIONS] IMAGE[:TAG|@DIGEST] [COMMAND] [ARG...]
-t = Allocate a pseudo-TTY
-i = Keep STDIN open even if not attached
-it = For interactive processes (like a shell), you must use -i -t together
-p = Publish a container's port(s) to the host
-d = Run container in background and print container ID

Lets try the interactive mode first

[root@localhost php_docker]# docker run -p 80:80 -it myphpdocker

Apache log appear on the terminal.
Open your browser and head to "http:/<host ip>/"


Now try the detach mode

[root@localhost php_docker]# docker run -p 80:80 -d myphpdocker

Check the running container

[root@localhost php_docker]# docker ps

CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                NAMES
4619304831d4        myphpdocker         "docker-php-entryp..."   6 seconds ago       Up 5 seconds        0.0.0.0:80->80/tcp   frosty_tesla

Wednesday, August 13, 2008

Enabling OCI8 for XAMPP under Linux

1 comment :
Following instruction from

http://www.apachefriends.org/f/viewtopic.php?t=27559&sid=96d42fb6867daf5d8932fdacf4232d58
,
here are my output.

My case is similar to this problem. The only different is, I have libclntsh.so.9.* which is older than the expected version. BTW, my OS is SLES 9.3. First thing to do is to download Oracle Instant Client version 10 to match the expected version from;

http://www.oracle.com/technology/software/tech/oci/instantclient/htdocs/linuxsoft.html


It is recommended to download .gz version than .rpm version since the .gz version is quite easy to be extracted. My case, I accidentally downloaded the .rpm version. So to extract it need special rpm2cpio command as below.

normuser@MYSERVER:~/OC> ls -al
total 32048
drwxr-xr-x 2 normuser normgroup 112 2008-08-12 13:03 ./
drwxr-xr-x 13 normuser normgroup 784 2008-08-12 13:03 ../
-rw-r--r-- 1 normuser normgroup 32782200 2008-08-12 12:55 oracle-instantclient-basic-10.2.0.4-1.i386.rpm

normuser@MYSERVER:~/OC> rpm2cpio oracle-instantclient-basic-10.2.0.4-1.i386.rpm | cpio -idv
./usr/lib/oracle/10.2.0.4/client/bin/genezi
./usr/lib/oracle/10.2.0.4/client/lib/libclntsh.so.10.1
./usr/lib/oracle/10.2.0.4/client/lib/libnnz10.so
./usr/lib/oracle/10.2.0.4/client/lib/libocci.so.10.1
./usr/lib/oracle/10.2.0.4/client/lib/libociei.so
./usr/lib/oracle/10.2.0.4/client/lib/libocijdbc10.so
./usr/lib/oracle/10.2.0.4/client/lib/ojdbc14.jar

Now, copy all .so files into xampp lib directory named /opt/lampp/lib/.

MYSERVER:/apps/home/normuser/OC/usr/lib/oracle/10.2.0.4/client/lib # cp * /opt/lampp/lib/

Next is to issue the lampp oci8 command by telling the program that the expected libs are at /opt/lampp/lib/ as root since xampp is under root.

MYSERVER:/opt/lampp # ./lampp oci8
Please enter the path to your Oracle or Instant Client installation:
[/opt/oracle] /opt/lampp/lib
installing symlink...
patching php.ini...
OCI8 add-on activation likely successful.
XAMPP: Stopping Apache with SSL...
XAMPP: Starting Apache with SSL (and PHP5)...

Now you can test your connection with some PHP example code from
http://www.php.net/oci8