Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

Chapter 3 Getting Started With PHP

Download as ppt, pdf, or txt
Download as ppt, pdf, or txt
You are on page 1of 13

CHAPTER 3

Getting Started with


PHP
 in this chapter, we’ll give directions for
installing PHP. By the end of the chapter, you
should be ready to write your first script.
Installing PHP
 This section looks at the installation of PHP onto
a computer. If you’re going to be using a hosting
provider that provides PHP or if you have a
friendly sysadmin who has installed PHP for you,
then this section will be of limited usefulness.
PHP runs on various platforms, including Linux,
various Unix flavors, Microsoft Windows, and
Mac OS X. Linux is the most popular platform for
PHP, and when combined with the Apache web
server, and MySQL forms the acronym LAMP
(although the “P” can also be Perl or Python).
What Do I Need?

 To start using PHP, you can:


 Find a web host with PHP and MySQL
support
 Install a web server on your own PC, and
then install PHP and MySQL
Use a Web Host With PHP Support

 If your server has activated support for PHP


you do not need to do anything.
 Just create some .php files, place them in
your web directory, and the server will
automatically parse them for you.
 You do not need to compile anything or install
any extra tools.
 Because PHP is free, most web hosts offer
PHP support.
Set Up PHP on Your Own PC

 however, if your server does not support


PHP, you must:
 install a web server
 install PHP
 install a database, such as MySQL
 The official PHP website (PHP.net) has
installation instructions for PHP: 
http://php.net/manual/en/install.php
Setting Up a Development Server
 You can use WAMP (stands for Windows Apache MySQL
PHP) or XAMPP (stands for X-OS Apache MySQL PHP
Perl) server. WAMP works only in Windows operating
system, whereas XAMPP is a cross-platform, it works in
Windows, Linux, Mac etc.
 The key difference between them apart from OS support is
security (WAMP was built with security in mind).
 You can download the preferred server for free from the
internet. Install the local server (we will use XAMP in this
course) probably and test it.
Testing the Installation
 The first thing to do at this point is verify that everything is
working correctly.
 Enter either of the following two URLs into the address
bar of your browser: Localhost or 127.0.0.1
 Note that, if you chose a server port other than, for
example, 8080, then you must place a colon followed by
that value after either of the preceding URLs—like this:
localhost:8080. You will have to do the same for all
examples: localhost:8080/example.php
Accessing the Document Root
The document root is the one that is entered when a basic
URL without a path is typed into a browser, such as
http://yahoo.com or, for your local server, http://localhost.
By default, XAMPP uses the following location for this
directory:
C://xampp/htdocs
First Page

<html>
<head>
<title>A quick test</title>
</head>
<body>
Hello World!
<?php
echo "PHP code goes here.";
?>
</body>
</html>
First Page

 Save the file into the document root directory


(C://xampp/htdocs) using the filename
test.php.
 You can now call this page up in your
browser by entering one of the following
URLs (according to the extension you used)
in its address bar.
 http://localhost/test.php
Using a Program Editor

 There are a number of good programs available such


as Notepad, Editra, Notepad++, Sublime, Visual
Studio Code etc. An integrated development
environments (IDEs) offer many additional features
such as in-editor debugging and program testing, as
well as function descriptions and much more.
 We use , Notepad++ for this course.
END

You might also like