Testing the Wamp Server : Executing Simple PHP Script

Testing the Wamp Server :

Now we have checked whether the wamp server is working fine or not after installing Wamp Server. Now its time to execute the simple PHP Script. In order to execute the PHP Script we should have sample PHP file.

<!DOCTYPE html>
<html>
<body>
<?php
echo "My first Sample PHP script!";
?>
</body>
</html>

Lets save above script by - test1.php

PHP Script Saving Location :

  1. Make sure that you have started all the service before testing the output of the PHP file -

[box]Right Click on Wamp Server Icon and Select “Start All Services” from Quick Admin Menu.[/box]

  1. Now Select the “WWW directory” menu from the

  1. After Selecting the WWW directory menu option you will be navigated to the following Screen -
c:/wamp/www/


[box]

Note -

In the previous installation steps we have given the installation path -

In the same folder “www” folder gets created and all the PHP files goes into this folder.
[/box]

  1. Now we have created a file test1.php in the www folder.

Executing Script in Browser :

Now we need to execute the Script in the Browser, So we need to create URL for executing the localhost script. Just type following url in the browser and you can see php in action.

http://localhost/test1.php

from the above url , You can conclude that -
[table border="1"]
Name of File Inside WWW Directory,URL Structure
test.php,http://localhost/test.php
dir/test.php,http://localhost/dir/test.php
dir/subdir/test.php,http://localhost/dir/subdir/test.php
[/table]

How to Install WAMP Server on Windows PC ?

Install WAMP Server on Windows :

  1. Firstly go to Wamp Server Website - Download Link
  2. Now Double click on the Downloaded Executable File to run Wamp Server by clicking on Run Button.
  3. Follow the Simple Steps to install the Wamp Server.

Congratulations !! You have installed the Wamp-Server successfully in your PC. Now go and Check whether Wamp Server is installed properly or not.

How to Check Wampserver is Installed on Window ?

In order to test PHP Scripts we need a Server as PHP is Server Side Scripting Language. We cannot afford web server just for testing or learning PHP.

1. Making Your Window PC a Server :

  1. We need to install wampserver to make local server pc.
  2. After installing Wamp Server , Window PC will acts as local server which can execute your PHP Scripts in your local workstation.
  3. If you haven’t yet dowloaded the Wampserver software, you can download it here : Download Link

2. Installing and Configuring :

  1. After installing Wamp Server we can see the Green Icon in the bottom right near the clock.
  2. After clicking on the green icon we are able to see following Wamp Server Menu.
  3. From the quick admin menu user can quickly start or stop all the services.

  1. After selecting the localhost , we can see the following screen -

  1. Click on the link under Tools Section saying phpinfo() , if everything goes right then you can see the following page -

Congratulations !! You have installed Wamp-Server Successfully

PHP Variable : Variable Naming Rules

1. Rules for PHP variable names:

  1. Dollar Sign is used to represented a Variable in PHP followed by the name of the variable.
  2. PHP Variable name is case-sensitive.
  3. PHP Variable name must begin with a letter or the underscore character
  4. A variable name can only contain alpha-numeric characters and underscores (A-z, 0-9, and _ )
  5. A variable name should not contain spaces
  6. Variable names are case sensitive (var1 and VAR1 are two different variables)

2. Regular Expression for PHP Variable :

[a-zA-Z_x7f-xff][a-zA-Z0-9_x7f-xff]*

3. Declaring PHP Variable :

<?php
$fname = 'Pritesh';
$lname = 'Taral';
echo "$fname, $lname";  // outputs "Pritesh, Taral"
$4site = 'not yet';     // invalid; starts with a number
$_4site = 'not yet';    // valid; starts with an underscore
$täyte = 'mansikka';    // valid; 'ä' is (Extended) ASCII 228.
?>

Note :

[box]$this is a special variable that can’t be assigned.[/box]

How to Specify Type of the Data Variable ?

In PHP we can assign any type of data to variable i.e

<?php
$svar = "Hello World!";
$ivar = 4;
$ivar = 8;
?>

In this example if we assign the integer value to the variable then Variable will acts as Integer Variable. Suppose we assign string value then it will acts as String Variable.

PHP Comments : Hiding Code Block

Introduction :

  1. Like each and every programming language , PHP do support comments which is used to hide the unwanted code or for documentation purpose.
  2. PHP Comments makes development easy and provide great way to hide the un-wanted code.
  3. Like C Programming , PHP Supports two types of comments i.e Single Line Comment and Multiple Line Comment.

Live Example of Comment :

[box]In PHP, we use // to make a one-line comment or /* and */ to make a comment block[/box]

<html>
<body>
<?php
//This is a Single Line comment PHP
/*
This is
block comment in
PHP
*/
?>
</body>
</html>

Explanation :

  1. Comments in PHP can be Multiple Line or Single Line
  2. PHP Comments are used to hide the code or to prevent code from execution.
  3. PHP Comments can be used effectively by smart programmer for documentation.
  4. PHP Comments can be written at any place in the code.

External Article : What is Difference Between Block Comment and Single Line Comment.

PHP Syntax : First PHP Script

After installing PHP on your system/server we need to write our first php program which can be executed on the server.Writing PHP script is very easy because you already know C Programming language. Many syntax in PHP are like c language. We are writing our first PHP script to print “Hello World” in the browser window.

First PHP Script :

<?php
echo "Hello World";
?>

Explanation of First PHP Script :

  1. PHP Script is simply written in notepad / notepad++.
  2. PHP Script starts with <?php and ends with ?>
  3. PHP Script can be written/placed anywhere in the document.
  4. PHP Script can be embedded in HTML document.

Shorthand Property :

We can also write PHP Script between <? and ?>.

<?
echo "Hello World";
?>

but still it is not the proper way to write/include PHP code. For maximum compatibility we cannot write above mentioned syntax.

About PHP File :

  1. Whenever we write any PHP file then we must save it using .php extension.
  2. PHP file normally contains dynamic PHP Script embedded and HTML tags.
  3. Each statement in PHP is terminated by semicolon. Semicolon is used to distinguish two code statements of PHP.
  4. In PHP we have two basic statements to print text on the webpage i.e echo and print.

Introduction to PHP - Sever Side Scripting

PHP is powerful tool to create dynamic pages that can run on server. PHP can be embedded in HTML to provide dynamic feature to the webpage. You need to learn HTML and JavaScript before learning PHP.

What is PHP ?

  1. PHP stands for Hypertext Preprocessor
  2. PHP scripts are executed on the server thus PHP is also called as server-side scripting language.
  3. PHP supports many databases such as MySQL, Informix, Oracle, Sybase, Solid, PostgreSQL, Generic ODBC, etc and provide database functionality to webpages.
  4. PHP is an open source software and thus any one can download it and install it on own server.
  5. PHP supports a large number of major protocols such as POP3, IMAP, and LDAP
  6. PHP provides interactivity to HTML page by executing dynamic content such as database connectivity,session tracking and more complex scripts such as E-Commerce.
  7. PHP syntax is similar to that of C Programming so if you are aware of C programming then writing php code is not a big deal for you.