Over the years, I’ve been involved in working on multiple projects. Some have been mom and pop type websites, some have been enterprise sized platforms, and others hovered somewhere in between. Meanwhile, I’ve been evolving my code practices to the point where I can just take a set of libraries, implement them, and hit the ground running.
Why not use 3rd party frameworks? Well, honestly, none of them do it for me. And, as the co-founder of PHP itself, Rasmus Lerdorf said it, “4 Reasons Why All PHP Frameworks Suck“. They’re slow, add multiple levels of unnecessary abstraction, and you typically have to learn a whole new language with them. And, in order to get them running fast, you’re going to need additional servers. Not very cost effective, or green for that matter.
I give you, “Clean PHP“:
A little github project I started a little while ago. Let me explain how it evolved. This explanation is so simple, anyone with the basic understanding of PHP can work with it, simply because it’s all in PHP. Oh, and knowing CSS, HTML, MySQL, JS and jQuery helps too.
The intro to web development typically started something like this:
Create a file, call it index.html, save it to your desktop and open it in your favorite browser. Done. Blank page, but it works. Write some text in that file with your favorite notepad editor, save it, and refresh. OOooh. Text!
Let’s get you set up to be a professional web developer. Download WAMP if you’re on a Windows machine. MAMP / XAMPP if you’re on a Mac. I’ve found WAMP to work best for me since I’ve been a PC/Windows guy most of my life.
Additional tools you might need:
IDE: You’re going to need an Integrated Development Environment to edit your files.
My favorite IDE: Notepad++ (it does the job, and with its many plugins becomes a powerful lightweight tool to be respected).
My favorite MySQL GUI Tool: SQLyog
Set up your apache server. Usually, they all come with some sort of an install guide. I will use WAMP since I use it most of the time, and so I don’t have to write up 3 different articles.
Once your server is set up, and hopefully you installed it under c:\wamp for us PC guys, let’s get to work to finish our setup.
First step to wrap things up should be to set up a domain name that works from your browser. Let’s call our very first project Clean PHP, and have it so we can call it from our browsers using local.cleanphp.com. Unfortunately, you won’t be able to see anything of what we’re expecting. You need to do two things. Configure your WAMP to use virtual hosts, and then tell windows what IP address to use for those hosts.
No worries, this is fairly simple. If you’re going to create a lot of test, sandbox domains, let’s keep this more permanent.
* Open up Notepad++.
* Under the Plugins Menu in the menu bar, select Plugin Manager.
* Yes, my root folder is somewhere else, but that’s just personal preference. You’ll see how you can change it too later.
* Install / enable the following plugins:
** Save as admin (if you don’t have admin rights on your machine)
** ScrollPastEOF (personal preference so I can scroll files past the end of file marker).
Ok, now that you have those, somewhere at the top, you’ll see these three buttons:
When you open up your heart (favorites), you’ll notice some panes opening up on the left side (possibly right side too). These tabs are your files browser. Open up the favorites:
You should see the following list where you will be adding new “files”
Right click on the Files list item.
Select New Link… and you will see this pop up. I’ve already set mine up with some values for the name and link. Your folder structure might differ depending on your install of windows, or OS. In any case, you need to know where your hosts file is located.
Do the same for your httpd-vhosts.conf file. This file is where your domain names are configured for apache to know where to look.
And, the same for your server configuration file:
And, finally, the php.ini file. This one can be a bit tricky since you’d expect it to be in the php subfolder. Nope, it’s under apache’s folder in your WAMP install.
This is what my favorites look like. You only need those four for now.
This was longer than expected, but good thing you only have to do this once. Let’s modify the hosts file first. Go to your favorites and double click the hosts file. Inside it you will see some commented out code, and then there will be this line:
This tells Windows that if a web browser is to try out the address of “localhost”, that is should look on this machine for that domain name’s hosted files. Add your domain name underneath that. For each domain you add, you will have to add it on a new line similar to the other ones. IP Address followed by your domain name URL.
Ok, that’s done. Now, onto the httpd.conf file. This one will have a TON of stuff in it for your server to be configured. Skip to the part where you see this code:
# Virtual hosts
… and remove the # character in front of the word Include. This will tell your WAMP installation to load this file. You will only have to do this once.
It should now look like this:
# Virtual hosts
Now, load up that file from your favorites. You will notice a lot of configuration settings for all of your servers. Don’t let that scare you. All you need in this file for now is just 4 lines of code to tell any browsers looking for the website where to look for the document root files.
And that’s it. Your server is ready to serve some files.
! IMPORTANT ! – Restart your WAMP server so the vhosts are recognized.
Let the development begin!
Once you restart your wamp, navigate to the following folder in your Notepad++ Explorer pane: c:\wamp\www, and create an actual folder with the name you listed for your virtual host: local.cleanphp.com
Inside here you should create the index.php file. This is your main file for the website. Apache recognizes index.php as a main point of entry for any folder. Your DirectoryIndex.
If you actually browse to local.cleanphp.com on your browser, you should see a blank page at this point. You haven’t added anything to your file.
Try adding something to it, save it and refresh your browser. Voila! Text.
Boy, that took a while to get here. Good thing most of that you only have to once per machine, and very little of it whenever you want to create a new project.
Let there be HTML!
Coming soon. HTML and validation.