About

The automated build docker LAMP image “linuxconfig/lamp” can be used as a testing and also as a production environment for a dynamic PHP applications. It comprises of Debian GNU/Linux, Apache webserver, MariaDB a community-developed fork of the MySQL relational database management system and PHP scripting language.

Deployment

The deployment of “linuxconfig/lamp” docker image is a fairly simple procedure. Let' start by creating a sample PHP website with a MariaDB connection handle:
<?php
$dbh = mysqli_connect('localhost', 'admin', 'pass');
if (!$dbh) {
    die('Could not connect: ' . mysqli_error());
}
echo 'Connected successfully to MariaDB database';
mysqli_close($dbh);
?>
Save the above code into index.php file and within a new html directory. Alternatively,html directory may contain your desired PHP application:
$ mkdir html
$ vi html/index.php
$ ls html/
index.php
At this stage we are ready to deploy “linuxconfig/lamp” docker image:
$ sudo docker run --name=lamp -dP -v $PWD/html:/var/www/html linuxconfig/lamp
c2d1687aef21f8a12a7fbb31bf8cf71c1e5adabf381bc6d70e8804c6663f0bc0
By executing the above command we have created and started a new docker container named lamp. At the same time we have also mounted our website development directory html as apache's root directory. Both, MariaDB and Apache ports are now bound to a host system's random port. The both local ports can now be used to access both MariaDB and Apache services :
$ sudo docker port lamp
80/tcp -> 0.0.0.0:49156
3306/tcp -> 0.0.0.0:49155

Apache Access

At this stage Nginx webserver and our website can be accessed via ports given by $ sudo docker port lamp command. Use command line or your browser to navigate to http://localhost:49156 URL:
$ curl -i http://localhost:49156
HTTP/1.1 200 OK
Date: Thu, 21 May 2015 00:39:52 GMT
Server: Apache/2.4.10 (Debian)
Set-Cookie: 6b690bb29883a1fb2d50e5547712a052=5qdo9u7m32e64jncjb7v30p8k3; path=/; HttpOnly
Expires: Mon, 1 Jan 2001 00:00:00 GMT
Last-Modified: Thu, 21 May 2015 00:39:52 GMT
Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0
Pragma: no-cache
Vary: Accept-Encoding
Transfer-Encoding: chunked
Content-Type: text/html; charset=utf-8


Connected successfully to MariaDB database

MariaDB ( MySQL ) Access

The MariaDB database can be accessed via admin user and default password pass. As previously, first we need to obtain the host system port number linked to MariaDB database within a docker image by using $ sudo docker port lamp command. Next, we can connect to database:
mysql -uadmin -ppass -h 127.0.0.1 -P49155
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MySQL connection id is 5
Server version: 5.5.43-0+deb8u1 (Debian)

Copyright (c) 2000, 2015, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MySQL [(none)]> 

Additional Information

Reset MariaDB user password

The below command will set a new password 123for theadmin user :
SET PASSWORD FOR 'admin'@'%' = PASSWORD('123');

Restart lamp stack

$ sudo docker exec lamp service supervisor restart

Container Access

While your lamp container is running it can be access by:
$ sudo docker exec -it lamp /bin/bash
root@733ae4bebf83:/#
ARE YOU LOOKING FOR A LINUX JOB?
Submit your RESUME, create a JOB ALERT or subscribe to RSS feed on LinuxCareers.com.
LINUX CAREER NEWSLETTER
Subscribe to NEWSLETTER and receive latest news, jobs, career advice and tutorials.
DO YOU NEED ADDITIONAL HELP?
Get extra help by visiting our LINUX FORUM or simply use comments below.

You may also be interested in: