How To Write Your First PHP Script

Posted by in Articles, PHP, Programming

You want to learn how to write PHP scripts but don’t know where to start from? In this tutorial I’ll show you all what you’ll need to write your first PHP script. It is a lot easier to get started with than you might think.

Why Use PHP?

PHP is a powerful tool for making dynamic and interactive Web pages.. By learning just a few simple functions, you are able to do a lot of things with your website. And once you know the basics, there are a wealth of scripts available on the internet that you only need to tweak a little to fit your needs

What you’ll need?

To start writing PHP scripts, you need access to a Web server running PHP.There are 2 options: to run php script on you web host or to run PHP script on your own computer .I recommend you second option to run PHP scripts locally, download XAMP and notepad++.

  • Run php script on you web host, if you have already your web host just upload php scripts on web server via FTP or file manager, if not then check this link Best Free Web Hosting, there you’ll find list of the best free web hosting, by my opinion. I recommend 000WebHost , all you need to do is register and you are ready to write you php scripts. The advantage of this approach is that you don’t have to install anything; the disadvantage is that it’s slower to write and test your script
  • Run PHP script on your own computer. There are many way to run php scripts locally , by my opinion the easiest way is to install a complete package like XAMPP. XAMPP is a great piece of software for a development machine, I highly recommend it. Be sure to have not start up when Windows starts, you can always turn it on manually when you need it. Here are detailed instruction How To Install XAMPP
  • Download text editor. To write PHP code you’ll need text editor, I recommend to download Notepad++ , here is download link

First PHP Script- Hello World.php

Every php script begins <?php with and ends with ?> . Below is example of simplest Hello World php script. PHP command echo is a means of outputting text to the web browser.

echo "Hello World";

How to upload php scripts on XAMPP?

Install XAMPP and launch it. Open text editor as notepad ++ type your code and save as filename.php.

Go to folder where you installed XAMMP, default it’s C:/xampp , there you’ll find folder called htdocs , save you script myFirstScript.php to htdocs

Launch your web browser and type http://localhost/myFirstScript.php

How to Upload PHP Scripts on

Login to your acc , open File manager

Go to folder public_html and click upload, browse your php script

Launch web browser and type