Author Topic: Starting PHP scripting - Setting up a PHP environment  (Read 22663 times)

0 Members and 4 Guests are viewing this topic.

Offline ande

  • Owner
  • Titan
  • *
  • Posts: 2664
  • Cookies: 256
    • View Profile
Starting PHP scripting - Setting up a PHP environment
« on: October 03, 2010, 04:43:30 am »
Starting PHP scripting
Setting up a PHP environment

Tutorial by ande for Evilzone

Contents _
0x00 - PHP
0x01 - Software
0x02 - Starting PHP scripting



0x00 - PHP
PHP - 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 - Software
In 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.

Windows
Apache for windows can be downloaded at www.apache.org, http://httpd.apache.org/download.cgi#apache22
Once 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.msi
When 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:
Code: [Select]
<?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!


Linux
To 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:
Code: [Select]
<?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 scripting
Believe 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
Code: [Select]
<?php
     
echo ("Hello World");
?>


Variable print
Code: [Select]
<?php
     $Variable1 
"Hello World";
     echo 
$Variable1;
?>


Math + print
Code: [Select]
<?php
     $Var1 
10;
     
$Var2 10;
     
$Var3 $Var1 $Var2;
     echo 
$Var3;
?>


PHP + HTML
Code: [Select]
<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
« Last Edit: August 26, 2014, 07:03:25 pm by ande »
if($statement) { unless(!$statement) { // Very sure } }
https://evilzone.org/?hack=true

PublicEnemy

  • Guest
Re: Starting PHP scripting - Setting up a PHP environment
« Reply #1 on: November 27, 2010, 03:12:01 pm »
You can simplify this:
Code: [Select]
sudo apt-get install apache2
sudo apt-get install php5
sudo apt-get install libapache2-mod-php5
by
Code: [Select]
sudo apt-get install apache2 php5 libapache2-mod-php5 ;)

Offline 10n1z3d

  • Serf
  • *
  • Posts: 42
  • Cookies: 8
    • View Profile
Re: Starting PHP scripting - Setting up a PHP environment
« Reply #2 on: November 28, 2010, 11:43:37 pm »
You could also use
Code: [Select]
sudo service apache2 restartinstead of
Code: [Select]
sudo /etc/init.d/apache2 restart
« Last Edit: November 28, 2010, 11:44:02 pm by 10n1z3d »
Code: [Select]
python -c "print ''.join(chr(x) for x in [int(oct(39)) + 2, 24 * 2, 313 % 203, 0x31, (2 ** 7) - 6, int('051'), (3 << 6) - 92])"

Offline iTpHo3NiX

  • EZ's Pirate Captain
  • Administrator
  • Titan
  • *
  • Posts: 2920
  • Cookies: 328
    • View Profile
    • EvilZone
Re: Starting PHP scripting - Setting up a PHP environment
« Reply #3 on: November 29, 2010, 12:23:54 am »
You could also use
Code: [Select]
sudo service apache2 restartinstead of
Code: [Select]
sudo /etc/init.d/apache2 restart

Depends on the OS, I know that with Debian, service apache2 restart doesn't work. Also I know on CentOS its actually:

Code: [Select]
service httpd restart (sudo implied if not running root)

I can't speak for other distros as I've only really used Debian, Ubuntu, BackTrack, and CentOS, for servers Debian and CentOS really.
[09:27] (+lenoch) iTpHo3NiX can even manipulate me to suck dick
[09:27] (+lenoch) oh no that's voluntary
[09:27] (+lenoch) sorry

Offline ande

  • Owner
  • Titan
  • *
  • Posts: 2664
  • Cookies: 256
    • View Profile
Re: Starting PHP scripting - Setting up a PHP environment
« Reply #4 on: November 29, 2010, 12:00:04 pm »
service apache2 restart works fine on any distro(almost) if you have sysvconfig installed.
Quote
sudo apt-get install sysvconfig

:)
if($statement) { unless(!$statement) { // Very sure } }
https://evilzone.org/?hack=true

Bursihido

  • Guest
Re: Starting PHP scripting - Setting up a PHP environment
« Reply #5 on: March 27, 2011, 01:00:01 am »
Awesome guide Thanks :)

Offline luffy12

  • NULL
  • Posts: 3
  • Cookies: 0
    • View Profile
Re: Starting PHP scripting - Setting up a PHP environment
« Reply #6 on: January 24, 2012, 09:50:45 am »
Does this still work if your using wamp?

Luffy

Offline Kulverstukas

  • Administrator
  • Zeus
  • *
  • Posts: 6627
  • Cookies: 542
  • Fascist dictator
    • View Profile
    • My blog
Re: Starting PHP scripting - Setting up a PHP environment
« Reply #7 on: January 24, 2012, 11:53:12 am »
Does this still work if your using wamp?

Luffy

Yes.
But I recommend LAMPP/XAMPP.

Offline dataspy

  • Peasant
  • *
  • Posts: 99
  • Cookies: 16
    • View Profile
Re: Starting PHP scripting - Setting up a PHP environment
« Reply #8 on: April 03, 2012, 03:19:36 am »
The only people for me are the mad ones, the ones who are mad to live, mad to talk, mad to be saved, desirous of everything at the same time, the ones who never yawn or say a commonplace thing, but burn, burn, burn, like fabulous yellow roman candles exploding like spiders across the stars.
-Kerouac

Offline poscore

  • Serf
  • *
  • Posts: 39
  • Cookies: -2
  • Have a nice day :)
    • View Profile
