Starting PHP scriptingSetting up a PHP environmentTutorial by ande for EvilzoneContents _0x00 -
PHP0x01 -
Software0x02 -
Starting PHP scripting0x00 - PHPPHP - A script language used for various tasks, but mostly known for its use in web pages. However, PHP can also be used as command line scripts locally or remotely. In this text I will only be showing how to set up an environment for web page scripting. PHP can be set up on most OS's, I will be covering Windows and Debian(Or any other Linux distribution with APT installed).
0x01 - SoftwareIn order to run any PHP script what so ever you will need the PHP engine and a PHP supporting web server, in this case we will use Apache.
WindowsApache for windows can be downloaded at
www.apache.org,
http://httpd.apache.org/download.cgi#apache22Once installed, you should see "It works!" in your browser when you write
http://127.0.0.1, now move on to PHP.
PHP for windows can be downloaded at
www.php.net,
http://windows.php.net/download/, you probably want this one:
http://windows.php.net/downloads/releases/php-5.3.29-Win32-VC9-x86.msiWhen you come to this step of the installer:
Select Apache 2.2.x Module and continue and select your apache config folder when it asks you to(the folder containing httpd.conf, by default its something like C:\Program Files\Apache Software Foundation\Apache2.2\conf\)
Restart Apache and make a file named index.php in your htdocs directory(by default its something like C:\Program Files\Apache Software Foundation\Apache2.2\htdocs) and write:
<?php echo ("It works! PHP"); ?>
Now, go to
http://127.0.0.1/ and you should see "It works! PHP". If so, you are ready to go!
LinuxTo install Apache and PHP run these commands:
- sudo apt-get install apache2
- sudo apt-get install php5
- sudo apt-get install libapache2-mod-php5
- sudo /etc/init.d/apache2 restart
Now create a file in the web directory(by default its something like /var/www/) called index.php and write:
<?php echo ("It works! PHP"); ?>
Now, go to
http://127.0.0.1/ and you should see "It works! PHP". If so, you are ready to go!
0x02 - Starting PHP scriptingBelieve it or not but you have already done a little bit of scripting already, by creating the test page saying "It works! PHP"! And this is how you create PHP scripts. Create a .php file, put PHP script tags inside it, and add script. Here is a few more PHP examples.
Simple Hello World print
<?php
echo ("Hello World");
?>
Variable print
<?php
$Variable1 = "Hello World";
echo $Variable1;
?>
Math + print
<?php
$Var1 = 10;
$Var2 = 10;
$Var3 = $Var1 + $Var2;
echo $Var3;
?>
PHP + HTML
<html>
<body>
<?php
echo ("Line1 <br /> Line2 <br /> Line 3");
?>
</body>
</html>
A great site for further quick learning:
http://www.tizag.com/phpT/A great example site for PHP and many other languages:
http://www.java2s.com/Code/Php/CatalogPhp.htm