[size=12pt]Getting started with PHP[/size]
I will assume you are running windows. Run the commands shown in code blocks in the Cmder terminal.
[hr]
HTML/Javascript is possible to run directly in your browser without any fuss as it’s the browser that usually run/parse these things.
PHP is a server side language, so it needs some server functionality for it to work. This can either be done by
Installing a web server and PHP (and optionally mysql etc) manually on your machine. This is not recommended as you’ll spend too long installing/configuring stuff which really isn’t what you’re after. In addition you are polluting your pc with software and services you don’t really need.
Installing a web server ++ through a bundled / package installer, like XAMPP or WAMPP. Not recommended because of the same issues as above (- some install / config hassle)
Running a virtual machine. This is good as you can have an (swappable) environment that is similar to your hosting environment. You can simply delete the virtual machine at any time and all server stuff is gone. You can also simply change out the VM to another machine, if you want to try to run your app(s) on another OS, PHP version, or similar.
[hr]
Prerequesites
Whatever you choose we will definitly want a better terminal than what’a already available in Windows. If you’re on OSX/Linux you are fine with the built in terminal.
Install CMDer
Download/unzip CMDer full http://cmder.net/
Create a shortcut for you where you want to execute it from
The advantage of CMDer, apart from being a proper terminal. Is that you can easily use git, ssh, and other services you will definitly need as a developer.
Set up GIT
GIT is version control software that will allow you to properly handle your (and others) code.
First, you need a key to authenticate with git (could also be used for other services, like ssh)
ssh-keygen -t rsa -b 2048 -C "[email protected]"
Press enter to accept default storage location
Choose a passphrase, you will have to enter this every time you want to use the key. It’s strongly advised to have one as this basically is your identity on the internet.
Register for free account at https://github.com
After registering go to Settings -> SSH keys
Click Add SSH key
Enter any title
Copy the public key you just generated into the key field (notepad c:\Users\Yourname.ssh\id_rsa.pub
Click add
Install an IDE
While you can use notepad to code it’s much easier to use a proper editor. IDEs have features like code validation and auto completion which are great to have when working. There are a lot of IDEs available, and when you get the time I suggest you try out a few just to see what works for you. Read more here http://www.phphelp.com/forum/the-occasional-tutorial/make-your-life-simpler-use-an-ide!/
A good and free IDE is Oracle NetBeans (PHP x64 or PHP x86 if you don’t have a 64bit computer)
https://netbeans.org/downloads/
[hr]
Getting set up to run virtual machines
Install Virtualbox, the actual virtual machine host
https://www.virtualbox.org/wiki/Downloads
Install Vagrant, a service providing virtual machines and configs that are easy to import to Virtualbox
Reboot
[hr]
Creating a directory to hold all our projects
Open up CMDer and you should be in C:\Users\Yourname
Create a directory to hold our projects
note: you can store your projects wherever you want
mkdir projects
Enter the projects dir
cd projects
[hr]
Setting up a PHP project
We’ll use Scotch Box “- A Vagrant LAMP Stack That Just Works”
Their website says "just clone and run vagrant up, so that’s exactly what we’ll do.
Make sure you are in the projects folder
git clone [email protected]:scotch-io/scotch-box.git learningphp
Enter your key password and the scotch box files should be cloned into projects/learningphp
Enter the project folder
cd learningphp
Run the machine
vagrant up
Visit the server in your browser
http://192.168.33.10/
The file you see there is generated from the index.php file that’s in the public folder. Congratulations, you are now running Ubuntu with PHP, Apache, Mysql, Memcached (and lots of other goodies) in a virtual machine!
Swap out the index.php file with your own file(s), though take note of default mysql credentials
[code]
Listing 1.1
<?php echo 'Hello World!' ?>
Happy coding