Tuesday, 9 September 2014

How To Run PHP on Ubuntu


How to run PHP on Ubuntu.


First of all you will need a web-server to host your PHP pages.
In this tutorial I use Apache2. You can install Apache2 from the Terminal by using:
$>sudo apt-get update

$> sudo apt-get install apache2

when the installation is finished, Apache is up and running and you can test that by pointing your web browser at

http://localhost/

The default page will come up with a message “it works”.This html file is located under your local file system in folder

/var/www/

Now you have to install PHP.
To install PHP and PHP support for Apache, just write the following in console:

$>sudo apt-get install php5 libapache2-mod-php5

When this is done you are ready.
Let’s go and delete the default page of Apache so we can create our own.
Open a terminal and type:

$>sudo rm /var/www/index.html

If you want to test that PHP is installed successfully into your system you can write and run a simple PHP script that will return to you the PHP information. So open the terminal and type:

$>sudo gedit /var/www/index.php

An empty document will open in gedit now just type the following and save the document.



Restart the web-server by typing:

$>sudo /etc/init.d/apache2 restart

And point your web browser at: http://localhost/
You should now be able to see your first PHP page running.
You can edit this page at any time by typing:

$>sudo gedit /var/www/index.php

Have fun creating your web pages!

No comments:

Post a Comment