Beginning a simple PHP app
Last time I left you, we had a running Virtual Machine and maybe you have been tinkering with it a bit. If so, good for you! This is specifically aimed at PHP development so if you’re not interested in that then I maybe skip over this and wait until we get to play about with another technology.
PHP has changed lots since I began using it back in the early 90’s. Developing apps now is generally so much quicker and easier and anyone who is just getting into it has never really had it so good. Our first task is to get a dev environment up and there is a super quick and easy way to do this via a lovely website called PuPHPet which is an amalgamation of two very powerful tools.
The site allows us to build a configuration file for Vagrant that will install all the relevant bits off software that we need with very minimal effort. Please feel free to go and play but we don’t expect you to know what you’re doing which is why we have pre-built a configuration for you to work with so please download that and follow the instructions that we will run through in a bit. We are going to build a very simple website that and eventually ask the end user to fill in a form. We will save what the user fills in then maybe make some use of the data we collect. Now we’re not building a mass user based system so were not too bothered about the underlying technology here but if you’re interested our machine is configured to run the following:
- PHP 7.0 – The most recent version of PHP, this may not be supported on machines we want to deploy to but let’s not worry about that now.
- MySQL – Our database server, there are many options to choose from and for what we are building it really won’t matter what we choose
- Apache 2.x – An old but trustworthy Web server. We are using Apache mostly because I know it better and it again will be perfectly fine for our needs.
Once you have downloaded and extracted our configuration to a directory of your choice, open a terminal window and go to the extracted folder then type in.
This will deploy our new development machine and go and grab yourself a cup of tea/coffee/rum because this is going to take a while. For the people who may be interested what you have just done is invoke vagrant to talk to an automated configuration tool called puppet. Puppet is really powerful and can allow you to setup your machine in any way you like but understanding how it does that takes some time. PuPHPet makes the job a lot easier by providing a graphical interface and simplified config file to build you a base configuration.
You should end up seeing something like the screen above then it’s done. I got a few issues running the deployment mostly because I have a crappy internet connection. If you do not see something like the above screenshot then in your terminal just type `vagrant provision` to retry the process. When it is complete you should be able to open a browser and type into the location bar http://192.168.56.101 and be met with a congratulations page. On this page are some instructions as to how to setup your machine to talk to the development environment that I have set up for you. Follow these instructions as to how to find and edit your ‘hosts’ file but when you’re entering the details you need to enter the following
192.168.56.101 geekout.dev www.geekout.dev
Head back to your browser and this time in the location bar you need to type http://geekout.dev and with any luck you should see a beginning page of something called Laravel 5.
To aid me in this tutorial I have decided to use a framework for PHP called Laravel. A framework is a base set of code that you can use to help you build your application a lot faster and save you an awful lot of hassle. There are many frameworks out there for PHP, Cake, Yii, Zend, Symfony and no doubt lots more, they all perform a very similar job and there are reasons why you would choose one over the other but I’m not going to get into that right now. What’s important is that I choose Laravel because it’s probably going to be easier to teach and has a great community. Laravel uses a well known coding principle called MVC which stands for Model, View, Controller. Don’t worry about that again for the time being I shall explain those as we go unless you want to go and do your own homework.
The next time we touch this we will start to change the application. So if you have any ideas as to what to build then please get in touch with us. You can of course, use the comments section below or any of our other medias like Reddit, Twitter or Facebook.
Love and rockets