In the last article I took a gander at setting up a basic improvement condition on Windows utilizing WAMP. In the event that you might want to audit that, it would be ideal if you visit https://blog.phpbb.com/2017/02/28/how-to-set-up-an advancement situation on-windows/
The more you spend creating programming, the all the more truly you begin to take setting up the ideal improvement condition. Also, the all the more truly you begin to take following accepted procedures. One of these practices is setting up an advancement situation that matches the generation condition that you are utilizing. There are two or three reasons why this is helpful. Right off the bat, if different designers are taking a shot at a task then you can make sure that code composed by one individual will work for alternate engineers. What’s more, also, when that code is conveyed to a generation domain you realize that it ought to hypothetically work straight away observing it was composed in a coordinating advancement condition.
A basic case of neglecting to do this would be if an engineer was utilizing a PHP7 improvement condition and composed an announcement which incorporated the spaceship administrator. On the off chance that this code was then sent on a PHP5 domain, the code would not work. In the event that the engineer, realizing that the generation condition runs PHP5, had set up their advancement condition as needs be this bug would have been seen much sooner.
At initial introduction, it appears to be incomprehensible that an engineer composing and testing code on their Windows PC can set up a neighborhood improvement condition that matches their live web server which in by far most of cases is running on Unix. However, this is really not the situation, it is conceivable – and indeed, not too troublesome – to do this.
It should be possible utilizing two or three Windows programs that empower the making of virtual Unix machines. Essentially this means you can set up a lightweight Unix server that keeps running inside Windows, so you can in any case utilize your most loved Windows content managers and instruments yet with regards to running the code it will be kept running in Unix. In this article I’ll be taking a gander at Vagrant and VirtualBox.
Note: This article expect fundamental information of the order line on Windows and Unix.
SETTING UP VAGRANT, VIRTUALBOX and PUTTY
The initial step is to introduce VirtualBox, which Vagrant backings out of the crate. VirtualBox is a program which takes into account the administration of virtual machines and can be downloaded from: https://www.virtualbox.org/wiki/Downloads
Utilize the default set up choices.
Now Vagrant needs to be installed. Vagrant runs alongside VirtualBox to allow users to quickly provision new and different types of development environments. It can be downloaded from https://www.vagrantup.com/downloads.html and once again the default installation options should be used.
You can confirm that it’s correctly installed by rebooting your PC, and then opening Command Prompt (cmd.exe) and running the command “vagrant”. This should return example usage options.
Note: Version 1.94 of Vagrant seems to have a couple of bugs, which I encountered trying to install this on a Windows 7 machine (I know, I know! But it’s the only Windows PC I had access to). The first resulted in a number of error messages when running the “vagrant” command. This was resolved by running “vagrant plugin install vagrant-share –plugin-version 1.1.8”. The second bug resulted in errors when running “vagrant up”, which I resolved by replacing 3 files – the procedure is explained at
https://github.com/mitchellh/vagrant/issues/8520#issuecomment-297792410 – it appears this will be resolved in v1.95.
With Vagrant now installed, create a folder on your PC where you want your Vagrant projects. I called mine VagrantProjects. In your command prompt window, “cd” into this folder. Then run this command: “vagrant init”. This will create a Vagrantfile. This is a file where development environment settings are stored.
Now run “vagrant box add ubuntu/xenial64” – this will add an Ubuntu 16.04 virtual box, a new release of Ubuntu. It is worth bearing in mind that there are plenty of other boxes you can choose from. Some even have the LAMP stack pre-installed which if you want to save time could be a good option. You can view a list at https://atlas.hashicorp.com/boxes/search
The download may take some time on slower connections. When it’s complete, open Vagrantfile and modify this variable to have the listed value:
config.vm.box = “ubuntu/xenial64”
Note: these steps can be combined if you simply run “vagrant init ubuntu/xenial64”
Then run “vagrant up” while still in that directory.
Watch the messages in the command prompt window for the SSH username and password. You will need to note these down so when the virtual machine is running you can log into it.
Once the VM (virtual machine) has booted, you can open the VirtualBox application to confirm that it has indeed been created. If you run “vagrant status” you will see that the state is running.
Next, run “vagrant ssh” – on Windows it likely won’t work. But it will provide some important information. The host/port/username will be shown again but so will “private key” – this path is important.
An SSH client needs to be installed now. This is a client that allows you to log in to a remote server – but in this case it can be used to log in to the virtual machine. Putty is a very lightweight and effective client, and can be downloaded and installed from https://www.chiark.greenend.org.uk/~sgtatham/putty/latest.html – download both Putty and PuttyGen.
Firstly, open PuttyGen, click load, and the choose the private key path specified a moment ago. Then using the default settings, click save private key. I called it pg_private_key.ppk. This key is later used merely to authenticate you and grant you access to the virtual machine.
Now open Putty. In the first screen fill out these details, which should match the information Vagrant displayed to you earlier:
Host name: 127.0.0.1
Now go to Connections -> SSH -> Auth -> Private key file for authentication and select the ppk file.
Under Connections -> Data you can enter under “auto login username” the username shown in the command prompt earlier. Then go to Sessions, and under Saved Sessions type “Vagrant”. Click “Save”. Now you will not have to perform this step again, you can simply double click “Vagrant” in the future to quick-load your VM.
Finally click open, and a new command window will appear. But this time, it’s your new virtual server!
From the Putty window, type “logout” to leave the session. And in the Windows command prompt window type “vagrant halt” to shutdown the virtual machine. “vagrant status” will confirm that the state is powered off.
INSTALLING THE LAMP STACK
The “Linux” part has been handled now, but to continue setting up a local development environment Apache, MySQL and PHP is still required.
Firstly, Apache can be installed by running the following commands (once you have logged into the VM through Putty):
sudo apt-get -y update
sudo apt-get -y install apache2
sudo rm -rf /var/www/
sudo ln -fs /vagrant/ /var/www
So that development can take place in Windows, but run on the Linux virtual machine there needs to be some level of directory synchronisation. The final two commands create a symbolic link so you can store your files locally but also run on the webserver in the virtual machine.
On your local machine, inside the VagrantProjects folder create a new folder called html/ – this is important because of the way Apache is set up. In that folder, create a file called index.html and put this in it:
Note: A shortcut for this can be followed by creating a script like the one at https://www.vagrantup.com/intro/getting-started/provisioning.html
Now open Vagrantfile and add the following entry:
config.vm.network :forwarded_port, guest: 80, host: 4567
Now run “vagrant halt” followed up by “vagrant up” to restart the virtual machine.
Go to http://127.0.0.1:4567/index.html in your browser and you will see the file created above.
With Apache now running, let’s install MySQL:
sudo apt-get -y install mysql-server php7.0-mysql
When prompted, choose a password for the MySQL database.
You can test the connection from the command line (still using the Putty window, as it’s local to the virtual machine) by typing this command:
mysql -h 127.0.0.1 -u root -p
… and entering the password chosen above.
Pro tip: if you wanted to quickly run an SQL query, you can do it by typing the query after you’ve run the previous command. Type “CREATE DATABASE test;” to try it out. Enter “exit” to exit from the query window.
Now to install PHP7:
sudo apt-get -y install php libapache2-mod-php
phpBB requires the XML/DOM extension, so also run this:
sudo apt-get -y install php-xml
Now create a file called phpinfo.php in your html/ folder, and put this in it:
And then run http://127.0.0.1:4567/phpinfo.php and you will see that PHP is running correctly. As this demonstrates, any files or subdirectories you put in the /html directory become accessible through the web server.
By this point, you have everything you need to install phpBB and you can use the “test” database that was created in an earlier step.
To install phpMyAdmin – a fantastic tool for viewing database tables and running queries in a visually appealing way – do the following. Run:
sudo apt-get -y install phpmyadmin
Select apache2 by pressing enter, when prompted. Then select “yes” when shown the dbconfig-common prompt. Finally enter your MySQL password.
Now run the following database queries (on the command line, using the mysql command demonstrated in the previous section):
GRANT ALL ON test.* TO phpmyadmin@localhost IDENTIFIED BY ‘password’;
This creates a database user called phpmyadmin (with a password of your choice, specified in the command above) with access to the test database created earlier.
Then run this command:
sudo vim /etc/apache2/apache2.conf
This will open the vim text editor. Press “i” to enter text edit mode. Then add the following line at the end of the file:
Press “Escape”, then “:wq” to save and exit the file.
With this done, you will now be able to log into phpMyAdmin by visiting this URL – http://127.0.0.1:4567/phpmyadmin/ – after logging in you can see the dashboard and view your tables and run queries.
With this complete, you now have a working development environment running on Linux with Apache, PHP and MySQL installed along with phpMyAdmin.