How to Run Your First PHP Application On Your Computer

How to Run Your First PHP Application On Your Computer

In this tutorial we will explain in detail, what PHP is and how to run a simple application on your own computer, this is to help your development of websites go much faster.

First, let’s begin to understand what PHP is and what’s required to make it run correctly.

PHP is a scripting language that runs on the “server-side”, which means that browsers aren’t able to process it, and it can be run from the command line or inside a webserver, e.g. Apache (more on that later). PHP is currently the most common scripting language used in today’s world, and it doesn’t just allow you to dynamically write HTML, it interacts with other databases and make’s use of other plugins and extensions. This is to provide your user with the best possible experience while surfing on the web or your website. The era of static websites has now come to an end with the introduction of PHP and other scripting languages.

Webpages are basically HTML files that include several hyperlinks to other files which can either be CSS, Javascript, images, media or other HTML files. When the HTML reaches the browser, no PHP scripting should be there. First, because PHP is not HTML and the browser doesn’t understand it. Second, because PHP is intended to run only on the server to provide HTML code for visualization.

To write PHP you can use the same HTML editor you’re already using, since PHP is just “text” mangled between HTML. Notice that PHP can do a lot more stuff than writing HTML, but it has to be contained in the files which are processed by the server. For now, just assume that we are using PHP to write HTML.

Every piece of PHP code inside any document follows certain rules. It must follow this specific pattern:

<?php
//PHP code here...
?>

Notice the <?php before writing the PHP code and the ?> after writing the PHP code. This tells the server that the piece of code enclosed is PHP and it has to be processed by the PHP extension.

But, what if the webserver doesn’t understand it? Simple, it sends the code to the client in the same way as HTML.

Example: Try opening a file in your web browser that includes the following contents (save it to a file, name it hello.php, and open it in the web browser of your choice):

<html>
<head>
<title>My first PHP Page</title>
</head>
<body>
<h2> <?php echo 'Hello World!'; ?> </h2>
</body>
</html>

You will notice that everything is shown, including the PHP code, which shouldn’t be there.

So, to start effectively running PHP code, we will need a webserver.

For Windows users, I advise you to install the WAMP Server it is really easy to install and setup with it’s extensive functionality and it’s easy to configure with the same versions your web host will provide you with.

If you’re a MAC OS X user, MAMP seems to be the perfect solution. As any MAC OS X application, its installation is simple, and it also provides a nice app to manage your configuration and a widget to start and stop the servers.

For details on installation and configuration, please refer to their “products page”. Nevertheless, you can also ask questions here about it and I will try to answer.

Sidenote on Webhosting companies: Any webhosting with PHP and MySQL support will do, the vast majority of them support it so pick the one you prefer. For the sake of simplicity, I’d go with one providing cPanel, which is a control panel for site managing, which allows easy backup and restore functionality. In case you need to change hosting company, you just need to backup from the old one and ask for restoration on the new one.

Each of the above mentioned products, contain a directory named htdocs or www, this is where you should place your files. It is advisable that you create a folder inside that one, say hello (…/htdocs/hello/) where you’ll put the hello.php file created above. Place the file inside and now direct your browser to //http://localhost/hello/hello.php// and you’ll be able to see something similar to:

Hello World!

Note that, Hello World! comes from PHP, through the use of the “echo” command which prints the “Hello World!” text in that place of the HTML file. Looking at the resulting HTML you should be able to see:

<html>
<head>
<title>My first PHP Page</title>
</head>
<body>
<h2> Hello World! </h2>
</body>
</html>

Now you’re ready to start learning PHP, there are a few nice tutorials on the web, this one from W3Schools that in my opinion provides a great kickstart and insight. Follow that tutorial if you want to learn more on PHP, in the next tutorials, we’ll cover PHP in more depth assuming that you’ve followed and understood that tutorial.

I hope you enjoyed this tutorial, feel free to comment, ask for help, provide tips on how to improve it, and also any new ideas for future tutorials.

If you are going to be using this tutorial, please link this back to our e-commerce website freebie post… http://nydesignweb.com/archives/166

Written and Thought of by Nuno Senica - Co-owner of my site Design Web

10 Apr 2011 19:45

rating: +2+x

Add a New Comment
developer-icon-set.png

About Us

Here at the Icon Deposit, we give you the opportunity to post your icons, designs, codes, and screenshots to promote your work and gain new clients. We feature hundreds of free icons, icon sets, UI/UX design, illustrator graphics, vector art, code tutorials for CSS, CSS3, JQuery, photoshop tutorials and tons more. If you would like a custom design or website built, Contact Us.

Popular Posts

Copyright © 2011-2019 Icon Deposit - All rights Reserved