8. Work inside the PHP container¶
The Devilbox allows you to completely work inside the PHP container (no matter what version), instead of your host operating system.
This brings a lot of advantages, such as that you don’t have to install any development tool on your OS or if you are on Windows, you get a full blown Linux environment.
Additionally, special port-bindings and forwards are in place that allows you to even interchangably work locally or inside the container without having to alter any php config for database and other connections.
Table of Contents
Entering the computer is fairly simple. The Devilbox ships with two scripts to do that. One for
Linux and MacOS (
shell.sh) and another one for Windows (
# Navigate to the Devilbox directory host> cd /path/to/devilbox # Run provided script host> ./shell.sh # Now you are inside the PHP Linux container firstname.lastname@example.org in /shared/httpd $
By using the provided scripts to enter the container you will become the user
This user will have the same uid and gid as the user from your host operating system.
So no matter what files or directories you create inside the container, they will have the same permissions and uid/gid set your host operating system. This of course also works the other way round.
If you want to find out more about synronized container permissions read up here: Syncronize container permissions
Sometimes however it is also necessary to do some actions that require super user privileges.
You can always become root inside the container by either impersonating it or by using
to issue commands.
sudo is configured to be used without passwords, so you can simply do the following:
# As user devilbox inside the container email@example.com in /shared/httpd $ sudo su - # You are now the root user firstname.lastname@example.org in /shared/httpd $
You can also use
sudo to run commands with root privileges without having to become root first.
# As user devilbox inside the container email@example.com in /shared/httpd $ sudo apt update firstname.lastname@example.org in /shared/httpd $ sudo apt install nmap
When you are inside the container and want to return to your host operating, just type
and you are out.
# As user devilbox inside the container email@example.com in /shared/httpd $ exit # You are now back on your host operating system host>
This section will give you an idea that there is actually no difference from inside the container and on your host operating system. Directory permissions, IP addresses, ports and DNS entries are fully syncronized allowing you to switch between container and host without having to change any settings.
The username inside the container (
devilbox) might be different from your local host operating
system username, however its actual uid and gid will match. This is to ensure file and directory
permissions are synronized inside and outside the container and no matter from which side you
create files and directories, it will always look as if they are owned by your system user.
One thing you should understand is the relation between the directories on your host operating system and the corresponding directory inside the PHP container.
The location of the data directory (HOST_PATH_HTTPD_DATADIR) on your host computer is controlled
HOST_PATH_HTTPD_DATADIR variable inside the
.env file. No matter what location you
set it to, inside the container it will always be mapped to
See the following table for a few examples:
|Host operating system||Inside PHP container|
The following table shows a mapping of IP addresses and hostnames. In other words, when you are inside the PHP container, you can reach the services via the below defined IP addresses or hostnames:
|MySQL, MariaDB, PerconaDB||mysql||mysql||172.16.238.12|
It is recommended to use hostnames as they can be remembered much easiert.
An example to access the MySQL database from within the PHP container:
# Access MySQL from your host operating system host> mysql -h 127.0.0.1 -u root -p # Access MySQL from within the PHP container firstname.lastname@example.org in /shared/httpd $ mysql -h mysql -u root -p
So when setting up a configuration file from your PHP project you would for example use
mysql as the host for your MySQL database connection:
<?php // MySQL server connection mysql_host = 'mysql'; mysql_port = '3306'; mysql_user = 'someusername'; mysql_pass = 'somepassword'; ?>
By default, ports are also synronized between host operating system (the ports that are exposed)
and the ports within the PHP container. This is however also configurable inside the
|Service||Port from host os||Port from within PHP container|
All project DNS records are also available from inside the PHP container independent of the value of TLD_SUFFIX.
The PHP container is hooked up by default to the bundled DNS server and makes use Setup Auto DNS.
You can achieve the same on your host operating system by explicitly enabling auto-dns. See also: Setup Auto DNS.
- You know how to enter the PHP container
- You know how to become root inside the PHP container
- You know how to leave the container
- You know that file and directory permissions are synronized
- You know by what hostnames you can reach a specific service
- You know that project urls are available inside the container and on your host