In this series of posts, PHP will be the second item that we will be installing. It is certainly not a necessity, as many websites are able to run on Apache alone, if they have no “server-side” code, such as static HTML pages, or file servers. But it is installed on many LAMP servers. Example uses of it are to run a forum, through software such as phpBB, to run a website with dynamic content, such as this website, which uses WordPress to manage all of the posts.
The command to install PHP5 (The most up to date version is):
sudo apt-get install php5-common php5 libapache2-mod-php5
This will automatically install, and configure, PHP5 to run with Apache. After this it is recommended that you restart Apache, just to make sure that everything has worked, run:
sudo /etc/init.d/apache2 restart
Remember that you will need administrative privileges to run all of these commands, which is why I have prefixed all of the commands with “sudo”, although if you are logged in as an administrator, then there is no need to do this.
Now the only thing left is to test your install, to do this you will create a phpinfo() file in the root directory of apaches web root, by default this is /var/www/, and that location is what I will be using. Although, if you have changed this please ignore any references to that.
First you need to navigate to apaches web root:
cd /var/www/
Then create a new file called phpinfo.php, you will need root privileges for this:
sudo nano phpinfo.php
In there type the following:
<?php
phpinfo();
?>
This will create a php script that, when opened, displays all the information about your PHP install. You now need to access it through a web browser, such as lynx, to test that everything is working. To do this type the following command:
lynx localhost/phpinfo.php
This will tell lynx to access the file at the address localhost/phpinfo.php, which is where your phpinfo.php script is saved. You should then be shown a large list of information. If you have followed these steps, but end up with a blank screen, then please post a comment and I will try my best to help you.




No user commented in " Setup a Web Server (Part 2) - PHP "
Follow-up comment rss or Leave a TrackbackLeave A Reply