Vagrant development environment for PHP

As a developer, I work on projects that require a variety of software, each tuned to different configurations. The easiest way to achieve this is to set up a virtual machine and configure that as per the need of the project. This allows me to keep my host machine clean, and share the virtual machine with other developers on the project.

In this blog, I’ll describe the configuration of a Vagrant machine that I’ve setup for PHP web development. Here’s a link to the box on vagrant cloud.

Vagrant configuration

Recommended configuration

The vagrant box runs Debian 10 Buster. It uses,

  1. 2 dedicated CPU cores
  2. 1560 MB of RAM from the host machine.

Port configuration

Following is the port configuration for the vagrant box,

Other configuration

  • Added vagrant user to www-data and adm group, in order to handle Apache permissions and view application logs.
  • SSH agent forwarding has been enabled.

Installed software

Listed below are software that have been installed on the system,

  1. Apache 2.4.38
  2. MariaDB 10.3.18
  3. htop, ncdu, curl, git, unzip
  4. PHP 7.3 and extensions
  5. Composer 1.9.1 (globally)
  6. Redis 5.0.3
  7. Node 12.14. 1 and npm 6.13.4 (via nvm)

Software configuration

  1. The base directory for Apache2 is configured to /vagrant/code. The vagrant user has been added to the www-data group to handle permission issues.
  2. Apache2 mod_rewrite module has been enabled.
  3. MariaDB has been configured with the following users,
    • Username: root / Password: T0P!33L
    • Username: admin / Password: C00La!d
  4. Following changes have been made to MariaDB configuration,
    • Increased innodb_buffer_pool_size to 768MB
    • Set innodb_file_per_table to 1.
    • Set max_allowed_packet to 256MB for MySQL, and 192MB for mysqldump
    • Enabled slow query logging. Long query time has been set to 5 seconds. Slow logs will be written to /var/log/mysql/mysql_slow.log.
  5. All PHP extensions required to run Laravel 6 have been installed. In addition, the tidy, xdebug, redis, and yaml extensions have been installed.
  6. Following changes have been made to PHP configuration file,
    • upload_max_filesize and post_max_size have been set to 20MB.
    • memory_limit has been set to 256MB.
    • Enabled error logging for both Apache and CLI.
  7. For Redis, maxmemory has been set to 256MB.
  8. Composer bin folder has been added to the PATH via .bashrc

PHP debugging support

Debugging support for PHP has been added via Xdebug and tested using VSCode with the PHP Debug extension.

Consider a sample VSCode project – debugging, created under /vagrant/code/debugging. This project has a file called index.php. Following is the configuration that needs to be put under the VSCode launch file. (/vagrant/code/debugging/.vscode/launch.json).

Following is the configuration for Xdebug,

Future improvements

I currently have the following things in mind,

  • The box is set to use 1536MB of RAM, and I might have to tweak this a little higher.
  • Test debugging support for applications run via the PHP server and on the PHP CLI
  • Install and setup XHProf and XHProf UI.

I plan on keeping this box up-to-date for the foreseeable future. I’m open to suggestions on how this box can be improved, and made more useful for PHP developers to quickly start their development.

Git hooks: Permission denied on a new HDD

I recently got a new Samsung 860 EVO 1TB SSD to add to my existing 128GB SSD that was filling up fast. After setting up the SSD on my machine using fstab, I started moving all my vagrant boxes and projects to a new partition dedicated to development. I mounted all the partitions under my home folder, and gave myself ownership of the respective folders.

I was ready to submit a patch to Wikimedia’s Gerrit platform. When you commit code, Gerrit runs a git commit-msg hook to add a Change-Id to every patch that is submitted for review. Committing code locally gave me the following error,

Continue reading “Git hooks: Permission denied on a new HDD”

Setting up MediaWiki, Vagrant and VSCode

The guide describes how to setup MediaWiki for development on Vagrant while adding support for debugging on VSCode using the XDebug PHP extension.

Various documents have been linked to which contain relevant information rather than copying it here again.

Continue reading “Setting up MediaWiki, Vagrant and VSCode”

Kerala Log 2 – Christmas Eve at Fort Kochi

Day 5, 6 – 22nd Dec – 23rd Dec

We spent these two days at home and finished a few household chores. I was also pursuing a possible work opportunity so we had our hands full.

Day 7, 8 – 24th Dec – 25th Dec – Merry Christmas!

We planned to attend the mass at the church on 25th Dec, 12:00 AM. As it would be too late to drive back home after that, we booked an Airbnb at Fort Kochi for that night.

Continue reading “Kerala Log 2 – Christmas Eve at Fort Kochi”

Kerala Log 1 – Fort Kochi

Day 1 – Dec 18th

It starts today – our 3 month trip to Kerala. We’ve been looking forward to this phase of our life for quite some time now and our excited that it is finally here.

We woke up early and finished some last minute packing. We were traveling on the Sabari express and the journey was 25 hours long. Although our tickets were booked from Secunderabad, we decided to board the train at Nampally – the starting station for the train. Two bikes to package and send to Kerala as luggage and boarding it from the origin point would give us more time to get the bikes packaged and boarded carefully.

Continue reading “Kerala Log 1 – Fort Kochi”