Question:

Php How do i compile a php code, so that it can run on the server side?

by  |  earlier

0 LIKES UnLike

Php How do i compile a php code, so that it can run on the server side?

 Tags:

   Report

2 ANSWERS


  1. PHP needs no compiling.  It's a script (like javascript except it runs on the server instead of the client) so it runs straight out of a text file that can be either all PHP code or PHP code mixed with HTML.  Just make sure the file has the .php extension and that all the PHP code is in between <?php and ?> like this:

    <?php

    /* some PHP code */

    ?>

    [edit] Bonus example, the obligatory Hello World program.

    <html>

    <head>

      <title>PHP mixed with HTML - Hello World</title>

    </head>

    <body>

      <?php

        echo '<p>Hello World!</p>';

      ?>

    </body>

    </html>

    Or you could do it with all PHP:

    <?php

    echo '<html><head><title>Pure PHP Hello World</title></head>';

    echo '<body><p>Hello World!</p></body></html>';

    ?>


  2. You don't need to compile it, the php script you write will be executed when the page is loaded.

    For example you have page.html:

    <html>

    <body>

    <?php

    echo "Wellcome !";

    ?>

    </body>

    </html>

    when a visitor load this page, the server will execute the script and output the following:

    <html>

    <body>

    Wellcome !

    </body>

    </html>

    So you don't have to compile php, but you need to put it in a server :)

    you can upload it to your hosting service company, or maybe install a server in your PC.

    To install a server go to: http://www.wampserver.com/

    download and install.

    Then put a php file into c:\wamp\www\ , and execute it from your browser at: localhost/

    for example: c:\wamp\www\page.php  ---> localhost/page.php

    good luck !

Question Stats

Latest activity: earlier.
This question has 2 answers.

BECOME A GUIDE

Share your knowledge and help people by answering questions.