Originally written to work with Patrick Louys' No Framework Tutorial for PHP.
I use Git Bash, which is installed with Git, as my SSH client, you can use whatever you prefer. Git Bash is a variant of MinGW.
Note: "head mode" means that the VM has a GUI, "headless mode" means that the VM is running, but there is no GUI, and requires a secure connection into the server, in this case by SSH.
- download Ubuntu
- create new VM inside Virtualbox
- assign iso to CD-ROM medium
- install ubuntu to VM
In the installation process, you will be required to create a password for the root account. Make this password as complex as feasibly possible. I usually have my password manager generate a password for me, and then I keep the password stored in my password manager in case I need it in the future. You will also be prompted to create a new user account and a password for this user account. This account will not have root access by default, so you will need to add it to sudo/sudoers.
If sudo is not installed already, it will need to be installed before you can add your user account to sudo/sudoers.
- start server in head mode
- access terminal, and switch user to root
su - root
- install sudo
apt-get install sudo
first, check that sudo/sudoers group existscat /etc/group
if the group does not exist, then create it
- in terminal, type
usermod -a -G sudo <user account>
, where<user account>
is replaced with your user account you've created during installation.
- install ssh via terminal
sudo apt-get install ssh
- install vim via terminal
sudo apt-get install vim
Port forwarding will need to be set up in Virtualbox in order to SSH into the VM from your SSH client.
- Settings -> Network -> Attached to: NAT -> Advanced -> Port Forwarding
-
name the rule
ssh
-
host port:
3022
-
guest port:
22
- leave guest/host IP blank
- this allows SSHing into the VM
-
name the rule
web server
-
host port:
8080
-
guest port:
80
- leave guest/host IP blank
- this allows accessing the guest web server by host web browser
-
- create directory on Windows computer somewhere
- e.g. C:\ubuntu-share
- start VM with head
- in the VM window, click on Devices menu, Shared Folders
- add shared folder from Windows computer, checkmark auto-mount and make permanent
- if make permanent isn't checkmarked, the shared folder will have to be added again the next time the VM is booted up
- also in Devices menu, Insert Guest Additions CD image
- this will install the required software on the ubuntu VM to make the shared folder work
- if Linux gives an error: Oops! There was a problem running this software. Unable to locate the program, then add exec to /etc/fstab for /dev/sr0
- install software (it will be an autorun prompt)
- restart VM
- either start the VM in headless mode and SSH in, or open the VM normally and open terminal
- to ssh into VM:
ssh -p 3022 <account name>@127.0.0.1
- to ssh into VM:
- create a directory in ubuntu to mount the share folder to
- e.g.
mkdir ~/share
- e.g.
sudo mount -t vboxsf ubuntu-share ~/share
- ubuntu-share is the folder name from shared folders (Windows dir), ~/share is the folder location in ubuntu
- create a file in ubuntu-share, e.g. index.php (put
<?php phpinfo();
in the file) - check that it's in ~/share by ls in the folder, it should be in there
For additional information on setting up shared folders for a Windows host and a Linux guest
- boot up VM in headless mode
- open git bash
- ssh into VM
ssh <username>@127.0.0.1 -p 3022
- install php
sudo apt-get update
sudo apt-get install software-properties-common
sudo add-apt-repository ppa:ondrej/php
sudo apt-get update
sudo apt-get install php7.2-fpm
To use PHP's built-in web server, apache must be shutdown
(Failed to listen on 0.0.0.0:80 (reason: Address already in use))
sudo /etc/init.d/apache2 stop
- Navigate to shared folder
- e.g. cd ~/share
sudo php -S 0.0.0.0:80
- requires sudo because it'll say permission denied on port 80
- check that it's working in host web browser by going to:
127.0.0.1:8080
using index.php
<?php
phpinfo();
should show php's info