PHP is one of the most useful and powerful scripting languages in web development. Facebook was mostly coded using PHP (along with the help of database management system Mysql). You can create an entire search engine for a website using PHP. The possibilities are endless. But the main reasons that PHP is so great is that it is easy to use and it allows for rapidly changing web pages. One can even just incorporate a little bit of PHP into their HTML document and voila! PHP all done!
What is PHP?
PHP stands for “PHP: Hypertext Preprocessor”. It was first designed by Rasmus Lerdorf back in 1994 with the goal of recording website traffic and displaying his résumé. Since then, a number of developers have stepped in and further developed the language.
When PHP code is compiled and run, it results in HTML. This HTML is then sent to the browser that is requesting a web page. PHP is extremely useful for creating dynamic web pages. The content of these pages can constantly change depending on what information the PHP code is given. This is done by means of variables and functions (which you should be familiar with if you have worked with almost any programming language). Enough of my blabbering, let’s set up our PHP environments and start coding!
Installing A Server Environment
Most computers don’t come with PHP installed. An exception is Macintosh, but you’ll still want to install a complete server environment even if you are on a Mac.
Server environment installers and managers install all the necessary libraries and programs necessary to run PHP, Mysql, Apache, and more (depending on which server environment you go with). There are a large number of these environment packages available, and it can seem a little overwhelming. Allow me to break it down for you and instruct you on how to choose and install them.
|Environment & What It Stands For/What It Offers||Operating System(s) It Can Run On||How To Install|
|MAMP – Mac Apache Mysql PHP||Mac||Head on over to http://www.mamp.info/en/downloads/index.html and hit the big download link at the top of the page. This will download a zip file containing the software installer packages for the MAMP software. Run the package to install MAMP. Done.|
|WAMP – Windows, Apache, Mysql, PHP||Windows||Go to http://www.wampserver.com/en/download.php and click the corresponding download link. Simply run the executable to install.|
|LAMP – Linux, Apache, Mysql, PHP||Linux||LAMP doesn’t come in a nice bundle of software, you have to install each element separately. Due to this, I’m just going to refer you to this helpful tutorial: http://www.howtoforge.com/ubuntu_lamp_for_newbies|
|XAMPP||Mac, Windows, Linux, Solaris||Click on over to http://www.apachefriends.org/en/xampp.html and select your operating system from the list. After you download the file from the page that you are sent to, follow the detailed instructions on the download page to install.|
For the purposes of this series of tutorials, I suggest you use MAMP if you are on a Mac, and XAMPP if you are on Windows or Linux. If MAMP doesn’t work for you for some reason, try XAMPP. If XAMPP on Windows doesn’t work for you, try WAMP.
Now let’s make sure we’ve got our environment set up correctly (and go over starting all the necessary servers). Each has a slightly different start procedure, so I’m going to go through them separately.
There are two ways to start up the MAMP server. The first is using the MAMP app that comes bundled with the MAMP software. Navigate to the MAMP folder that you installed to your Applications folder. The MAMP application is in this folder. Upon opening it, a small control window will pop up. If the server statuses don’t switch to the on position automatically, click the “start servers” button. Next, click the “preferences…” button, and, in the “ports” tab, click “set to default Apache and MySQL ports” button.
An alternative way (that I prefer) is using the dashboard widget. Unfortunately, the only way to get it is to download the old version of MAMP (the link can be found at the bottom of the MAMP download page). It’s in the MAMP folder that is in the disk image (MAmp Control.wdgt). Once the widget is installed (double-click it), all you have to do is click the start button on the widget when viewing your dashboard.
Once all of the lights are green and everything is running, go to http://localhost/MAMP/ . You should see the “Welcome to MAMP” screen.
On Macintosh, starting your server is as easy as opening the “XAMPP Control” application that is in the XAMPP folder. If you installed it as described in the instructions, the XAMPP folder is in your Applications folder. Upon opening it, a small control window will open. Start Apache. If all is well, you should see the XAMPP splash screen when you go to http://localhost .
On Windows, you can access the XAMPP control panel by clicking on the “XAMPP Control Panel” shortcut that was made on your desktop during the installation. Start “Apache”, and navigate to http://localhost . You should see the XAMPP splash screen.
On Linux, starting XAMPP is as easy as running the command “/opt/lampp/lampp start”. Point your browser to http://localhost and you should see the XAMPP splash screen.
I hope you found this tutorial helpful! In our next tutorial, we are going to go over where to put our PHP files, what we should use to edit them, and a how to write basic program in PHP.