Docker-php5.6 setup on ubuntu
Docker - php5.6 setup on ubuntu:
https://hub.docker.com/r/gotechnies/php-5.6-alpine
$: mkdir php56-lamp
$: cd php56-lamp
$: touch docker-compose.yml (copy the file content from url
https://hub.docker.com/r/gotechnies/php-5.6-alpine ) OR copy paste following lines
version: “2.0”
services:
web:
container_name: php5.6
image: gotechnies/php-5.6-alpine
ports:
– “80:80”
– “443:443”
links:
– db
– phpmyadmin
volumes:
– ./html:/var/www/html
restart: always
db:
image: mysql:5.6
container_name: database
ports:
– 3306:3306
environment:
MYSQL_DATABASE: mysql_server
MYSQL_USER: magento2
MYSQL_PASSWORD: gotechnies
MYSQL_ROOT_PASSWORD: gotechnies
restart: always
phpmyadmin:
image: phpmyadmin/phpmyadmin
container_name: phpmyadmin
environment:
– PMA_ARBITRARY=1
restart: always
links:
– db
ports:
– 8080:80
volumes:
– /sessions$: docker compose up -d OR docker-compose up -d
$: docker ps
$: docker exec -it php5.6 bash (for ssh to php5.6 & apache)
bash-4.4# httpd -t
AH00558: httpd: Could not reliably determine the server’s fully qualified domain name, using
172.20.0.4. Set the ‘ServerName’ directive globally to suppress this message
Syntax OK
bash-4.4# httpd -k stop
AH00558: httpd: Could not reliably determine the server’s fully qualified domain name, using
172.230.0.4. Set the ‘ServerName’ directive globally to suppress this message
Terminated
bash-4.4# httpd -k restart
AH00558: httpd: Could not reliably determine the server’s fully qualified domain name, using
172.20.0.4. Set the ‘ServerName’ directive globally to suppress this message
$: docker inspect -f ‘{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}’ php5.6
(for checking the IP of container)
# Copy from host to container
$: docker cp /your-file-path/yourdomain-backup.tar.gz php5.6:/var/www/yourdomain.com
$: docker cp /your-file-path/yourdomain-db.tar.gz php5.6:/var/www/yourdomain.com
$: docker exec -it database bash
root@f9398afe030d:/# mysql -u root -pYourrootpass
mysql> create database yourdatabase;
CREATE USER yourdbuser@’%’ IDENTIFIED BY ‘yourdbpass’;
GRANT ALL PRIVILEGES ON yourdatabase.* TO ‘yourdbuser’@’%’;
$: docker exec -i database mysql -u yourdbuser -p’yourdbpass’ yourdatabase <
/path-to-your-file/yourdatabase.sql
$: docker inspect -f ‘{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}’ databaseAdd host as “database” in your php application for db connection.
<?php
con_db_host = “database”
//database is db container name in above line
con_db_port = “3306”
con_db_id = “your-db-username”
con_db_pass = “your-db-pass”
con_db_name = “your-db-name”
tablepre
= “met_”
db_charset = “utf8”;
?>
$: a2enmod proxy
$: a2enmod proxy_http
$: a2enmod proxy_balancer
$: a2enmod proxy_connect
Enable above module for reverse proxy at Host (main linux server) of docker containers and
setup following vhost at Host of container
<VirtualHost *:80>
ServerName yourdomain.com
ServerAlias www.yourdomain.com
#Redirect permanent / http://www.yourdomain.com
ProxyPreserveHost On
ProxyRequests Off
ProxyPass / http://127.0.0.1:8081/
ProxyPassReverse / http://127.0.0.1:8081/
ServerAdmin yourdomain@gmail.com
ErrorLog /var/www/yourdomain.com/logs/error_log
CustomLog /var/www/yourdomain.com/logs/access_log common
</VirtualHost>
<VirtualHost *:443>
ServerAdmin admin@yourdomain.com
ServerName yourdomain.com
SSLEngine on
SSLCertificateFile /etc/ssl/yourdomain/yourdomain.crt
SSLCertificateKeyFile /etc/ssl/yourdomain/yourdomain.key
ProxyPreserveHost On
#ProxyRequests Off
ProxyPass / http://127.0.0.1:8081/ProxyPassReverse / http://127.0.0.1:8081/
#SSLEngine on
#SSLCertificateFile /var/www/yourdomain.com/ssl/glory.com.crt
#SSLCertificateKeyFile /var/www/yourdomain.com/ssl/glory.com.key
#SSLCACertificateFile /var/www/yourdomain.com/ssl/domain_bundle.crt
</VirtualHost>
Setup following vhost at the php5.6 docker container
bash-4.4# cat /etc/apache2/conf.d/yourdomain.com.conf
<VirtualHost *:80>
ServerName yourdomain.com
ServerAdmin yourdomain@gmail.com
DocumentRoot /var/www/yourdomain.com/htdocs/
<Directory /var/www/yourdomain.com/htdocs/>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
ErrorLog /var/www/yourdomain.com/logs/error_log
CustomLog /var/www/yourdomain.com/logs/access_log common
</VirtualHost>
For SSL
Enable following modules at Host of docker container
sudo a2enmod ssl
sudo a2enmod headers
sudo systemctl restart apache2
Let’s Encrypt (free, automated)
sudo apt install certbot python3-certbot-apache
sudo certbot –apache -d yourdomain.com
Manual/self-signed certificate
sudo mkdir -p /etc/ssl/yourdomain
sudo openssl req -x509 -nodes -days 365 -newkey rsa:2048 \
-keyout /etc/ssl/yourdomain/yourdomain.key \
-out /etc/ssl/yourdomain/yourdomain.crt
ServerName yourdomain.com
Redirect permanent / https://yourdomain.com
