Getting started with PHP

Preconditions for the PHP Tutorial

To work on this workshop you should allready know html (If not you can start with our html workshop to learn html). This workshop will not describe the installation of PHP there are many distributions (like xampp for windows) and tons of documentations on the web.


Beside that you should have fun to play and try out new thinks. Because with PHP it's like in many other fields. You will learn more and more while doing new things :-)


A good reference is also the documentation on php.net. There you can find a detailed documenation for most of the existing classes and function.

 

 

How do i start with PHP programming?

If you have never installed a webserver and php i would recommend you to use an installer. This installer installs a webserver and php. Then you have everything you need to start.

For Windows i can recommend the following installers:
 

  1. FoxServ (http://sourceforge.net/projects/foxserv/)

  2. XAMPP (http://www.apachefriends.org/de/xampp.html)


If you use linux, most of the distrbutions are able to install php and the apache webserver. Your distribution installs the webserver and php and makes it running.

What can i use to write PHP Scripts?

In general you can use any text editor to write PHP scripts.

At the beginning i would even recommend you to use a simple editor. There are several development environments available that support PHP, but these can also swamp you!

For the beginning i would use a simple editor like notepad or pico. Later in this workshop you will also see how IDEs like Eclipse or PHPStorm can support you during the development, but for now a simple editor is fine.

Open a simple editor and write the following lines:

<html>
   <head>
      <title>Mein erstes PHP Skript</title>
   </head>
   <body>
      <?php echo "Hello World"; ?>
   </body>
</html>

Now save the file in the root directory of your webserver as "test.php".

Where the root folder is located, depends on your webserver. When you use the Apache Webserver, the root folder is often named "htdocs". Maybe check in the documentation of the installer where your webroot is located.

 

To run the script, open your browser and go to the following adress:

127.0.0.1/test.php

If you now see the text "HelloWorld" in your browser, you are done. Congratiulations, that's your first PHP script.

 

Check your PHP-Configuration

To check your PHP-Configuration on your installation, you can use the following script:

 

<?php
   phpinfo();
?>

With the output of phpinfo, you can see any configuration parameter that was set in your installation (in the php.ini). It also shows you, which version of PHP you are running.

Navigation