123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105 |
- <!DOCTYPE html>
- <html lang="en" xmlns="http://www.w3.org/1999/xhtml">
- <head>
- <title>Quickly Deploy an Apache/PHP/MySQL Development Environment in Docker</title>
- <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
- <meta charset="UTF-8">
- <meta name="keywords" content="Docker Made Easy,Home Lab,Home Lab Ideas,Install Guide,Self-Hosted,Coding,Fun With Code,HTTP,PHP,PHP Developer,Web Server,Web Developer,Linux,Homelab,Docker Tutorial,Docker Simplified,Docker Made Simple,Docker Installation Tutorial,Docker How To,Docker,Container,MariaDB,Apache HTTPD,LAMP,How To,Tutorial,i12bretro">
- <meta name="author" content="i12bretro">
- <meta name="description" content="Quickly Deploy an Apache/PHP/MySQL Development Environment in Docker">
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
- <meta name="revised" content="08/24/2023 07:53:04 PM" />
- <link rel="icon" type="image/x-icon" href="includes/favicon.ico">
- <script type="text/javascript" src="https://code.jquery.com/jquery-3.5.1.min.js"></script>
- <script type="text/javascript" src="includes/js/steps.js"></script>
- <link href="css/steps.css" rel="stylesheet" type="text/css" />
- </head>
- <body>
- <div id="gridContainer">
- <div class="topMargin"></div>
- <div id="listName" class="topMargin">
- <h1>Quickly Deploy an Apache/PHP/MySQL Development Environment in Docker</h1>
- </div>
- <div></div>
- <div id="content">
- <h2>Installing Docker</h2>
- <ol>
- <li>Log into the Linux host and run the following commands in a terminal window
- <div class="codeBlock"># install prerequisites<br />
- sudo apt install apt-transport-https ca-certificates curl software-properties-common gnupg-agent -y<br />
- # add docker gpg key<br />
- curl -fsSL https://download.docker.com/linux/$(awk -F'=' '/^ID=/{ print $NF }' /etc/os-release)/gpg | sudo apt-key add -<br />
- # add docker software repository<br />
- sudo add-apt-repository "deb [arch=$(dpkg --print-architecture)] https://download.docker.com/linux/$(awk -F'=' '/^ID=/{ print $NF }' /etc/os-release) $(lsb_release -cs) stable"<br />
- # install docker<br />
- sudo apt install docker-ce docker-compose containerd.io -y<br />
- # enable and start docker service<br />
- sudo systemctl enable docker && sudo systemctl start docker<br />
- # add the current user to the docker group<br />
- sudo usermod -aG docker $USER<br />
- # reauthenticate for the new group membership to take effect<br />
- su - $USER</div>
- </li>
- </ol>
- <h2>Setting Up the Development Environment</h2>
- <ol>
- <li>Continue with the following commands in a terminal window
- <div class="codeBlock"># create working directories<br />
- mkdir ~/docker/apache2/www/html -p && mkdir ~/docker/apache2/{conf,php,ext} -p && mkdir ~/docker/mariadb -p<br />
- # extract apache conf container<br />
- docker run --rm php:apache tar -cC /etc/apache2 . | tar -xC ~/docker/apache2/conf<br />
- # extract php config from container<br />
- docker run --rm php:apache tar -cC /usr/local/etc/php . | tar -xC ~/docker/apache2/php<br />
- # extract php extensions from container<br />
- docker run --rm php:apache tar -cC /usr/local/lib/php/extensions . | tar -xC ~/docker/apache2/ext<br />
- # copy the production php.ini<br />
- cp ~/docker/apache2/php/php.ini-development ~/docker/apache2/php/php.ini<br />
- # enable mysqli php extension<br />
- sed -i "s/;extension=mysqli/extension=mysqli/" ~/docker/apache2/php/php.ini<br />
- # set owner of working directories<br />
- sudo chown "$USER":"$USER" ~/docker -R<br />
- # run the mariadb docker container<br />
- docker run -d --name mariadb -e MYSQL_ROOT_PASSWORD='r00tp@$$' -v ~/docker/mariadb:/var/lib/mysql -p 3306:3306 --restart unless-stopped mariadb:latest<br />
- # run the php:apache container<br />
- docker run -d --name www -v ~/docker/apache2/www:/var/www -v ~/docker/apache2/conf:/etc/apache2 -v ~/docker/apache2/php:/usr/local/etc/php -v ~/docker/apache2/ext:/usr/local/lib/php/extensions -p 8080:80 --restart unless-stopped php:apache<br />
- # install the mysqli extension<br />
- docker exec -it www docker-php-ext-install mysqli<br />
- # restart the apache2 container<br />
- docker restart www<br />
- # create simple phpinfo page<br />
- echo -e "<?php\n\tphpinfo();\n?>" > ~/docker/apache2/www/html/phpinfo.php</div>
- </li>
- <li>Open a web browser and navigate to http://DNSorIP/phpinfo.php</li>
- </ol>
- <h2>Adding phpMyAdmin (optional)</h2>
- <ol>
- <li>Continue with the following commands in a terminal window
- <div class="codeBlock"># download phpmyadmin<br />
- wget -O /tmp/phpmyadmin.tar.gz https://www.phpmyadmin.net/downloads/phpMyAdmin-latest-english.tar.gz<br />
- # create phpmyadmin directory<br />
- mkdir ~/docker/apache2/www/html/phpmyadmin -p<br />
- # extract downloaded phpmyadmin archive<br />
- tar xf /tmp/phpmyadmin.tar.gz --strip-components=1 -C ~/docker/apache2/www/html/phpmyadmin<br />
- # copy sample config file<br />
- cp ~/docker/apache2/www/html/phpmyadmin/config.sample.inc.php ~/docker/apache2/www/html/phpmyadmin/config.inc.php<br />
- # generate a random string<br />
- # copy the output string to the clipboard<br />
- openssl rand -base64 16<br />
- # edit phpmyadmin config<br />
- nano ~/docker/apache2/www/html/phpmyadmin/config.inc.php</div>
- </li>
- <li>Paste the generated string in the blowfish_secret value</li>
- <li>Update the Server host from localhost to the Docker host's DNS or IP</li>
- <li>Press CTRL+O, Enter, CTRL+X to write the changes</li>
- <li>In a new tab, navigate to http://DNSorIP/phpmyadmin</li>
- <li>Login with the username root and the password r00tp@$$</li>
- </ol> </div>
- </div>
- </body>
- </html>
-
|