Docker Community Forums

Share and learn in the Docker community.

Cannot manage to successfully setup LAMP

Hi everyone.

I’ve been trying ALL DAY to install Apache2,MYSQL,PHP7.3 (with mcrypt).
As soon as i find/fix one dependency , something else comes up…
I;ve read and tried so MANY suggestions as to what LIB/Dependencies i need…nothing has worked…
Im missing something, but what?
Ime getting a error of: Unable to locate package php-openssl
Could someone please be so kind to have a look at my Dockerfile and suggest me something.
Thanks!!

    FROM ubuntu:latest
ENV DEBIAN_FRONTEND=noninteractive
ENV PORT 80
WORKDIR /WWW

RUN apt-get update && apt-get install -y software-properties-common
RUN add-apt-repository ppa:ondrej/php
RUN add-apt-repository ppa:ondrej/apache2
RUN apt-get update -y
RUN apt-get upgrade -y

RUN apt-get install -y php7.3-dev
RUN apt-get install -y libcurl3-openssl-dev

#---MISC
RUN apt-get install -y gcc
RUN apt-get install -y g++
RUN apt-get install -y openssl
RUN apt-get install -y libssl-dev
RUN apt-get install -y libcurl4-openssl-dev
RUN apt-get install -y gcc
RUN apt-get install -y make
RUN apt-get install -y autoconf
RUN apt-get install -y libc-dev
RUN apt-get install -y pkg-config 
RUN apt-get install -y composer

#---APACHE2 + PHP
RUN apt-get install -y apache2 
RUN apt-get install -y php 
RUN apt-get install -y php-dev 
RUN apt-get install -y php-mysql 
RUN apt-get install -y libapache2-mod-php 
RUN apt-get install -y php-curl 
RUN apt-get install -y php-json 
RUN apt-get install -y php-common 
RUN apt-get install -y php-mbstring
RUN apt-get install -y php-bcmath
RUN apt-get install -y php-cgi
RUN apt-get install -y php-cli
RUN apt-get install -y php-date
RUN apt-get install -y php-gd
RUN apt-get install -y php-openssl
RUN apt-get install -y php-sockets
RUN apt-get install -y php-sodium
RUN apt-get install -y php-token
RUN apt-get install -y php-simplexml
RUN apt-get install -y php-xmlrpc
RUN apt-get install -y php-xslt
RUN apt-get install -y php-zip
RUN apt-get install -y php-zlib

#---INSTALL/CONF APACHE2 + PHP7.3
RUN curl -s "https://packagecloud.io/install/repositories/phalcon/stable/script.deb.sh" | /bin/bash
RUN apt-get install -y software-properties-common
RUN apt-get install -y php 7.3-phalcon

#---MCRYPT
RUN apt-get install -y php-http
RUN apt-get install -y php-raphf
RUN apt-get install -y php-raphf-dev
RUN apt-get install -y php-propro
RUN apt-get install -y php-propro-dev
RUN apt-get install -y libmcrypt-dev  
RUN pecl install memcached \ && docker-php-ext-enable memcached
RUN pecl install mcrypt-1.0.1

#——INITIALIZE
COPY ./php.ini /etc/php/7.3/apache2/php.ini
COPY ./slc.conf /etc/apache2/sites-available/slc.conf
COPY ./apache2.conf /etc/apache2/apache2.conf
RUN rm -rfv /etc/apache2/sites-enabled/*.conf
RUN ln -s /etc/apache2/sites-available/slc.conf /etc/apache2/sites-enabled/slc.conf

CMD ["apachectl","-D","FOREGROUND"]
RUN a2enmod rewrite
EXPOSE 80
EXPOSE 443

I did not test the Dockerfile you posted, and I’ll get into some of the reasons soon. Getting to the error you’re receiving, Unable to locate php-openssl, this is because there is no package named such. OpenSSL support is built into the php build. You can check that using the following command.

php -r 'phpinfo();' | grep '^OpenSSL support'

You should see the message enabled on the screen.

Now about your Dockerfile, couple of points that I think you should keep in mind -

1. Firstly I see you’re pulling in quite so many packages in there. Probably some of the things you need for a project? Try to not do that. If you need packages other than the ones in LAMP stack, use a separate Dockerfile for that and use this one’s image as the base image.

2. Add PPAs manually. Like this

$ cat <<EOF>/etc/apt/sources.list.d/some_name.list
>...
>EOF
$ apt-key adv --keyserver <keyserver> --recv-keys <key>
$ apt update

This way you’re going to keep your image as light as possible, no need to pull in excess dependencies.

3. Don’t run foreign scripts directly like that. See its contents and try to include only the parts that you need in the Dockerfile.

4. Don’t use the :latest tag unless you have a very specific reason in mind. If you do need the absolute latest, specify the release name, for example I normally use ubuntu:focal if ever I need to spin up an Ubuntu container. You can use ubuntu:groovy if you want the very latest one.

Debdut

Huh…well i knew that OppenSSL was built into PHP but i’ve been using pre-built Ammps/MAMP stacks for so long, i never trully got down to the core modules… but now that it has come time to do so, pretty much any post/article i read mentioned php-openssl. That is why also i have so many packages, upon reading certain articles, i added the packages as were described…
This is my second day with Docker so my experience is very limited…

Thanks for all your input, all noted, i’ve made the changes. I’ll setup the APT Sources once i manage to get a running stack…
I’ve slimmed-down the Dockerfile to the following:

FROM ubuntu:focal
ENV DEBIAN_FRONTEND=noninteractive
ENV PORT 80
WORKDIR /WWW

RUN apt-get update && apt-get install -y software-properties-common
RUN add-apt-repository ppa:ondrej/php
RUN add-apt-repository ppa:ondrej/apache2
RUN apt-get update -y
RUN apt-get upgrade -y

#---CORE Essentials
RUN apt-get install -y gcc
RUN apt-get install -y make
RUN apt-get install -y autoconf
RUN apt-get install -y libc-dev
RUN apt-get install -y pkg-config 
RUN apt-get install -y composer

#————————————————---———————— [*** LAMP Stack ***] 
#---APACHE2 
RUN apt-get install -y apache2
RUN apt-get install -y libapache2-mod-php 

#---PHP
RUN curl -s "https://packagecloud.io/install/repositories/phalcon/stable/script.deb.sh" | /bin/bash
RUN apt-get install -y php7.3-phalcon
RUN apt-get install -y php7.3-dev
RUN apt-get install -y php-common 
RUN apt-get install -y php-cli

#---PHP Extensions 
#RUN apt-get install -y php  
RUN apt-get install -y php-mysql 
RUN apt-get install -y php-curl 
RUN apt-get install -y php-gd
RUN apt-get install -y php-json 
RUN apt-get install -y php-mbstring
RUN apt-get install -y php-bcmath
RUN apt-get install -y php-xml
RUN apt-get install -y php-readline
RUN apt-get install -y php-intl
RUN apt-get install -y php-zip
RUN apt-get install -y php-bz2

#---MCRYPT
#RUN apt-get install -y libmcrypt-dev  
#RUN pecl install memcached \ && docker-php-ext-enable memcached
#RUN pecl install mcrypt-1.0.1

#---INITIALIZE
COPY ./php.ini /etc/php/7.3/apache2/php.ini
COPY ./slc.conf /etc/apache2/sites-available/slc.conf
COPY ./apache2.conf /etc/apache2/apache2.conf
RUN rm -rfv /etc/apache2/sites-enabled/*.conf
RUN ln -s /etc/apache2/sites-available/slc.conf /etc/apache2/sites-enabled/slc.conf

CMD ["apachectl","-D","FOREGROUND"]
RUN a2enmod rewrite
EXPOSE 80
EXPOSE 443

Everything compiles/installs upTo #—MCRYPT, then i get an error of:
failed to build: The command '/bin/sh -c pecl install memcached \ && docker-php-ext-enable memcached' returned a non-zero code: 1
Any suggestions for this?..I decided to leave MCRYPT/dont install now, Install only when i get the stack running… So i disabled those RUN’s.

With MCRYPT install disabled, next i got the following error:
failed to build: COPY failed: stat /var/lib/docker/tmp/docker-builder244028669/php.ini: no such file or directory

Its obviously trying to find the “php.ini”, but looking at my Project folder there are no new files, besides 2 Dockerfiles, docker-compose.yml, and a couple empty folders.

Where am i going wrong here?
Thanks!!

1 Like

Noted :slight_smile:

The output that you provided didn’t actually mention any issues, remember, always be as verbose with questions as possible. After trying it out myself, the output of concern is

 checking for zlib location... configure: error: memcached support requires ZLIB. Use --with-zlib-dir=<DIR> to specify the prefix where ZLIB headers and library are located
ERROR: `/tmp/pear/temp/memcached/configure --with-php-config=/usr/bin/php-config --with-libmemcached-dir=no --with-zlib-dir=no --with-system-fastlz=no --enable-memcached-igbinary=no --enable-memcached-msgpack=no --enable-memcached-json=no --enable-memcached-protocol=no --enable-memcached-sasl=yes --enable-memcached-session=yes' failed

This is obviously a dependency issue, after a little bit of trial and error, I see there are two packages that you need to install first and they’re

zlib1g-dev
libmemcached-dev

This line is slightly confusing to me. Did you copy the Dockerfile from someplace else? The Dockerfile commands you’re talking about [e.g. COPY ./php.ini /etc/php/7.3/apache2/php.ini], copy the files “php.ini”, “slc.conf”, “apache2.conf” from you context directory (the directory you pass to the docker build command) to your image’s filesystem. The error indicates exactly what you guessed, if the files are not there, the build will fail with those commands there. You should have those files in place if it’s you who wrote the Dockerfile.

Thanks for the speedy response!
The ZLib error i didnt see this time. I did see this error previously but i cant recall what exactly i had setup…

Thanks for the zlib1g-dev, libmemcached-dev! Added.

As for the COPY commands, now i get it. I should have looked at the code closer. I was just following directions(i assumed they were right). There was no mention of creating these files… now looking at a few Docker project examples, they do have those files, so i get whats going on there.
After commenting-Out the COPY stuff it Successfully Built! Yay!
But… :slight_smile: I still got no new files in my Project root dir…
My “docker-compose.yml” is as follows:

version: '3'
services:
  apachephp:
    build:
      context: ./
      dockerfile: LAMP_php73.Dockerfile
    ports:
      - "80:80"
      - "443:443"
    volumes:
      - /Volumes/macOS/Users/ten7kur/Docker/lamp_php73:/Volumes/macOS/Users/tom/Docker/lamp_php73/Containers
  mysql:
    build:
      context: ./
      dockerfile: LAMP_php73_MYSQL.Dockerfile
    ports:
      - "3306:3306"
    environment:
      MYSQL_ROOT_PASSWORD: ''
      MYSQL_ALLOW_EMPTY_PASSWORD : 'yes'
    restart: always
    volumes:
    - /Volumes/macOS/Users/ten7kur/Docker/lamp_php73:/Volumes/macOS/Users/tom/Docker/lamp_php73/Containers

Project folder structure:

/~./Docker/lamp_php73/Containers
/~./Docker/lamp_php73/WWW
/~./Docker/lamp_php73/LAMP_php73.Dockerfile
/~./Docker/lamp_php73/LAMP_php73_MYSQL.Dockerfile
/~./Docker/lamp_php73/docker-compose.yml

I have a feeling my “volumes:” path is not correct ??

And, in terms of “use a separate Dockerfile and use this one’s image as the base image”.
Could you show me how you would do that? I havent had a minute to search for more info on that, will do in a minute but i came across this article: Docker MultistageBuild, there it states to include everything in one file…
Is this a different use case?
Thanks!

-EDIT;
Using Terminal;
‘docker images’ gives me:

REPOSITORY             TAG                 IMAGE ID            CREATED            
lamp_php73_mysql       latest              bc49b52b21d5        2 hours ago  
lamp_php73_apachephp   latest              8c4333f23c6e        2 hours ago 
ubuntu                 focal               f643c72bc252        2 weeks ago 
ubuntu                 latest              f643c72bc252        2 weeks ago
mysql                  5.7.25              98455b9624a9        20 months ago 

I run using:

docker run -p 8080:80 --name lamp1 -d lamp_php73_apachephp
docker run --name linux -d ubuntu

Apache is running, but where are the containers? How do i access the fileSystem?

Having gone through the Getting Started with Docker video, I changed my ‘docker-compose.yml’ to be as in the video instructions, but i cant get the services running using: ‘docker-compose up -d’
It gives me an error of:

ERROR: The Compose file './docker-compose.yml' is invalid because:
services.apachephp.build contains unsupported option: 'ports'
services.mysql.build contains unsupported option: 'ports'

docker-compose.yml:

version: '2'
services:
  apachephp:
    build:
        context: ./
        dockerfile: LAMP_php73.Dockerfile
        container_name: apachephp  
        volumes:
            - lamp_php73_CONFIG:/Containers/apache
        ports:
            - "80:80"
          
  mysql:
    build:
        context: ./
        dockerfile: LAMP_php73_MYSQL.Dockerfile
        container_name: mysql
        volumes:
            - lamp_php73_MYSQL_CONFIG:/Containers/mysql 
        ports:
            - "3306:3306"
        environment:
            MYSQL_ROOT_PASSWORD: ''
            MYSQL_ALLOW_EMPTY_PASSWORD : 'yes'
        restart: always   
    
volumes:
  lamp_php73_CONFIG:
  lamp_php73_MYSQL_CONFIG:  

Shouldn’t this work?

Ok, I managed to get the services runninning again by changing the ‘docker-compose.yml’ and changing the structure/order of the commands. Crazy how much it makes a difference!!

However, i still do not understand, How do i Browse the fileSystem? Does it not Mount in physically?

The edited ‘docker-compose.yml’

version: '2'
services:
  apachephp:
    build:
        context: ./
        dockerfile: LAMP_php73.Dockerfile
    ports:
        - "80:80"
        - "443:443"
    volumes:
        - lamp_php73_CONFIG:/Containers/apache
        
          
  mysql:
    build:
        context: ./
        dockerfile: LAMP_php73_MYSQL.Dockerfile 
    ports:
        - "3306:3306"  
    environment:
        MYSQL_ROOT_PASSWORD: ''
        MYSQL_ALLOW_EMPTY_PASSWORD : 'yes'
    restart: always
    volumes:
        - lamp_php73_MYSQL_CONFIG:/Containers/mysql     
    
volumes:
  lamp_php73_CONFIG:
  lamp_php73_MYSQL_CONFIG:

Hi, it’s late here, will be going to sleep soon. I’ll get back to you tomorrow :slight_smile:

1 Like

@ imdebdut has been very helpful! Everyone needs sleep!

“docker exec -it a560854c1c85 /bin/bash” logs me in to the container(root@a560854c1c85:/CODE#), but calling ‘ls’ to list files/dir, the directory is empty…

In Kitematic, under my mysql service/Volumes there is a /Containers/mysql (which is created in .yml) and a second directory of: var/lib/mysql. It contains everything!

However under my apachePhp service[mounted,running]/Volumes, it only shows /Containers/Apache , it doesnt show the “Local folder”.
Why could this be?
And another problem i dont understand is why the PHP installed version is 7.4.13. I specified php7.3-phalcon ?