Archive for the ‘PHP’ Category
This is a HOW TO guide to installing LAMP (Linux Apache MySQL PHP). This consists of Apache web server, MySQL database (as well as a DB tool), and PHP. Together these can be used to run as a local web server on your computer, using Ubuntu distribution of Linux. This is similar to WAMP, which is the Windows version.
The idea of this HOW TO is to explain how to get these working together, with little to no use of the Terminal Command Line, but I will give the command line interface (from now on I will call this CLI) as well as they do make life a little faster. For this we will be using the “Synaptic Package Manager” (from now on I will call this SPM) which can be found on Ubuntu in System -> Administration -> Synaptic Package Manager.
So first up we need to install the Apache Web Server. Type the following into the SPM Quick Search box:
apache2
If you add a space after it will be the first result returned, without and it will be the third. For all SPM options make sure you mark them for The command line alternative is (it assumes that you are running as a sudo user, this is the same for all CLI alternatives written here):
sudo apt-get install apache2
To check if this works, click http://localhost, which points to your new local web server. If the words “It works!” appear then everything is on track!
With Apache installed, we now want to install PHP. For this use either SPM and search for:
php5 and libapache2-mod-php5
Or using the CLI: sudo apt-get install php 5 libapache2-mod-php5
Next we need to restart the Apache server so it loads PHP. To do this without the CLI you need to use “Run Application…”, this can be found by right clicking one of the task-bars and and adding the “Run Application..” to the task bar panel. Once this is done type the following command:
gksudo /etc/init.d/apache2 restart Note: This will prompt for your password
Or using the CLI: sudo /etc/init.d/apache2 restart
Now you need to check that PHP is installed correctly. We need to create a small PHP file in the Web Servers directory that displays the PHP info. To do this we are going to run the following command under “Run Application…”:
gksudo gedit /var/www/testphp.php
Or using the CLI: sudo gedit /var/www/testphp.php
Once GEdit is open add the following line and save the file: phpinfo(); inside opening and closing PHP tags
Now check that this has worked by clicking : http://localhost/testphp.php
This should display all the information about the PHP configuration that’s just been installed. Now we move on to the last part which is to install the MySQL server. Using the SPM find and install:
mysql-server
Or using the CLI: sudo apt-get install mysql-server
This will run the MySQL set-up which will at some point prompt you for a root password. This is for root login to your MySQL server, and you’ll need to enter it twice.
After MySQL has been set-up there are two more packages that you need, the first is MySQL libraries for PHP 5, and the second is for Apache to use MySQL.
php5-mysql and libapache2-mod-auth-mysql
Or using the CLI: sudo apt-get install libapache2-mod-auth-mysql php5-mysql
Once these have been installed you need to tell PHP about the MySQL extension by editing the php configuration file. This can be done using “Run Application..” using:
gksudo gedit /etc/php5/apache2/php.ini
In this file you need to find the line that says ; extension=msql.so, remove the ; from the begining of the line, save and close the file.
That’s it, Apache, PHP & MySQL are all installed and set-up. However there is one more stage that might be of use. That is to install Navicat, which allows easy administration to a MySQL Database. First head to the Navicat Download Page and get the appropriate version. I use the Lite (non-commercial) version.
Once your downloaded the tar ball, extract it to where ever you want Navicat to be installed. To run it create a shortcut to the start_navicat file.