There is a web server built into Ubuntu, you don't need to install anything. PHP does not ship with Ubuntu, but you can install it easily using Software Center.
How to use Python to run a CGI web server
Simply make a new directory (lets call it
www_playground) enter it using the terminal. Make a new directory in the directory called
cgi-bin. Now make a text file called
hello.php in the
cgi-bin directory. Write this into the file and make it executable:
echo "Content-type: text/html\n\n"; /* DON'T TOUCH THIS unless you know what you're doing */
<p>How are you? The time is <?php echo date("r"); ?>.</p>
Now, in the terminal (which is in the
www_playground directory), write
python -m CGIHTTPServer and ⏎ Enter. The server will start, leave it running in the terminal in the background for as long as you want.
You can now open a web browser and go to
http://localhost:8000/cgi-bin/hello.php, and you should see the web page we just created.