PHP scripts can be run via two methods-1.Using web hosting. 2.Installing a server on computer.
- Using web hosting- You can take services of some web hosting site that supports php and sql scripts. Nowadays most of the hosting sites support these two. So you don't have to install anything. You just have to create php files with extension .php and upload them on the web hosting site and there you go.
- Installing a server on computer- This is easier task than using a web hosting site. You just have to install a server once and then you can run your php files offline through this server. There are many servers available to be installed on computers. We will discuss WampServer here and use it in the entire tutorial.
Downloading Wamp Server
- Download wamp server from HERE according to your computer.
Installing Wamp Server
- Install wamp server by running the .exe file downloaded in above step. Install it in c:\wamp directory.
- In between the installation, it may ask you to give the path of a web browser. Provide the location of any web browser. The common location of web browsers is c:\Program Files or c:\Program Files(x86).
- At last it will ask for SMTP and Email. For now keep them to the default values i.e. localhost and you@yourdomain respectively.
Running Wamp Server
- After installing the wamp server, run it by opening the installed file.
- On running this software, your system might ask for allowance in User Account Control dialog box. Press the Yes button.
- Now in the right side of the task bar, there should be the icon of the wamp server. Click (Left Click) on this icon and see what is the first option from the bottom. If it is 'Put Onine' , then click on this option to turn on the server. When the server is online, the icon will turn green..
Where to create files?
- The servers only run the files that are present in their root directory or subdirectories of their root directory.
- To go to the root directory of wamp server, click on the wamp server icon in the right side of the taskbar and then click on www directory.
- If you installed wamp server in c:\wamp, its root directory will be c:\wamp\www. You must save all your php files in this directory. You can also create subdirectories in this root directory.
Running php files
- For running the php files from the root directory and its subdirectories, you must navigate to these files from the web browser. To open the root directory in a web browser-
- Click on the wamp server icon in taskbar, and then click on localhost. or
- Open a web browser and type localhost in its address bar.
- Note: Some systems may have problem with normal port. You can try localhost:8080 in the address bar.