You can easily install the Apache web server (A), MySQL (M) and PHP (P) on your laptop or home PC. The three come bundled together, referred to as either the WAMP, MAMP or LAMP according to whether you are installing them on Windows (W), a Mac (M), or Linux (L).
Below you'll find instructions for WAMP, MAMP and LAMP. Feel free to send me corrections or improvements to these instructions. (Thanks to Sean Cormican and Conor Roche, whose comments have already been incorporated, and special thanks to Paul McGarry, who supplied all of the instructions for LAMP, based on instructions found here: http://tuxtweaks.com/2009/10/install-lamp-on-ubuntu-9-10-karmic-koala/.)
Warning: There will be many, many small differences between your personal installation and the one we have here in UCC. A PHP script that you write might run at home but produce an error message on the CS1 server, or vice versa. Ensure that you test all your scripts on our server, since this is what I will use when grading your work.
The MAMP is available if you are running Apple Mac OS X version 10.4.0 or later.
sudo apt-get install lamp-server^
'
(without the quotes but including the ^ )
Open Firefox and browse to this address: http://localhost/
You should see a web page that says "It Works!"
gksudo gedit /var/www/testing.php
'
(gedit being the default text editor, others should work too)
<?php phpinfo(); ?>
sudo /etc/init.d/apache2 restart
'
http://localhost/testing.php/
You should see a page displaying version information for your php installation.
sudo apt-get install libapache2-mod-auth-mysql phpmyadmin
'
http://localhost/phpmyadmin/
You should see a login page similar the one shown in CS1106 lectures.
Double-click the Desktop icon (or choose WampServer from your Quick Launch tray if you have one, or choose Start > All Programs > WampServer > start WampServer). An icon will appear in your System Tray (rightmost in the Windows Taskbar at the bottom of your screen.) Hover over this icon and a tooltip should say WAMPSERVER - Server Offline. This is good. (Again I'm assuming that you do not want to allow external access to this server.)
Note that the McAfee firewall, if you are running it, may interfere with the WAMP servers, preventing them from successfully launching. You can either disconnect from the Internet (you don't need to be connected whilst using the WAMP) and temporarily disable the firewall, or uninstall the McAfee firewall and seek alternative protection software that does not interfere with the WAMP.
Click the MAMP icon (which is in Applications > MAMP but it may also be in the Dock if you dragged it here earlier). A window should pop up and, if all is well, Apache Server and MySQL server will both have green radio buttons alongside them.
If either of the buttons is ever red, then click Start Servers.
If installed as above, the servers should be started automatically.
Left click on the WAMP icon in your System Tray. From the menu, choose Stop All Services.
The icon should turn part red. Left click it again, and choose PHP and then
php.ini
. This should open the php.ini file in Notepad.
Edit the file to make your installation a little closer to the one you use on our machines in UCC. In other words, for each of the following, find the left-hand side in your file and, if necessary, change the right-hand side to what you see below.
allow_call_time_pass_references = On
allow_url_fopen = Off
error_reporting = E_ALL & ~E_STRICT
log_errors = Off
magic_quotes_gpc = On
precision = 12
register_argc_argv = On
safe_mode = On
short_open_tag = On
Save the file and exit Notepad. Then start the servers again by left-clicking the System Tray icon and choosing Start All Services. Wait for the icon to turn from red to yellow and then to green.
We will add a password to your MySQL database:
localhost
. This takes you to another new
web page.
C:\wamp\apps\phpmyadmin\config.inc.php
.
$cfg['Servers'][$i]['password'] = '';and change it thus:
$cfg['Servers'][$i]['password'] = 'yournewpassword';but replacing yournewpassword with the password that you just created with phpMyAdmin.
N.B. The above is adequate for an installation on your personal laptop or PC, especially since I recommended that you keep the server offline, so that external users cannot access it. If you are installing on a shared machine, or running online, then consult an authoratative source for information about secure configuration.
At the moment, if you left click the WAMP icon in your System Tray and, from the menu, choose Localhost (or phpMyAdmin), I imagine that it is the Firefox browser that is launched. Let's suppose you want to change this to Chrome.
You must use a text editor such as Notepad++ to open and edit two files:
C:/wamp/wampmanager.conf
and C:/wamp/wampmanager.ini
.
In these two files, you must replace all occurrences of this:
C:/Program Files/Mozilla Firefox/firefox.exe
with the location of your installation of Chrome, most likely the following:
C:/Users/userid/AppData/Local/Google/Chrome/Application/chrome.exe --enable-ipv6
— but with the user id that you use when logging in to your PC/laptop
in place of userid
.
Also, in Chrome, choose Settings > Show advanced settings > Change proxy settings > LAN Settings. Make sure that Automatically detect settings is not checked and that Bypass proxy server for local addresses is checked.
With all that done, I found it necessary to restart my machine.
Hopefully, the next time you left-click the WAMP icon in your System Tray and choose Localhost from the menu, it will launch Chrome. But be warned: I found this to be very temperamental!
Your php.ini
file can be found in
Applications/MAMP/conf/php5
.
Use an editor to change this file, as per WAMP above.
The password for MySQL for the root user will be 'root'. If you work out how to (successfully) change this, send me instructions. Leaving it as 'root' is OK. With the free version of MAMP, there is no option anyway of allowing external access. (For MAMP PRO, the story is different.)
Open a terminal and type the command 'sudo gedit /etc/php5/apache2/php.ini
'
Edit the file to make your installation closer to the one you use on our machines in UCC. In other words, for each of the following, find the left-hand side in your file and, if necessary, change the right-hand side to what you see below.
allow_call_time_pass_references = On
allow_url_fopen = Off
error_reporting = E_ALL & ~E_STRICT
log_errors = Off
magic_quotes_gpc = On
precision = 12
register_argc_argv = On
safe_mode = On
short_open_tag = On
There is a lot of commented out information. In gedit, the lines you need to look at and
possibly change should be highlighted in green.
Make sure to save after you make these changes, then restart the php server using this
command: 'sudo /etc/init.d/apache2 restart
'
I will assume that you have launched the servers. (See instructions above.)
To be runnable, your scripts (and HTML, images and stylesheets) must be placed in the following folder:
C:\wamp\www
. (You can reach this folder more quickly by left-clicking on the WAMP
icon in your System Tray and choosing www directory from the menu.)
Suppose you have placed a script called greetings1.php
into the folder. Simply
double-clicking it will not run the script.
Instead, you must open your browser and type in the following URL:
http://localhost/greetings1.php
Obviously, if you had placed greetings1.php
in a subfolder of
C:\wamp\www
, then you would need to include that subfolder's name in the URL.
I will assume that you have launched the servers. (See instructions above.)
To be runnable, your scripts (and HTML, images and stylesheets) must be placed in the following directory:
Applications/MAMP/htdocs
.
Suppose you have placed a script called greetings1.php
into the directory. Simply
double-clicking it will not run the script.
Instead, you must open your browser and type in the following URL:
http://localhost:8888/greetings1.php
8888 is the port, although this can be changed.
Obviously, if you had placed greetings1.php
in a subdirectory of
Applications/MAMP/htdocs
, then you would need to include that subdirectory's name in the URL.
To run scripts they must be in the folder /var/www/
If you have a script called greetings1.php
you will have to browse to
http://localhost/greetings1.php
to view it.