Re: Starting PHP scripting - Setting up a PHP environment
« Reply #9 on: June 25, 2012, 12:31:12 pm »
The sticky is an introduction about PHP programming. Nice :D I was wondering if there any members here who could help, maybe group a team and write a full PHP tutorial?


Its just an idea hoping for responce :)
Just asking and saying my opinion... :)

Offline Kulverstukas

  • Administrator
  • Zeus
  • *
  • Posts: 6627
  • Cookies: 542
  • Fascist dictator
    • View Profile
    • My blog
Re: Starting PHP scripting - Setting up a PHP environment
« Reply #10 on: June 25, 2012, 01:18:01 pm »
The sticky is an introduction about PHP programming. Nice :D I was wondering if there any members here who could help, maybe group a team and write a full PHP tutorial?
or maybe you should go ahead and read a book?

Offline poscore

  • Serf
  • *
  • Posts: 39
  • Cookies: -2
  • Have a nice day :)
    • View Profile
Re: Starting PHP scripting - Setting up a PHP environment
« Reply #11 on: June 25, 2012, 01:35:14 pm »
Ok, as i said it was just an idea :P
Just asking and saying my opinion... :)

Offline ande

  • Owner
  • Titan
  • *
  • Posts: 2664
  • Cookies: 256
    • View Profile
Re: Starting PHP scripting - Setting up a PHP environment
« Reply #12 on: June 25, 2012, 02:45:19 pm »
The sticky is an introduction about PHP programming. Nice :D I was wondering if there any members here who could help, maybe group a team and write a full PHP tutorial?


Its just an idea hoping for responce :)

There are already a ton of good tutorials and guides out there. You are better of asking questions here.
if($statement) { unless(!$statement) { // Very sure } }
https://evilzone.org/?hack=true

Offline poscore

  • Serf
  • *
  • Posts: 39
  • Cookies: -2
  • Have a nice day :)
    • View Profile
Re: Starting PHP scripting - Setting up a PHP environment
« Reply #13 on: June 25, 2012, 03:02:57 pm »
Thats "the other side" of my mind :P Have you ever read HEAD FIRST PHP & Mysql?
Just asking and saying my opinion... :)

Offline ande

  • Owner
  • Titan
  • *
  • Posts: 2664
  • Cookies: 256
    • View Profile
Re: Starting PHP scripting - Setting up a PHP environment
« Reply #14 on: June 25, 2012, 06:54:35 pm »
Thats "the other side" of my mind :P Have you ever read HEAD FIRST PHP & Mysql?

Nope, started PHP after I had done C# and C++ so it kinda came naturarly after some experimenting. As well as the awesome PHP documentation makes reading a book unnecessary.
if($statement) { unless(!$statement) { // Very sure } }
https://evilzone.org/?hack=true