Aside from making the container configuration easier to understand, Docker Compose coordinates the creation, start and stop of the containers used together in the environment.
The environment has multiple sites served on various ports including at least one WordPress site, a phpmyadmin site and mysql. For virtual host names, nginx-proxy is being used for containers with virtual host environment properties set in their docker compose data. Additionally, the mysql db container is accessible from the host at 127.0.0.1:8001
Create this docker compose yaml file in the projects root directory with the nginx-proxy configuration.
Create this docker compose yaml file for the WordPress stack. This includes the linked MariaDB database and phpMyAdmin containers from their official repositories. Xdebug is not included in the official WordPress image on Docker Hub and will not be included in this configuration since it is using unmodified images. Adding xdebug and rebuilding the image is covered on page two.
Create new nginx-proxy and WordPress containers using the up command with docker-compose.
docker-compose -f nginx-proxy.yml -f wp.yml up
The -f flags specify the compose files to use. Multiple compose files are combined into a single configuration. This multiple file solution is for demonstration purposes. Here is a single file example that can be run without a file flag.
Stop the containers without removing them.
docker-compose -f wp.yml -f nginx-proxy.yml stop
Start the stopped containers. Include the nginx-proxy.yml first so when the WordPress containers are started the virtual hosts can be dynamically configured.
My favorite feature so far is in the form of an extension. The vscode-php-debug extension works better than any free PHP debugging solution I have tried, such as Eclipse, Netbeans or SublimeTextXdebug. In order to use the debugger, the Xdebug PHP extension will need to be installed for your version of PHP. Here are some Xdebug installation resources:
This post was written well before VS Code, however the Xdebug setup instructions should work just fine, XAMPP Windows Setup
My VS Code user preferences – I am not thrilled with the existing VS Code Git integration, I prefer the command line tools for this, so I have it disabled in my settings. Another setting I changed from the default, "workbench.editor.enablePreview": true – When this is set to true, a subsequent file open will close the previous file if it has not been double clicked or edited. I wanted to keep the files open, so I set this to false.
// Place your settings in this file to overwrite the default settings
"editor.fontFamily": "Fira Code",
// Is git enabled
Remote debugging with xdebug – As noted in the Remote Host Debugging section, To make VS Code map the files on the server to the local machine, add the serverSourceRoot and localSourceRoot settings in the project .vscode/launch.json file. For example,
After discovering how nice the vscode-php-debug extension works in Visual Studio Code on my Windows 10 laptop, I wanted this same setup for a PHP project on my work Mac Book Pro running OS X Yosemite (10.10). The version of XAMPP I currently have installed on the Mac is 5.6.11-0 and for this tutorial, there are a few requirements to consider:
Use homebrew to install the autoconf utility for producing configure scripts.
# install autoconf
brew install autoconf
XAMPP comes with phpize which we will want to utilize to prepare the build environment for the Xdebug PHP extension. If another version of phpize is installed, it will need to be renamed. Check to see if phpize is installed in /usr/bin:
ls -al | grep phpize
-rwxr-xr-x 1 root wheel 4508 Sep 9 2014 phpize
Starting with OS X 10.11 El Capitan, system files and processes are protected with the new System Integrity Protection feature. Therefore, the following writes to /usr/bin are not permitted unless SIP is disabled (not recommended). For a workaround, try adding this environment variable to the .bash_profile: export PATH=/Applications/XAMPP/xamppfiles/bin:$PATH
If the grep search returns phpize, similar to what is shown above, then rename it to phpize_bak.
Create a new symbolic link in /usr/bin to target the XAMPP version of phpize.
# navigate to the /usr/bin directory
# create symbolic link to XAMPP phpize
sudo ln -s /Applications/XAMPP/bin/phpize-5.6.11 phpize
# check phpize version
PHP Api Version: 20131106
Zend Module Api No: 20131226
Zend Extension Api No: 220131226
phpize -v command output should be similar to what is shown above.
Open the XAMPP phpinfo.php file in a web browser, for example, http://localhost/dashboard/phpinfo.php. In another browser window or tab, open https://xdebug.org/wizard.php and copy the phpinfo page content in the first window or tab and paste it into the textbox on the xdebug.org page. Then submit for analysis to determine the Xdebug source to download. The response should be a Summary and Tailored Installation Instructions.
Additionally, add these xdebug configuration settings in php.ini after the zend_extension setting:
xdebug.remote_autostart = 1
; uncomment these dev environment
; specific settings as needed
;xdebug.idekey = "netbeans-xdebug"
;xdebug.idekey = "sublime.xdebug"
;some pages in your Drupal site will not work default = 100
Optional – for development only
Find “max_execution_time” and set to unlimited:
This blog post addresses a common scenario — a local LAMP development environment on your Windows or OS X computer. You could use XAMPP on either Windows or OS X, MAMP on OS X or native Apache in OS X. Here, we will create a Linux virtual machine with Samba configured to share the Virtual Machine file system with the host computer. We will also create virtual hosts, install and configure WordPress and Xdebug.
First thing you will need is Virtual Machine software. For my Virtual Machine, I chose to install the free VMware Player. If your host operating system is OS X, you can install VirtualBox if you do not want to purchase VMware Fusion or Parallels. You could also use VirtualBox on a Windows host instead of VMware if you prefer.
Next, you will need to create a Linux virtual machine. I decided to Download Ubuntu Server 32 bit since it is compatible with the intel processor of my host computer.
After creating a new VM and installing Linux, time to get our dev environment setup. Install SSH so we can run commands from the host. Later we will use ssh to to tunnel the Xdebug connection from the VM back to the host.
Since we have set the hosts file to map 192.168.59.129 to ubuntu.vm, once you disconnect your current ssh session (Ctrl+D), you will need to use the host alias you specified in the hosts file to reconnect.
Samba Network Share
You can use Samba to share the /var folder in you virtual machine.
# install Samba
$ sudo apt-get install samba
Linux system permissions take precedence over Samba permissions. For example if a directory does not have Linux write permission, setting samba writeable = Yes will not allow to write to shared directory / share.
# edit Samba config
$ sudo nano /etc/samba/smb.conf
####### Authentication #######
security = user
# bottom of smb.conf
path = /etc
browsable = yes
read only = no
create mask = 0755
admin users = jim
path = /home
browsable = yes
read only = no
create mask = 0755
admin users = jim
path = /var
browsable = yes
read only = no
create mask = 0755
admin users = jim
Ctrl+C to exit nano, press Y to save and return to write your changes to the file.
Install the PAM authentication module for Samba which will sync the system users to the Samba user database.
# Install libpam-smbpass package
$ sudo apt-get install libpam-smbpass
# restart Samba for the new settings to take effect
$ sudo restart smbd
$ sudo restart nmbd
# set user jim as the owner of share directory
$ sudo chown -R jim /var/www
For OS X, open Finder, select Go > Connect to Server (command + K). Enter the server address: smb://ubuntu.vm and select Connect
For Windows, select Run from the Start menu or open Windows Explorer and enter:
Server Time Synchronisation
Server time is likely to become inaccurate in our development scenario. We can use Ubuntu’s NTP server and NTP’s server pool to keep the server datetime accurate.
# install ntp
$ sudo apt-get install ntp
# edit /etc/ntp.conf
$ sudo nano /etc/ntp.conf
# add these two lines
# change server time zone
$ sudo dpkg-reconfigure tzdata
Enabling Module Rewrite
The mod_rewrite Apache module is a rule-based rewriting engine to rewrite requested URLs. It is very useful for genarating SEO friendly URLs.
# enable the module
$ sudo a2enmod rewrite
# restart apache to activate the configuration change
$ sudo service apache2 restart
# download the latest WordPress to a downloads directory
$ mkdir ~/downloads
$ cd ~/downloads
$ wget http://wordpress.org/latest.tar.gz
# -z : Uncompress the resulting archive with gzip command.
# -x : Extract to disk from the archive.
# -v : Produce verbose output i.e. show progress and file names while extracting files.
# -f latest.tar.gz : Read the archive from the specified file.
# -C : To change the directory (current directory is default)
# this will create /var/www/wordpress since the archive root directory is wordpress
$ sudo tar -zxvf latest.tar.gz -C /var/www
# make yourself the owner
sudo chown jim /var/www/wordpress
Create MySql database, user and grant permissions in one line.
base_user is typically root
base_user_pass is password for base_user (no space between -p and base_user_pass is important)
mysql -u base_user -pbase_user_pass -e "create database new_db; GRANT ALL PRIVILEGES ON new_db.* TO new_db_user@localhost IDENTIFIED BY 'new_db_user_pass'"
If phpMyAdmin is installed, you can use it to create the wordpress database as described in this next section. Read my earlier blog post if you need help doing this,
Mint LAMP Development Environment
In the browser, goto http://ubuntu.vm/phpmyadmin/. Select the Databases tab and under “Create new database”, enter in a database name such as “wordpress”, and select Create. Collation will automatically be assigned by MySQL when the database tables are created, during the WordPress installation.
In the browser, goto http://wordpress.vm and start the installation. If you need to manually edit the wp-config.php file, you can do so with nano.
$ nano wp-config.php
// ** MySQL settings - You can get this info from your web host ** //
/** The name of the database for WordPress */
/** MySQL database username */
/** MySQL database password */
/** MySQL hostname */
When debugging from the host computer, use ssh to tunnel the debug-connection back to it.
# ssh remote port forwarding
ssh -R 9000:localhost:9000 email@example.com
Using the “-R” argument tells ssh to listen on TCP port 9000 on the ubuntu server and forward it back through the ssh connection to the TCP port specified (localhost:9000). So from Xdebug’s perspective on the Ubuntu server, it is talking to localhost on the local computer.
I decided it was time to ditch my Linux 13 KDE setup and try the improved MATE 1.6 desktop now that Linux Mint 15 released. I find it pretty slick and fast, a nice change from Windows when I decide to do some development in a true LAMP environment. Speaking of which, we need to get that installed. Before doing that, the first thing I like to do is open up a terminal and run:
sudo apt-get update
This will download the package lists from the repositories and update them with information on the latest package versions. If you have not installed LAMP (Linux, Apache, MySQL & PHP) please read my earlier blog post, Mint LAMP Development Environment. Then you can return to this post to add an IDE with debugging capabilities along with some other nice tools.
sudo apt-get install php5-xdebug
PHP 5.4.9-4ubuntu2 (cli) (built: Mar 11 2013 16:09:26)
Copyright (c) 1997-2012 The PHP Group
Zend Engine v2.4.0, Copyright (c) 1998-2012 Zend Technologies
with Xdebug v2.2.1, Copyright (c) 2002-2012, by Derick Rethans
sudo pluma /etc/php5/mods-available/xdebug.ini
Add the following xdebug config values after the zend_extension path value so it looks like this.
The IDE I prefer for Drupal development as of this writing is NetBeans. I found this post, Configuring NetBeans for Drupal development to be very helpful. In the Usage section of the post, the author suggests using the sites folder of your Drupal installation when creating the New Project > PHP Application with Existing Sources. This did not work for me, instead, I selected the root folder of my Drupal install as the Sources Folder for the NetBeans IDE project import. By including the entire Drupal installation in my NetBeans project, I could step through and debug any of the Drupal code including modules in the sites folder.
As of this writing, the latest stable version of Eclipse was Eclipse Juno (4.2). I downloaded the Eclipse Classic 4.2.2 64 bit Linux version from http://www.eclipse.org/downloads/. Make sure you download the appropriate 32 or 64 bit version of Eclipse to match your Linux Mint operating system. To check which version of Linux Mint you are running, in a terminal, enter
i686 = 32-bit; x86_64 = 64 bit
Open up a terminal, change to the Downloads directory and and extract the archive.
tar xzf eclipse-SDK-4.2.2-linux-gtk-x86_64.tar.gz
With superuser permissions, move the extracted eclipse directory and its contents into the /opt/ folder.
sudo mv eclipse /opt/
Create a symbolic link so you can start Eclipse from a terminal