The first thing I wanted to do was setup a clean environment to do the build. Initially I was thinking I should get a virtual machine running. However, I’ve lately taking a liking to Linux containers (LXC). I set one up for a work project that needed to CentOS build environment. The build does better with a lot of processing power and memory, and a container is better than a virtual machine for this. So I followed a similar recipe to get my build environment setup for the PHP 7 and 5 test. Some people may choose to use Docker for container management. LXC is so simple and this doesn’t need to be deployed, so I don’t see a reason to add Docker.
I run Linux Mint on the Snow Dragon and LXC is installed. A coworker runs a much more lien Liunx OS and had to install it. Since I didn’t have to do this I will assume LXC is installed. For the test environment I am just going to use the latest Debian. So the container creation command looks like this:
sudo lxc-create -t /usr/share/lxc/templates/lxc-download -n php7_5 -- -d debian -r bullseye -a amd64
With the container created, I don’t need to do anything else to get it configured. Sometimes directories between the container and the host need to be shared. In that case, one could edit the configuration file for the container.
sudo nano /var/lib/lxc/php7_5/config
And in that file the add the line:
lxc.mount.entry = <host_path> <client_path> none rw,bind,create=dir 0 0
Where host_path is the location to share on the host machine, and client_path is where it shows up in the running container. Note that one can change the rw part of the mount to ro to create a read-only location. Nice if you want to access files, but don’t want the container to be able to make changes.
One other item in the config
Now that the container is created, need to start it:
sudo lxc-start php7_5
Once it is running we can login:
sudo lxc-attach php7_5
Logging out of the container is as simple as typing “exit”.
To shutdown the container the command:
sudo lxc-stop php7_5
And when finished testing we can remove the container with everything in it:
sudo lxc-destroy php7_5
Just like a virtual machine, anything done in the container only effects the container. However, memory and CPU resources are shared with the host. This is perfect for build environments as the container will run at native speeds with full memory access, but without any risk of messing up the host machine’s build environment.