filmov
tv
Quickly Deploy an Apache/PHP/MySQL Development Environment in Docker
Показать описание
#PHP #Development #Docker
--------------------------------------------------------------------
Installing Docker
--------------------------------------------------------------------
01. Log into the Linux host and run the following commands in a terminal window
# install prerequisites
sudo apt install apt-transport-https ca-certificates curl software-properties-common gnupg-agent -y
# add docker gpg key
# add docker software repository
# install docker
# enable and start docker service
sudo systemctl enable docker && sudo systemctl start docker
# add the current user to the docker group
sudo usermod -aG docker $USER
# reauthenticate for the new group membership to take effect
su - $USER
--------------------------------------------------------------------
Setting Up the Development Environment
--------------------------------------------------------------------
01. Continue with the following commands in a terminal window
# create working directories
mkdir ~/docker/apache2/www/html -p && mkdir ~/docker/apache2/{conf,php,ext} -p && mkdir ~/docker/mariadb -p
# extract apache conf container
docker run --rm php:apache tar -cC /etc/apache2 . | tar -xC ~/docker/apache2/conf
# extract php config from container
docker run --rm php:apache tar -cC /usr/local/etc/php . | tar -xC ~/docker/apache2/php
# extract php extensions from container
docker run --rm php:apache tar -cC /usr/local/lib/php/extensions . | tar -xC ~/docker/apache2/ext
# enable mysqli php extension
# set owner of working directories
sudo chown "$USER":"$USER" ~/docker -R
# run the mariadb docker container
docker run -d --name mariadb -e MYSQL_ROOT_PASSWORD='r00tp@$$' -v ~/docker/mariadb:/var/lib/mysql -p 3306:3306 --restart unless-stopped mariadb:latest
# run the php:apache container
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
# install the mysqli extension
docker exec -it www docker-php-ext-install mysqli
# restart the apache2 container
docker restart www
# create simple phpinfo page
--------------------------------------------------------------------
Adding phpMyAdmin (optional)
--------------------------------------------------------------------
01. Continue with the following commands in a terminal window
# download phpmyadmin
# create phpmyadmin directory
mkdir ~/docker/apache2/www/html/phpmyadmin -p
# extract downloaded phpmyadmin archive
# copy sample config file
# generate a random string
# copy the output string to the clipboard
openssl rand -base64 16
# edit phpmyadmin config
02. Paste the generated string in the blowfish_secret value
03. Update the Server host from localhost to the Docker host's DNS or IP
04. Press CTRL+O, Enter, CTRL+X to write the changes
06. Login with the username root and the password r00tp@$$
### Connect with me and others ###
--------------------------------------------------------------------
Installing Docker
--------------------------------------------------------------------
01. Log into the Linux host and run the following commands in a terminal window
# install prerequisites
sudo apt install apt-transport-https ca-certificates curl software-properties-common gnupg-agent -y
# add docker gpg key
# add docker software repository
# install docker
# enable and start docker service
sudo systemctl enable docker && sudo systemctl start docker
# add the current user to the docker group
sudo usermod -aG docker $USER
# reauthenticate for the new group membership to take effect
su - $USER
--------------------------------------------------------------------
Setting Up the Development Environment
--------------------------------------------------------------------
01. Continue with the following commands in a terminal window
# create working directories
mkdir ~/docker/apache2/www/html -p && mkdir ~/docker/apache2/{conf,php,ext} -p && mkdir ~/docker/mariadb -p
# extract apache conf container
docker run --rm php:apache tar -cC /etc/apache2 . | tar -xC ~/docker/apache2/conf
# extract php config from container
docker run --rm php:apache tar -cC /usr/local/etc/php . | tar -xC ~/docker/apache2/php
# extract php extensions from container
docker run --rm php:apache tar -cC /usr/local/lib/php/extensions . | tar -xC ~/docker/apache2/ext
# enable mysqli php extension
# set owner of working directories
sudo chown "$USER":"$USER" ~/docker -R
# run the mariadb docker container
docker run -d --name mariadb -e MYSQL_ROOT_PASSWORD='r00tp@$$' -v ~/docker/mariadb:/var/lib/mysql -p 3306:3306 --restart unless-stopped mariadb:latest
# run the php:apache container
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
# install the mysqli extension
docker exec -it www docker-php-ext-install mysqli
# restart the apache2 container
docker restart www
# create simple phpinfo page
--------------------------------------------------------------------
Adding phpMyAdmin (optional)
--------------------------------------------------------------------
01. Continue with the following commands in a terminal window
# download phpmyadmin
# create phpmyadmin directory
mkdir ~/docker/apache2/www/html/phpmyadmin -p
# extract downloaded phpmyadmin archive
# copy sample config file
# generate a random string
# copy the output string to the clipboard
openssl rand -base64 16
# edit phpmyadmin config
02. Paste the generated string in the blowfish_secret value
03. Update the Server host from localhost to the Docker host's DNS or IP
04. Press CTRL+O, Enter, CTRL+X to write the changes
06. Login with the username root and the password r00tp@$$
### Connect with me and others ###
Комментарии