How to Build a Complete PHP 7 Development Environment with Homestead, Xdebug, and Docker
This guide walks you through setting up a dedicated PHP 7 development environment using Laravel's Homestead Vagrant box, configuring Xdebug for step‑by‑step debugging, integrating PHPStorm, and optionally packaging everything into a ready‑to‑run Docker container.
Homestead – A Full‑Feature PHP 7 Box
Install the Homestead Vagrant box
Homestead is an official Laravel‑maintained Vagrant box based on Ubuntu 14.04 that bundles an LNMP stack, common PHP packages and modules. It provides a convenient way to set up a dedicated PHP 7 testing environment.
Before starting, install VirtualBox and Vagrant on your host OS.
Download the box: vagrant box add laravel/homestead-7 Verify the installation:
vagrant box listInstall the Homestead deployment script
git clone -b php-7 https://github.com/laravel/homestead.git Homestead7 cd Homestead7
bash init.shThe script creates Homestead.yaml in ~/.homestead, which will hold all LNMP project configurations.
Configure an LNMP project
mkdir php7Edit Homestead.yaml to add a folder sync and a site definition for the new php7 directory.
Bring the box up
<?php phpinfo(); ?>Run the box: vagrant up Add a host entry 192.168.10.10 php7.app and browse to http://php7.app/demo.php. Seeing the PHP info page confirms the environment works.
Xdebug – Debug PHP Code Step by Step
Compile and install Xdebug
wget http://xdebug.org/files/xdebug-2.4.0rc1.tgz
tar xvzf xdebug-2.4.0rc1.tgz
cd xdebug-2.4.0rc1
phpize7.0
./configure --enable-xdebug
make
sudo make installNote the path of the generated .so file.
Enable Xdebug
zend_extension="/usr/lib/php/20151012/xdebug.so"
xdebug.remote_enable = 1
xdebug.remote_connect_back = 1
xdebug.remote_port = 9000
xdebug.max_nesting_level = 500Copy the file to /etc/php/mods-available and create symlinks:
sudo ln -sfn /etc/php/mods-available/xdebug.ini /etc/php/7.0/cli/conf.d/20-xdebug.ini
sudo ln -sfn /etc/php/mods-available/xdebug.ini /etc/php/7.0/fpm/conf.d/20-xdebug.iniRestart PHP‑FPM: service php7.0-fpm restart Verify with php -m, php -i | grep xdebug, or by checking the Xdebug logo in the phpinfo page.
PHPStorm Integration
Install PHPStorm, open the php7 project, and add a PHP Web Application run configuration. Define a remote server that points to the Homestead VirtualBox instance and set the correct path mappings.
Set a breakpoint in demo.php, start the “Run/Debug” configuration, and PHPStorm will launch Chrome and pause execution at the breakpoint, allowing step‑by‑step debugging.
Package Everything into a Docker Container
A ready‑made Docker image boxueio/php7-with-xdebug bundles the LNMP stack, PHP 7, Xdebug and common Laravel modules.
docker pull boxueio/php7-with-xdebug
docker run -d --name php7 -p 8088:80 -p 33060:3306 -v [your source dir]:/var/www/php7.app php7-with-xdebugAdd php7.app to /etc/hosts and access the environment at http://php7.app:8088.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
21CTO
21CTO (21CTO.com) offers developers community, training, and services, making it your go‑to learning and service platform.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
