I don't work with WP neither PHP. But sometimes I'm asked to have a look at a wordpress site (we've all been through this ... sight)
Instead of installing LAMP or whatever, I'd rather sandbox the shit in a docker, so I can easily uninstall everything once done.
I find the docker-compose
approach as suggested in the official wordpress docker kind of complicated.
Instead, since it is for development purpose only, I'd rather have a single Docker that would contain the whole PHP + MySQL config, and simply having to:
Replace DB_NAME
, DB_USER
, DB_PASSWORD
and DB_HOST
in wp-config.php
Import the SQL of the existing DB. Eg. docker run mydocker /bin/mysql-import ~/Desktop/export.sql
docker start mydocker --source ~/Workspace/myproject
Does this approach make sense? Are there any ressource I could find to achieve this (if it hasn't been done already)?
This shall certainly be improved, but here are the steps I took:
docker pull linode/lamp
sudo docker run -p 80:80 -v <local_path_to_site_sources>:/var/www/<sitename> -t -i linode/lamp /bin/bash
At this step, you have forwarded Docker's port 80 to your host 80 (which means you can try out http://localhost and should get a result), entered into the docker's bash with /var/www/<sitename>
containing your source code.
Unfortunately there is still some little config to make, which should be automated IMHO.
apt-get update
(no more sudo, you are root there)apt-get install php5-mysql
(for some unfortunate reason, the package was missing)/var/www/<sitename>/log
exists by running mkdir -p /var/www/<sitename>/log
Run nano /etc/apache2/sites-available/<sitename>.conf
with the following content (everything's detailed there):
ServerAdmin webmaster@ # Probably not mandatory ServerAlias # Probably not mandatory
# Index file and Document Root (where the public files are located) DirectoryIndex index.html index.php DocumentRoot /var/www/ # Log file locations LogLevel warn ErrorLog /var/www//log/error.log CustomLog /var/www//log/access.log combined
Run a2ensite <sitename>
mysql -u root -p
password: Admin2015
as explained herecreate database <dbname>;
then exit
Import current data if exists: mysql -u root -p <dbname> < <dbbackupfile>.sql
(note that the <dbbackupfile>.sql
needs to be available in the docker, so putting in into your <local_path_to_site_sources>
shall help.
Update (from your host, not the docker, the files are shared) wp-config.php
with:
/** Nom de la base de données de WordPress. */ define('DB_NAME', '');
/** Utilisateur de la base de données MySQL. */ define('DB_USER', 'root');
/** Mot de passe de la base de données MySQL. */ define('DB_PASSWORD', 'Admin2015');
/** Adresse de l'hébergement MySQL. */ define('DB_HOST', '127.0.0.1');
Run service apache2 restart; service mysql restart
Go check http://localhost : annnnnndd DONE!!