- Lamp
- Versions
- Usage for site sample
- Usage for diem's site sample
- Usage for install testa's site
- Linux usage
- Mac OSX / Windows usage
Docker image for diem sites. Debian with LAMP, nodeJs, imagick... etc
ATTENTION: master/latest: PHP 7 version Call version you prefer in run command:
- lamp:latest
- lioshi/lamp:php5
- lioshi/lamp:php5v8js
This docker image is used to launch container with all necessary applicatives instances for diem CMF
- Debian
- Apache
- PHP 5 or 7
- Mysql
- Node
- ImageMagick
- NodeJs
- V8JS or not
- etc ...
Create local datas. Create host directories.
mkdir lioshi/data
mkdir /home/lioshi/data/lamp
mkdir /home/lioshi/data/lamp/conf
mkdir /home/lioshi/data/lamp/www
mkdir /home/lioshi/data/mysql
Directory /home/lioshi/data/lamp/conf contains apache conf files for each site
Directory /home/lioshi/data/lamp/www contains site's source's file
Add host locally (in your /etc/hosts file)
127.0.0.1 site.loc
On Mac OSX : the host Ip will be the IP you will be given when you'll start the Docker Quickstart terminal (IP of the "default" machine)
Run docker service
sudo service docker start
Ajouter user au group docker
groupadd docker
sudo usermod -aG docker $USER
exit
clone lioshi/lamp repo
cd /home/lioshi/gitlibs/
git clone https://github.com/lioshi/lamp.git
Build image LAMP for version you need, a root of repo LAMP directory
docker build --tag="lamp:latest" .
docker build -f Dockerfile-php5 --tag="lamp:php5" .
(optional) docker build -f Dockerfile-php5v8js --tag="lamp:php5v8js" .
Container launching (with sample site create)
docker run --privileged=true -d -p 80:80 -p 3306:3306 \
-v /home/lioshi/data:/data \
-v /home/lioshi/data/mysql:/var/lib/mysql \
-e MYSQL_PASS="admin" \
-e SITE_SAMPLE="create" \
--name=lamp \
lamp:latest
Container launching (with sample site erase if allready exists in /home/lioshi/data dir of host machine)
docker run --privileged=true -d -p 80:80 -p 3306:3306 \
-v /home/lioshi/data:/data \
-v /home/lioshi/data/mysql:/var/lib/mysql \
-e MYSQL_PASS="admin" \
-e SITE_SAMPLE="erase" \
--name=lamp \
lamp:latest
Create local datas. Create host directories.
mkdir /home/lioshi/data
mkdir /home/lioshi/data/lamp
mkdir /home/lioshi/data/lamp/conf
mkdir /home/lioshi/data/lamp/www
mkdir /home/lioshi/data/gitlibs/
git clone https://github.com/SidPresse/diem.git
cd /home/lioshi/data/gitlibs/diem
git submodule update --init --recursive
Directory /home/lioshi/data/lamp/conf contains apache conf files for each site Directory /home/lioshi/data/lamp/www contains site's source's file
Container launching
docker run --privileged=true -d -p 80:80 -p 3306:3306 \
-v /home/lioshi/data:/data \
-v /home/lioshi/data/mysql:/var/lib/mysql \
-e MYSQL_PASS="admin" \
--name=lamp \
--add-host=vm20.local:91.194.100.247 \
lamp:latest
Alternative launching with added hosts for container. Needed for install a diem site
docker run --privileged=true -d -p 80:80 -p 3306:3306 \
-v /home/lioshi/data:/data \
-v /home/lioshi/data/mysql:/var/lib/mysql \
-e MYSQL_PASS="admin" \
--name=lamp \
--add-host=sitediem.loc:127.0.0.1 \
--add-host=sitediem2.loc:127.0.0.1 \
--add-host=sitediem3.loc:127.0.0.1 \
--add-host=vm20.local:91.194.100.247 \
lamp:latest
Command line access of previous container
docker exec -it lamp env TERM=xterm bash
You are now into docker container Into CLI of container to install a new diem site:
Create directory of site into /data/lamp/www/ Into this dir launch your local diem, example:
php /data/lamp/lib/diem/install
Etc...
Sample for an sitediem2.loc site
mkdir /data/lamp/www/sitediem2 && \
cd /data/lamp/www/sitediem2 && \
php /data/gitlibs/diem/install && \
php /data/lamp/www/sitediem2/symfony theme:install && \
php /data/lamp/www/sitediem2/symfony db:loadDB && \
php /data/lamp/www/sitediem2/symfony less:compile-all
docker rm -f lamp
docker restart lamp
See status
apachectl status
apachectl configtest
Install package Xdebug
apt-get -y install php5-xdebug
find / -name 'xdebug.so' 2> /dev/null
Add extension to php.ini
echo 'zend_extension="/usr/lib/php5/20131226/xdebug.so"' >> /etc/php5/apache2/php.ini
echo 'display_errors = On' >> /etc/php5/apache2/php.ini
echo 'html_errors = On' >> /etc/php5/apache2/php.ini
apachectl restart
If needed
echo 'xdebug.max_nesting_level = 1000' >> /etc/php5/apache2/php.ini
echo 'xdebug.profiler_enable = 1' >> /etc/php5/apache2/php.ini
echo 'xdebug.profiler_output_name = xdebug.out.%t' >> /etc/php5/apache2/php.ini
echo 'xdebug.profiler_output_dir = /data' >> /etc/php5/apache2/php.ini
echo 'xdebug.profiler_enable_trigger = 1' >> /etc/php5/apache2/php.ini
apachectl restart
Container launching (with ElasticSearch link, for testa application usage)
launch previously "lioshi/elasticsearch" image with directory in host to persist elasticsearch indexations
docker run --privileged=true -d -p 9200:9200 -p 9300:9300 \
-v /home/lioshi/data/elasticsearch:/usr/share/elasticsearch/data \
--name=elasticsearch \
lioshi/elasticsearch
docker run --name memcached -p 11211:11211 -d lioshi/memcached
docker run --privileged=true -d -p 80:80 -p 3306:3306 \
-v /home/lioshi/data:/data \
-v /home/lioshi/data/mysql:/var/lib/mysql \
-e MYSQL_PASS="admin" \
--link elasticsearch \
--link memcached:memcached \
--name=lamp \
lamp:latest
docker exec -it lamp env TERM=xterm bash
NB: for information the link elasticsearch is used into config.yml file into testa :
fos_elastica:
clients:
default: { host: elasticsearch, port: 9200 }
docker exec -it lamp env TERM=xterm bash
php app/console fos:elastica:populate
Créer un fichier de testa.conf apache dans le dossier /home/lioshi/data/lamp/conf de l'hôte ou dans le dossier /data/lamp/conf du container bien sûr
<VirtualHost *:80>
ServerName testa.loc
DocumentRoot /data/lamp/www/testa/web
AddType application/x-httpd-php .php
DirectoryIndex app.php
<Directory /data/lamp/www/testa/web>
# Add correct content-type for fonts
AddType application/vnd.ms-fontobject .eot
AddType application/x-font-ttf .ttf
AddType application/x-font-opentype .otf
AddType application/x-font-woff .woff
AddType image/svg+xml .svg
# add deflate
<IfModule mod_deflate.c>
# compress text, html, javascript, css, xml:
AddOutputFilterByType DEFLATE text/plain
AddOutputFilterByType DEFLATE text/html
AddOutputFilterByType DEFLATE text/xml
AddOutputFilterByType DEFLATE text/css
AddOutputFilterByType DEFLATE application/xml
AddOutputFilterByType DEFLATE application/xhtml+xml
AddOutputFilterByType DEFLATE application/rss+xml
AddOutputFilterByType DEFLATE application/javascript
AddOutputFilterByType DEFLATE application/x-javascript
# Compress compressible fonts
AddOutputFilterByType DEFLATE application/x-font-ttf application/x-font-opentype image/svg+xml
</IfModule>
# Add expiration dates to static content
# sudo a2enmod expires && sudo apache2ctl restart
<IfModule mod_expires.c>
ExpiresActive On
ExpiresByType image/gif "access plus 1 year"
ExpiresByType image/png "access plus 1 year"
ExpiresByType image/jpg "access plus 1 year"
ExpiresByType image/jpeg "access plus 1 year"
ExpiresByType image/png "access plus 1 year"
ExpiresByType image/x-icon "access plus 1 year"
ExpiresByType image/svg+xml "access plus 1 year"
ExpiresByType text/css "access plus 1 year"
ExpiresByType text/javascript "access plus 1 year"
ExpiresByType application/x-Shockwave-Flash "access plus 1 year"
ExpiresByType application/vnd.ms-fontobject "access plus 1 year"
ExpiresByType application/x-font-ttf "access plus 1 year"
ExpiresByType application/x-font-opentype "access plus 1 year"
ExpiresByType application/x-font-woff "access plus 1 year"
</IfModule>
<IfModule mod_rewrite.c>
RewriteEngine On
#<IfModule mod_vhost_alias.c>
# RewriteBase /
#</IfModule>
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ app.php [QSA,L]
</IfModule>
</Directory>
</VirtualHost>
Et ajouter dans le /etc/hosts de l'hôte
127.0.0.1 testa.loc
Cloner https://github.com/SidPresse/testa.git (ou un fork si vous n'avez pas accès) dans le dossier /data/lamp/www de l'hôte
cd /home/lioshi/data/lamp/www
git clone https://github.com/SidPresse/testa.git
Créer le fichier composer.json à l'image de composer.json.dist
cp /home/lioshi/data/lamp/www/testa/composer.json.dist /home/lioshi/data/lamp/www/testa/composer.json
Dupliquer le fichier parameters.yml sur l'hôte
cp /home/lioshi/data/lamp/www/testa/app/config/parameters.yml.dist /home/lioshi/data/lamp/www/testa/app/config/parameters.yml
Lancer à la racine du projet un
composer update
NB: Composer va demander un token pour l'accès à certains repo privés, suivez les directives de composer: Générez un jeton pour vous sur github: https://github.com/settings/tokens Nous recevons notre jeton, par exemple: 1234567890abcdef1234567890abcdef123456789 Exécutez la commande dans la console:
composer config -g github-oauth.github.com 1234567890abcdef1234567890abcdef123456789
Si problème de config avec composer update, ou alors pour gagner du temps car le composer update demande beaucoup de temps pour "puller" tous les vendors nécessaires de packagist:
cat vendors.tar.gz-* > vendors.tar.gz
tar -xzvf vendors.tar.gz
Mettra une version qui fonctionne (en date du fichier) de tous les vendors nécessaires. Un composer update
peut être lancé ensuite, il sera plus rapide.
Pour remmettre dans le repo git une archive de vendors (decoupee en fichier de 50mo: limite de github) à jour:
split -b 50000k vendors.tar.gz
On crée la base de données
php app/console doctrine:database:create
php app/console doctrine:schema:update --dump-sql
php app/console doctrine:schema:update --force // IMPORTANT : pour mettre à jour les entities
Les assets
php app/console assets:install web --symlink
php app/console assetic:dump
Purge du cache
php app/console cache:clear --env=prod
php app/console cache:clear --no-debug
Création du dossier des médias
mkdir web/uploads
mkdir web/uploads/media
chmod -Rf 777 web/uploads
Créer les dossiers de cache et de log (si besoin)
mkdir app/cache
mkdir app/logs
A la racine de votre projet lancer:
setfacl -R -m u:www-data:rwx -m u:`whoami`:rwx app/cache app/logs
setfacl -dR -m u:www-data:rwx -m u:`whoami`:rwx app/cache app/logs
Créer un utilisateur super admin
php app/console fos:user:create admin [email protected] admin --super-admin
Créer un utilisateur type Web avec peu d'accès
php app/console fos:user:create web [email protected] web
php app/console fos:user:promote web ROLE_ADMIN_WEB
Créer le dossier d'import K4
mkdir /data/import
mkdir /data/import/_xmlK4Testa
chmod -R 777 /data/import
Mettre quelques articles.xml à l'intérieur
Créer les dossiers utiles
mkdir /data/export
chmod -R 777 /data/export
mkdir /data/export/_exportTesta
chmod -R 777 /data/export/_exportTesta
mkdir /data/export/_exportTesta/_archive
chmod -R 777 /data/export/_exportTesta/_archive
mkdir /data/export/_mediasTesta
chmod -R 777 /data/export/_mediasTesta
Lancer un import des articles
php app/console testa:import k4 --env=prod
Lancer le populate d'elasticSearch
php app/console fos:elastica:populate --env=prod
sudo service docker start
docker restart elasticsearch
docker restart memcached
docker restart lamp
docker run --privileged=true -d -p 80:80 -p 3306:3306 -v /home/lioshi/data:/data -v /home/lioshi/data/mysql:/var/lib/mysql -e MYSQL_PASS="admin" --name=lamp --add-host=sitediem1.loc:127.0.0.1 --add-host=sitediem2.loc:127.0.0.1 --add-host=sitediem3.loc:127.0.0.1 --add-host=sitediem4.loc:127.0.0.1 --add-host=sitediem5.loc:127.0.0.1 --add-host=sitediem6.loc:127.0.0.1 --add-host=sitediem7.loc:127.0.0.1 --add-host=sitediem8.loc:127.0.0.1 --add-host=sitediem9.loc:127.0.0.1 --add-host=vm20.local:91.194.100.247 lamp:latest
docker exec -it lamp env TERM=xterm bash
docker run --privileged=true -d -p 9200:9200 -p 9300:9300 -v /home/lioshi/data/elasticsearch:/usr/share/elasticsearch/data --name=elasticsearch lioshi/elasticsearch
docker run --name memcached -p 11211:11211 -d lioshi/memcached
docker run --privileged=true -d -p 80:80 -p 3306:3306 -v /home/lioshi/data:/data -v /home/lioshi/data/mysql:/var/lib/mysql -e MYSQL_PASS="admin" --link elasticsearch --link memcached --name=lamp --add-host=sitediem1.loc:127.0.0.1 --add-host=sitediem2.loc:127.0.0.1 --add-host=sitediem3.loc:127.0.0.1 --add-host=sitediem4.loc:127.0.0.1 --add-host=sitediem5.loc:127.0.0.1 --add-host=sitediem6.loc:127.0.0.1 --add-host=sitediem7.loc:127.0.0.1 --add-host=sitediem8.loc:127.0.0.1 --add-host=sitediem9.loc:127.0.0.1 --add-host=vm20.local:91.194.100.247 lamp:latest
docker exec -it lamp env TERM=xterm bash
docker ps - Lists containers.
docker logs - Shows us the standard output of a container.
docker stop - Stops running containers.
ifconfig docker0
get IP adresse of docker0 In workbench use this IP and admin user with password choose in docker run -e MYSQL_PASS var
sudo service docker start && \
docker rm -f lamp && \
docker run --privileged=true -d -p 80:80 -p 3306:3306 -v /data:/data -v /data/mysql:/var/lib/mysql -e MYSQL_PASS="admin" --name=lamp --add-host=sitediem.loc:127.0.0.1 --add-host=sitediem2.loc:127.0.0.1 --add-host=sitediem3.loc:127.0.0.1 --add-host=vm20.local:91.194.100.247 lamp:latest && \
docker exec -it lamp env TERM=xterm bash
No persist mysql db via volume host/container possible with restriction of permissions between host -> VM -> container Then no persitence with volume used:
-v /data/mysql:/var/lib/mysql
But use var MYSQL_PERSIST_BY_CRON to made a cron launch regulary (every minute) to dump all bases in /data host dir. And when image is run then restore all databases if file saved by cron exists.
-e MYSQL_PERSIST_BY_CRON="yes"
Then launch those commands
sudo service docker start && \
docker rm -f lamp && \
docker run -d -p 80:80 -p 3306:3306 -v /data:/data -e MYSQL_PERSIST_BY_CRON="yes" -e MYSQL_PASS="admin" --name=lamp --add-host=sitediem.loc:127.0.0.1 --add-host=sitediem2.loc:127.0.0.1 --add-host=sitediem3.loc:127.0.0.1 --add-host=vm20.local:91.194.100.247 lamp:latest && \
docker exec -it lamp env TERM=xterm bash