16
TABLE OF CONTENTS ﴾HIDE﴿ 1. Introduction 2. LAMP/WAMP/MAMP Server 2.1 WampServer 2.5 ﴾For Windows 2.2 XAMPP ﴾For Windows/Mac OS 2.3 LAMP Server ﴾For Ubuntu﴿ 3. Eclipse PDT ﴾PHP Developer Too 4. PhpMyAdmin 5. SQL Buddy 6. Debugging PHP Webapps 6.1 XDebug for Debugging Server 6.2 Zend Debugger for Debugging 6.3 Firebug Plugin for Firefox for D 7. PHP Webapp Exercises yet another insignificant programming notes... | HOME Setting Up Apache/MySQL/PHP (AMP) for Linux, Windows and Mac 1. Introduction LAMP/WAMP/MAMP Server To develop PHP webapps, you need to setup Apache, MySQL and PHP, in a so called LAMP ﴾Linux/Apache/MySQL/PHP﴿, WAMP ﴾Windows/Apache/MySQL/PHP﴿, or MAMP ﴾Mac OS X/Apache/MySQL/PHP﴿ environment, for your operating platform. There are two ways of setting up LAMP/WAMP/MAMP: 1. Install individual software components, i.e., Apache, MySQL and PHP. 2. Install a bundle package, which includes all software components needed for developing PHP webapps. For beginners running on Windows/Mac, I certainly recommend the bundle approach for simplicity ﴾although they might not bundled the latest releases﴿. These are the bundles available: WampServer @ http://www.wampserver.com/en/ ﴾for Windows only﴿. XAMPP @ https://www.apachefriends.org/index.html ﴾Cross‐platform for Windows, Mac OS X and Linux﴿. Zend Server ﴾@ http://files.zend.com/help/Zend‐Server‐Community‐Edition/zend‐server‐community‐edition.htm﴿ ﴾Cross‐platform for Windows, Mac OS X and Linux﴿. Easy PHP ﴾@ http://www.easyphp.org/﴿. Others. I shall describe how to install and setup some of these bundles in Section "LAMP/WAMP/MAMP Servers". Integrated Development Environment ﴾IDE﴿ You also need to install an IDE, such as Eclipse PHP Development Tool ﴾PDT﴿. Read Section "How to install Eclipse PDT". You need to setup these debugging tools and be familiar with: Server‐side PHP debugging with xDebug, and Client‐side JavaScript debugging with Firebug.

How to Set Up Apache_MySQL_PHP for Linux (LAMP), Windows (WAMP) and Mac (MAMP)

Embed Size (px)

DESCRIPTION

good

Citation preview

Page 1: How to Set Up Apache_MySQL_PHP for Linux (LAMP), Windows (WAMP) and Mac (MAMP)

6/24/2015 How to Set Up Apache/MySQL/PHP for Linux (LAMP), Windows (WAMP) and Mac (MAMP)

http://www.ntu.edu.sg/home/ehchua/programming/webprogramming/AMP_Setup.html 1/16

TABLE OF CONTENTS ﴾HIDE﴿

1.  Introduction2.  LAMP/WAMP/MAMP Server

2.1  WampServer 2.5 ﴾For Windows﴿2.2  XAMPP ﴾For Windows/Mac OS X/Linux﴿2.3  LAMP Server ﴾For Ubuntu﴿

3.  Eclipse PDT ﴾PHP Developer Tool﴿4.  PhpMyAdmin5.  SQL Buddy6.  Debugging PHP Webapps

6.1  XDebug for Debugging Server‐side PHP Script6.2  Zend Debugger for Debugging Server‐side PHP Script6.3  Firebug Plugin for Firefox for Debugging Client‐side JavaScript/HTML/CSS

7.  PHP Webapp Exercises

yet another insignificant programming notes...   |   HOME

Setting UpApache/MySQL/PHP(AMP) for Linux,Windows and Mac

1.  Introduction

LAMP/WAMP/MAMP Server

To develop PHP webapps, you need to setup Apache, MySQL and PHP, in a so called LAMP﴾Linux/Apache/MySQL/PHP﴿, WAMP ﴾Windows/Apache/MySQL/PHP﴿, or MAMP ﴾Mac OS X/Apache/MySQL/PHP﴿environment, for your operating platform.

There are two ways of setting up LAMP/WAMP/MAMP:

1. Install individual software components, i.e., Apache, MySQL and PHP.

2. Install a bundle package, which includes all software components needed for developing PHP webapps.

For beginners running on Windows/Mac, I certainly recommend the bundle approach for simplicity ﴾although theymight not bundled the latest releases﴿. These are the bundles available:

WampServer @ http://www.wampserver.com/en/ ﴾for Windows only﴿.

XAMPP @ https://www.apachefriends.org/index.html ﴾Cross‐platform for Windows, Mac OS X and Linux﴿.

Zend Server ﴾@ http://files.zend.com/help/Zend‐Server‐Community‐Edition/zend‐server‐community‐edition.htm﴿﴾Cross‐platform for Windows, Mac OS X and Linux﴿.

Easy PHP ﴾@ http://www.easyphp.org/﴿.

Others.

I shall describe how to install and setup some of these bundles in Section "LAMP/WAMP/MAMP Servers".

Integrated Development Environment ﴾IDE﴿

You also need to install an IDE, such as Eclipse PHP Development Tool ﴾PDT﴿. Read Section "How to install EclipsePDT".

You need to setup these debugging tools and be familiar with:

Server‐side PHP debugging with xDebug, and

Client‐side JavaScript debugging with Firebug.

Page 2: How to Set Up Apache_MySQL_PHP for Linux (LAMP), Windows (WAMP) and Mac (MAMP)

6/24/2015 How to Set Up Apache/MySQL/PHP for Linux (LAMP), Windows (WAMP) and Mac (MAMP)

http://www.ntu.edu.sg/home/ehchua/programming/webprogramming/AMP_Setup.html 2/16

Read Section "Debugging PHP Webapps".

Programming Languages

I shall assume that you have some basic knowledge on these programming languages. Otherwise, read the relevantsections.

1. Database programming: SQL ﴾or PostgreSQL﴿. Read the "SQL Section".

2. Sever‐side programming: PHP ﴾or Python, or Perl﴿. Read "PHP Section"

3. Client‐side programming: HTML, CSS and JavaScript. Read "Client‐side Programming: HTML/CSS/JavaScriptSection". In addition, BootStrap and jQuery for advanced programming.

﴾Not for Dummies﴿ Version Control System

Set up a Version Control System, such as Git, for backup, version control and collaboration. Read "How to setup andget started with Git".

 

2.  LAMP/WAMP/MAMP ServerIn this section, I shall briefly describe how to install and customize some of the AMP bundles. To install individualcomponents, read "How to install and get start with Apache", "How to install and get started with MySQL".

2.1  WampServer 2.5 ﴾For Windows﴿

WampServer ﴾@ http://www.wampserver.com/en/﴿ bundles Apache, MySQL and PHP for Winodws in a singlepackage. It also includes tools such as PhpMyAdmin ﴾a MySQL database administration tool﴿, SQL Buddy ﴾analternative to PhpMyAdmin﴿, XDebug ﴾a PHP Debugging Tool﴿, WebGrind ﴾a PHP Profiling Tool﴿.

At the time of writing, WampServer 2.5 bundles Apache 2.4.9, MySQL 5.6.17, PHP 5.5.12, PhpMyAdmin 4.1.14,SqlBuddy 1.3.3 and XDbebug 2.2.5.

Installing WampServer

To Install WampServer:

1. Download: Goto WampServer mother site at http://www.wampserver.com/en ⇒ Select "DOWNLOADS" ⇒Choose the appropriate package for your platform ﴾32‐bit or 64‐bit﴿ ⇒ Download the installation file ﴾e.g.,wampserver2.5‐Apache‐2.4.9‐Mysql‐5.6.17‐php5.5.12‐64b.exe﴿.

2. Install: To install the WampServer, simply run the downloaded installation file. Choose your installationdirectory. I shall assume that WampServer is installed in "d:\WampServer", denoted as <WAMPSERVER_HOME>, inthis article.

Starting/Stopping WampServer

To start the WampServer, choose "Start WampServer" from the "Start" menu; or run "wampmanager.exe" from theWampServer installed directory.

An little icon will appear on the icon tray. "Green" indicates that all the services have started; while "Red" indicatesthat all the services have stopped. Click on the icon to open the "WampServer Control Panel". You could:

Under "Quick Admin": Start/Stop/Restart all the services ﴾Apache & MySQL services﴿.

Put the server online ﴾so that user can access the server over the Internet﴿ or offline.

Page 3: How to Set Up Apache_MySQL_PHP for Linux (LAMP), Windows (WAMP) and Mac (MAMP)

6/24/2015 How to Set Up Apache/MySQL/PHP for Linux (LAMP), Windows (WAMP) and Mac (MAMP)

http://www.ntu.edu.sg/home/ehchua/programming/webprogramming/AMP_Setup.html 3/16

Configure Apache, MySQL and PHP, under their respective sections.

Launch "PhpMyAdmin".

Others.

To shutdown the program, click "Stop All Services" on WampServer Control Panel ⇒ right‐click on the WampServericon ⇒ Exit.

Verifying Apache/MySQL/PHP Installation

By default, a directory called "www" was created under the WampServer installed directory, which serves as theApache's document root directory. A welcome page called "index.php" was also created in the "www" directory.

To verify the installation:

1. Start the WampServer. Wait for the icon to turn green indicating all services have started ﴾otherwise, click theicon and select "Start All Services"﴿. For testing, put the server "offline" to disable external access ﴾i.e., it can onlybe accessed in localhost﴿.

2. To verify Apache: Start a browser and issue URL http://localhost. This will in turn request for "index.php".The index page provides links to documentations, aliases and tools. The installation creates these aliases forApache: phpmyadmin, sqlbuddy, phpsysinfo for the respective services. You can issue URLhttp://localhost/alias‐name to access these services.

3. To verify MySQL: Issue URL http://localhost/phpmyadmin to access the MySQL via PhpMyAdmin. Click onthe "Users", which reveals that no password was set for the superuser root and the anonymous user.

4. To verify PHP: Issue URL http://localhost/?phpinfo=1, which runs the phpinfo() function.

Write a Hello‐world PHP Script

Use a programming editor ﴾such as notepad++ for Windows, or gedit for Ubuntu/Mac OS X﴿ to write a simple PHPscript called "hello.php" and save under the "www" directory, as follows:

<html><head><title>First PHP Page</title></head><body><?phpecho '<h1>Hello, world!</h1>';?></body></html>

To run this script, start a browser and issue URL http://localhost/hello.php, assuming that the Apache serverhas been started.

Another Example : Write another PHP script called "phpinfo.php" ﴾saved under "www"﴿ to display the PHPsettings under Apache, as follows:

<?phpphpinfo();?>

Run the script by issuing URL "http://localhost/phpinfo.php".

WampServer Directory Structure

WampServer is organized in the following directory structure. The important ones are:

Page 4: How to Set Up Apache_MySQL_PHP for Linux (LAMP), Windows (WAMP) and Mac (MAMP)

6/24/2015 How to Set Up Apache/MySQL/PHP for Linux (LAMP), Windows (WAMP) and Mac (MAMP)

http://www.ntu.edu.sg/home/ehchua/programming/webprogramming/AMP_Setup.html 4/16

bin : contains binaries for Apache, MySQL, and PHP, in their respectively sub‐directory. For each component, youcan install multiple versions and select one of them in operation.

apps : contains server‐side tools such as PhpMyAdmin, SQL Buddy, and WebGrind.

tools : contains client‐side tool such as xdc ﴾XDebug Client﴿.

www : the default apache's document root directory.

logs : contains apache, php, mysql error/access logs.

alias : contains the the apache's alias configuration for PhpMyadmin, SQL Buddy and WebGrind.

Apache Configuration

The Apache's main configuration file "httpd.conf" is located at "<WAMPSERVER_HOME>\bin\apache\Apache2.x.xx\conf". Take note of the following configuration directives.

The core directives are:

ServerRoot "<WAMPSERVER_HOME>/bin/apache/apache2.x.xx"Listen 80ServerName localhost:80DocumentRoot "<WAMPSERVER_HOME>/www/"

The ServerRoot specifies the apache's installed directory. Listen specifies the TCP port number for Apache webserver, in this case, default of TCP port 80. The DocumentRoot specifies the root directory of the web server.

The directives related to directory authorization are:

## Each directory to which Apache has access can be configured with respect# to which services and features are allowed and/or disabled in that# directory (and its sub‐directories). ## First, we configure the "default" to be a very restrictive set of # features.  #<Directory />    Options FollowSymLinks    AllowOverride None    Order deny,allow    Deny from all</Directory>## This should be changed to whatever you set DocumentRoot to.#DocumentRoot "<WAMPSERVER_HOME>/www/"<Directory "<WAMPSERVER_HOME>/www/">    Options Indexes FollowSymLinks    AllowOverride all    Order Deny,Allow    Deny from all    Allow from 127.0.0.1</Directory>

[TODO] Explanation

The directives related to logging are:

ErrorLog "<WAMPSERVER_HOME>/logs/apache_error.log"CustomLog "<WAMPSERVER_HOME>/logs/access.log" common

Page 5: How to Set Up Apache_MySQL_PHP for Linux (LAMP), Windows (WAMP) and Mac (MAMP)

6/24/2015 How to Set Up Apache/MySQL/PHP for Linux (LAMP), Windows (WAMP) and Mac (MAMP)

http://www.ntu.edu.sg/home/ehchua/programming/webprogramming/AMP_Setup.html 5/16

PHP Configuration

The PHP's main configuration for Apache2 "php.ini" is located at "<WAMPSERVER_HOME>\bin\apache\Apache2.x.xx\bin" ﴾as revealed by phpinfo() output﴿.

[TODO] Explanation

MySQL Configuration

The MySQL's main configuration file "my.ini" is located at "<WAMPSERVER_HOME>\bin\mysql\mysql5.x.xx". Takenote of the following settings:

MySQL Server

[wampmysqld]port = 3306socket = /tmp/mysql.sockbasedir=<WAMPSERVER_HOME>/bin/mysql/mysql5.x.xxlog‐error=<WAMPSERVER_HOME>/logs/mysql.logdatadir=<WAMPSERVER_HOME>/bin/mysql/mysql5.x.xx/data

The port specifies the TCP port number for the MySQL server ﴾defaulted to 3306﴿. The basedir specifies theMySQL installed directory. The datadir specifies the databases directory. The log‐error specifies the MySQLerror log file.

MySQL Server Daemon ﴾mysqld.exe﴿

[mysqld]port = 3306

MySQL Interactive Client ﴾mysql﴿

[client]port = 3306

Customizing MySQL

The default MySQL installation creates a superuser "root" without password. It also creates an anonymous user withno password. You need to:

1. Set a password for "root".

2. Remove the anonymous user.

3. You should not use superuser "root" for normal daily operations. Instead, create a new user ﴾says wampuser﴿for operational use.

There are many ways to administer MySQL, via the graphical client "PhpMyAdmin" or "SQL Buddy"; or command‐lineclient "mysql.exe".

PhpMyAdmin: login to PhpMyAdmin via "http://localhost/phpmyadmin". Click the "Users" tab ⇒ Setpassword for root ﴾for all hosts﴿ ﴾Select ⇒ Edit Privilege ⇒ Change Password ⇒ GO ⇒ Refresh﴿. Delete theanonymous user denoted as "Any" User ﴾Select ⇒ Remove selected users ⇒ GO﴿. Create a new user called"wampuser" by clicking the "Add User". Grant all privileges to begin with.Note: Once you set a password for root, you may need to modify the PHP configuration file in order to login withthe new password. See "PhpMyAdmin PHP Configuration".

SQL Buddy: login to SQL Buddy via "http://localhost/sqlBuddy". Click "Submit" with empty password for"root". Select "Users". Set password for all root users of all hosts ﴾Select ⇒ Edit﴿. Remove the anonymous user﴾the row with empty user name﴿ ﴾Select ⇒ Delete﴿. Create a new user called "wampuser" by filling in "Add a New

Page 6: How to Set Up Apache_MySQL_PHP for Linux (LAMP), Windows (WAMP) and Mac (MAMP)

6/24/2015 How to Set Up Apache/MySQL/PHP for Linux (LAMP), Windows (WAMP) and Mac (MAMP)

http://www.ntu.edu.sg/home/ehchua/programming/webprogramming/AMP_Setup.html 6/16

User". Grant all privileges except the "Grant option" to begin with.

MySQL command‐line client ﴾"mysql.exe"﴿: Read "How to setup MySQL".

Start a new PHP Webapp

To start a new PHP webapp, create you working directory under "www" ﴾says directory "hello"﴿. You can launch yourwebapp via URL "http://localhost/hello". Alternatively, you can use the "www" directory, by removing all theexisting contents. You can access the webapp via URL "http://localhost".

For Production, configure a virtual host ﴾in Apache﴿ for your project.

2.2  XAMPP ﴾For Windows/Mac OS X/Linux﴿

The XAMPP ﴾stands for Cross‐platform, Apache, MySQL, PHP and Perl @ https://www.apachefriends.org/index.html﴿bundles Apache, MySQL, PHP and Perl, for Windows, Linux and Mac OS X. It also includes FileZilla FTP Server, MercuryMail Server, and Tomcat Server; plus tools PhpMyAdmin, Webalizer, and Fake Sendmail.

At the time of writing, XAMPP 1.8.3 bundles PHP 5.5.15, Apache 2.4.10, MySQL 5.6.20 and PhpMyAdmin 4.2.7.1.

Installing XAMPP on Windows

1. Download: Goto XAMPP mother site at https://www.apachefriends.org/index.html ⇒ Download the Windowspackage ﴾e.g., xampp‐win32‐1.8.3‐5‐VC11‐installer.exe﴿.

2. Install: Simply run the downloaded Installer. Choose your installation directory. I shall assume that XAMPP isinstalled in "d:\xampp", denoted as <XAMPP_HOME>, in this article.

Installing XAMPP on Mac OS X [@@To Check!!]

1. Download: Goto XAMPP mother site at https://www.apachefriends.org/index.html ⇒ Download the Mac OSX package ﴾e.g., .....﴿.

2. Install: Simply run the downloaded Installer. Choose your installation directory. I shall assume that XAMPP isinstalled in "......", denoted as <XAMPP_HOME>, in this article.

Starting/Stopping XAMPP Servers

Launch the "XAMPP Control Panel" ﴾"xampp‐control.exe" for Windows, @@To Check ...... MAC OS X﴿ under theXAMPP installed directory. A little icon appears in the Icon Tray. Right‐click on the icon ⇒ "Show/Hide" to show the"full" Control Panel Window.

The XAMPP Control Panel allows you to start/stop each of these servers: Apache HTTP Server, MySQL DatabaseServer, FileZilla FTP Server, Mercury Mail Server, and Tomcat HTTP Server. You can also check their configurations﴾"Config"﴿, logs ﴾"Logs"﴿ and launch the administrator tools such as PhpMyAdmin for MySQL ﴾"Admin"﴿.

Verifying the Apache/MySQL/PHP/Perl Installation

By default, a directory called "htdocs" was created under the XAMPP installed directory, which serves as the Apache'sdocument root directory.

To verify the installation, launch the XAMPP Control Panel. Start the Apache and MySQL servers by clicking the "Start"buttons.

On your browser, issue "http://localhost" to get the welcome page. Select your language, which leads you tothe XAMPP home page ﴾under "htdocs/xampp"﴿. You can now verify all the components by clicking on the infolinks on the left panel, e.g., phpinfo() for PHP, perlinfo() for Perl, PhpMyAdmin for MySQL.

Page 7: How to Set Up Apache_MySQL_PHP for Linux (LAMP), Windows (WAMP) and Mac (MAMP)

6/24/2015 How to Set Up Apache/MySQL/PHP for Linux (LAMP), Windows (WAMP) and Mac (MAMP)

http://www.ntu.edu.sg/home/ehchua/programming/webprogramming/AMP_Setup.html 7/16

On your browser, issue "http://localhost/phpmyadmin" to access the MySQL via PhpMyAdmin. Select the"Users" tab. which reveals that no password is set for the superuser root and the anonymous user. ﴾You can alsoclick the "Admin" button under MySQL to launch PhpMyAdmin.﴿

To shutdown XAMPP, stop all the services and press "Quit".

Write a Hello‐world PHP Script

By default, the Apache's document root directory is located at "<XAMPP_HOME>/htdocs". Use a programming editor﴾such as notepad++ for Windows, or gedit for Ubuntu/Mac OS X﴿ to write a simple PHP script called "hello.php"and save under the "htdocs" directory, as follows:

<html><head><title>First PHP Page</title></head><body><?phpecho '<h1>Hello, world!</h1>';?></body></html>

To run this PHP script, start a browser and issue URL http://localhost/hello.php, assuming that Apache serverhas been started.

Another Example : Write another PHP script called "phpinfo.php" ﴾saved under "htdocs"﴿ to display the PHPsettings under Apache, as follows:

<?phpphpinfo();?>

Run the script by issuing URL "http://localhost/phpinfo.php".

XAMPP Directory Structure

XAMPP is organized in the sub‐directories. The important ones are:

htdocs : the default apache's document root directory.

apache , mysql , FileZillaFTP , MercuryMail , tomcat : for the server software.

phpMyAdmin : for the PhpMyAdmin tool.

php , perl : for the languages.

Apache Configuration

The Apache's main configuration file "httpd.conf" is located at "<XAMPP_HOME>\apache\conf". Take note of thefollowing configuration directives:

The core directives are:

ServerRoot "<XAMPP_HOME>/apache"Listen 80ServerName localhost:80DocumentRoot "<XAMPP_HOME>/htdocs"

The ServerRoot specifies the apache's installed directory. Listen specifies the TCP port number for Apache webserver, in this case, default of TCP port 80. The DocumentRoot specifies the root directory of the web server.

Page 8: How to Set Up Apache_MySQL_PHP for Linux (LAMP), Windows (WAMP) and Mac (MAMP)

6/24/2015 How to Set Up Apache/MySQL/PHP for Linux (LAMP), Windows (WAMP) and Mac (MAMP)

http://www.ntu.edu.sg/home/ehchua/programming/webprogramming/AMP_Setup.html 8/16

The directives related to directory authorization are:

## Deny access to the entirety of your server's file system. You must# explicitly permit access to web content directories in other # <Directory> blocks below.#<Directory />    AllowOverride none    Require all denied</Directory> ## DocumentRoot: The directory out of which you will serve your# documents. By default, all requests are taken from this directory, but# symbolic links and aliases may be used to point to other locations.#DocumentRoot "<XAMPP_HOME>/htdocs"<Directory "<XAMPP_HOME>/htdocs">    Options Indexes FollowSymLinks Includes ExecCGI    AllowOverride All    #    # Controls who can get stuff from this server.    #    Require all granted</Directory>

[TODO] Explanation

The directives related to logging are:

ErrorLog "logs/error.log"CustomLog "logs/access.log" combined

PHP Configuration

The PHP's main configuration file "php.ini" is located from "<XAMPP_HOME>\php" ﴾as revealed by phpinfo()output﴿.

[TODO] Explanation

MySQL Configuration

The MySQL's main configuration file "my.ini" is located at "<XAMPP_HOME>\mysql\bin". Take note of the followingsettings:

MySQL Server Daemon ﴾mysqld.exe﴿

[mysqld]port = 3306socket = "<XAMPP_HOME>/mysql/mysql.sock"basedir = "<XAMPP_HOME>/mysql"tmpdir = "<XAMPP_HOME>/tmp"datadir = "<XAMPP_HOME>/mysql/data"pid_file = "mysql.pid"log_error = "mysql_error.log"

The port specifies the TCP port number for the MySQL server ﴾defaulted to 3306﴿. The basedir specifies theMySQL installed directory. The datadir specifies the databases directory. The log‐error specifies the MySQLerror log file.

Page 9: How to Set Up Apache_MySQL_PHP for Linux (LAMP), Windows (WAMP) and Mac (MAMP)

6/24/2015 How to Set Up Apache/MySQL/PHP for Linux (LAMP), Windows (WAMP) and Mac (MAMP)

http://www.ntu.edu.sg/home/ehchua/programming/webprogramming/AMP_Setup.html 9/16

MySQL Interactive Client ﴾mysql﴿

[client]port = 3306socket = "<XAMPP_HOME>/mysql/mysql.sock"

Customizing MySQL

The default MySQL installation creates a superuser called "root" without password. It also provides an anonymoususer with no password. You need to

1. Set a password for "root".

2. Remove the anonymous user.

3. You should not use superuser "root" for normal daily operations. Instead, create a new user ﴾says xampppuser﴿for operational use.

There are a few ways to administer MySQL, via the graphical client "PhpMyAdmin", or command‐line client "mysql".

PhpMyAdmin: login to PhpMyAdmin via "http://localhost/phpmyadmin". Click the "Users" tab ⇒ Setpassword for root ﴾for all hosts﴿ ﴾Select ⇒ Edit Privilege ⇒ Change Password ⇒ GO ⇒ Refresh﴿. Delete theanonymous user denoted as "Any" User ﴾Select ⇒ Remove selected users ⇒ GO﴿. Create a new user called"xampppuser" by clicking the "Add User". Grant all privileges to begin with.Note: Once you set a password for root, you may need to modify the PHP configuration file in order to login withthe new password. See "PhpMyAdmin PHP Configuration".

MySQL command‐line client ﴾"mysql.exe"﴿: Read "How to setup MySQL".

Start a new PHP Webapp

To start a new PHP webapp, create you working directory under "htdocs" ﴾says directory "hello"﴿. You can launchyour webapp via URL "http://localhost/hello". Alternatively, you can use the "htdocs" directory, by removing allthe existing contents. You can access the webapp via URL "http://localhost".

For Production, configure a virtual host ﴾in Apache﴿ for your project.

2.3  LAMP Server ﴾For Ubuntu﴿

Read the various sections in "How to Install and Setup Ubuntu". For example,

1. Install Ubuntu: Read "How to install Ubuntu Desktop".

2. Install LAMP Server: Read "How to install LAMP Server for Ubuntu".

3. Install PHPMyAdmin: Read "How to install PHPMyAdmin for Ubuntu".

4. Others.

3.  Eclipse PDT (PHP Developer Tool)Eclipse PDT ﴾@ http://www.eclipse.org/pdt﴿ is an IDE for PHP webapp development. The main advantage is it candebug PHP Server‐side scripts with XDebug or Zend Debugger.

Alternative PHP IDEs are: NetBeans ﴾@ http://www.netbeans.org﴿, PHPEclipse ﴾@ http://www.phpeclipse.com﴿.

Install Eclipse PDT

If you have never installed any Eclipse package, goto Eclipse mother site @ http://www.eclipse.org ⇒ Downloads

Page 10: How to Set Up Apache_MySQL_PHP for Linux (LAMP), Windows (WAMP) and Mac (MAMP)

6/24/2015 How to Set Up Apache/MySQL/PHP for Linux (LAMP), Windows (WAMP) and Mac (MAMP)

http://www.ntu.edu.sg/home/ehchua/programming/webprogramming/AMP_Setup.html 10/16

⇒ Select "Eclipse for PHP Developers":

For Windows: Download the ZIP file ﴾32‐bit or 64‐bit﴿. Unzip the downloaded file in a directory of yourchoice.

For Mac OS X: Read "How to Install Eclipse on Mac".

For Ubuntu: Read "How to Install Eclipse on Ubuntu".

If you have installed an Eclipse package ﴾such as Eclipse IDE for Java Developers﴿, you can add the PDT plugin by:

Launched Eclipse ⇒ Select menu "Help" ⇒ "Install New Software".

The "Install" dialog appears. In "Work with" field, pull down the drop‐down menu and select "Luna ‐http://download.eclipse.org/releases/luna" ﴾or Kepler for Eclipse 4.3; or Juno for Eclipse 4.2; or helios forEclipse 3.7﴿.

In the "Name" box, expand "Programming Language" node ⇒ Check "PHP Development Tools ﴾PDT﴿" ⇒"Next" ⇒ Accept the license ⇒ "Finish".

Configure Eclipse PDT

Launch Eclipse ﴾run "eclipse.exe" from the Eclipse installed directory﴿ ⇒ Select menu "Window" ⇒ "Preferences" ⇒Expand "PHP" node:

1. Select "PHP Servers" ⇒ Check that there is an entry with "Name" of "Default PHP Server" and "URL" of"http://localhost" ⇒ Select the entry ⇒ Edit ⇒ Select "Server" tab ⇒ In "Debugger": Select "XDebug".

2. Select "PHP Executable" ⇒ "Add":

In "Name", Enter a name, e.g. "WampServer" or "XAMPP".

In "Executable Path", enter the location of PHP executable "php.exe" ﴾e.g., "<WAMPSERVER_HOME>\bin\php\php5.x.x\php.exe" for WampServer, "<XAMPP_HOME>\php\php.exe" forXAMPP ﴾Windows﴿﴿.

In "PHP ini file", enter the php configuration file used by the Apache ﴾e.g., "<WAMPSERVER_HOME>\bin\apache\Apache2.2.xx\bin\php.ini" for WampServer. "<XAMPP_HOME>\php\php.ini" for XAMPP ﴾Windows﴿﴿.

In "SAPI Type", select "CGI".

In "PHP Debugger", select "XDebug" ﴾which is bundled in WampServer and XAMPP﴿.

3. Select "Debug":

In "PHP Debugger", select "XDebug".

In "Server", select "Default PHP Server".

In "PHP Executable", select the PHP Executable configured in the previous step ﴾i.e., "WampServer" or"XAMPP"﴿.

4. Select "PHP Manual" ⇒ Check that there is an entry with "Site Name" of "php.net" with "URL" of"http://www.php.net/manual/en".

5. Browse through the other settings for PHP.

Writing a Hello‐world PHP program in Eclipse PDT

1. Launch Eclipse. Choose a workspace.

2. Create a new PHP project: "File" ⇒ New ⇒ PHP Project ﴾or "Project..." ⇒ PHP ⇒ PHP Project﴿.

In "Project Name", enter a name for the project, e.g., "hello".

In "Contents", select "Create project at exiting location", enter your web server's root directory followed bythe project name ﴾e.g., "<WAMPSERVER_HOME>\www\hello" for WampServer, "

Page 11: How to Set Up Apache_MySQL_PHP for Linux (LAMP), Windows (WAMP) and Mac (MAMP)

6/24/2015 How to Set Up Apache/MySQL/PHP for Linux (LAMP), Windows (WAMP) and Mac (MAMP)

http://www.ntu.edu.sg/home/ehchua/programming/webprogramming/AMP_Setup.html 11/16

<XAMPP_HOME>\htdocs\hello" for XAMPP ‐ Make a sub‐directory called "hello" under "www" or"htdocs"﴿ ⇒ "Finish".

3. Write your PHP program: Right‐click on the project "hello" ⇒ "New" ⇒ "PHP File". Enter the following codesand saved as "HelloObj.php":

<?phpclass Hello{   // Variables   var $message;    // Constructor   function __construct(){      $this‐>message= "Hello World!";   }    /**    * Function that prints the value of the instance variable $message    */   function printMessage(){      echo $this‐>message;   }}?>

Again, create a new PHP file for the following driver program "HelloDriver.php":

<?phpinclude_once('HelloObj.php');$hello= new hello();$hello‐>printMessage();?>

4. To run the program, right‐click anywhere on "HelloDriver.php" ⇒ "Run As" ⇒ "PHP Web Application"﴾output shown in Eclipse internal browser or external browser﴿ ⇒ The launch URL shall behttp://localhost/hello/HelloDriver.php.To select your browser, select "Window" ⇒ Preferences ⇒ General ⇒ Web Browser ⇒ Choose your browser,such as internal web browser, or external web browser ﴾Firefox, IE, etc﴿.The browser shall display "Hello World!".Note: You can also run this script as a "PHP CLI Application", i.e., a standalone command‐line interface programinstead of server‐side script, as the above program are purely PHP, with no HTML statements.

Debugging PHP Server‐side Script

HERE.

4.  PhpMyAdminPhpMyAdmin ﴾http://www.phpmyadmin.net﴿ is a popular open source web‐base tool intended to handle theadministration of MySQL database system.

Installing PhpMyAdmin

PhpMyAdmin is bundled in WampServer, installed under "<WAMPSERVER_HOME>\apps\phpmyadmin4.x.xx". It is alsobundled in XAMPP, under "<XAMPP_HOME>\phpmyadmin".

For Ubuntu, read "Install PhpMyAdmin for Ubuntu".

Page 12: How to Set Up Apache_MySQL_PHP for Linux (LAMP), Windows (WAMP) and Mac (MAMP)

6/24/2015 How to Set Up Apache/MySQL/PHP for Linux (LAMP), Windows (WAMP) and Mac (MAMP)

http://www.ntu.edu.sg/home/ehchua/programming/webprogramming/AMP_Setup.html 12/16

Launching PhpMyAdmin

PhpMyAdmin is an Apache PHP application. Typically, an alias called "phpmyadmin" is defined which maps to itsinstalled directory.

To launch PhpMyAdmin, start Apache and MySQL servers. Then, start a browser and issue URLhttp://localhost/phpmyadmin.

Using PhpMyAdmin

[TODO]

PhpMyAdmin's Configuration for Apache

In WampServer: PhpMyAdmin is configured in "<WAMPSERVER_HOME>\alias\phpmyadmin.conf", which isincluded into Apache's main configuration file "<WAMPSERVER_HOME>\bin\apache\apache2.4.9\conf\httpd.conf" via directive "Include  "<WAMPSERVER_HOME>/alias/*"". In the "phpmyadmin.conf", an alias called "/phpmyadmin" is defined whichmaps to PhpMyAdmin's directory "<WAMPSERVER_HOME>/apps/phpmyadmin4.x.xx/".

In XAMPP: PhpMyAdmin is configured in "<XAMPP_HOME>\apache\conf\extra\httpd‐xampp.conf", which isincluded into Apache's main configuration file "<XAMPP_HOME>\apache\conf\httpd.conf" via an Includedirective. In the configuration, an alias called "/phpmyadmin" is defined which maps to PhpMyAdmin's directoryat "<XAMPP_HOME>/phpMyAdmin/".

PhpMyAdmin's PHP Configuration

PhpMyAdmin is a PHP app running under Apache. The PHP app uses a configuration file called "config.inc.php",located at the PhpMyAdmin installed directory. The default configuration uses so‐called "config" authentication typewhich requires you to hardcode the MySQL user and password inside the configuration file:

$cfg['Servers'][$i]['auth_type'] = 'config'$cfg['Servers'][$i]['user'] = 'root';$cfg['Servers'][$i]['password'] = 'your_root_password';$cfg['Servers'][$i]['AllowNoPassword'] = true;

If you change MySQL root's password, you need to enter the new password into this file, in order to login intoMySQL.

I recommend that you change the authentication type to "cookie", which prompts you to for the login user andpassword.

// $cfg['Servers'][$i]['auth_type'] = 'config'$cfg['Servers'][$i]['auth_type'] = 'cookie';// $cfg['Servers'][$i]['user'] = 'root';// $cfg['Servers'][$i]['password'] = 'your_root_password';// $cfg['Servers'][$i]['AllowNoPassword'] = true;

Notes on ErrorsCannot login using root, after setting password. See above.

If you get an error "Connection for controluser as defined in your configuration failed", see"http://stackoverflow.com/questions/11506224/connection‐for‐controluser‐as‐defined‐in‐your‐configuration‐failed‐phpmyadmin‐xa". ﴾I encountered this error for XAMPP.﴿

Page 13: How to Set Up Apache_MySQL_PHP for Linux (LAMP), Windows (WAMP) and Mac (MAMP)

6/24/2015 How to Set Up Apache/MySQL/PHP for Linux (LAMP), Windows (WAMP) and Mac (MAMP)

http://www.ntu.edu.sg/home/ehchua/programming/webprogramming/AMP_Setup.html 13/16

5.  SQL BuddySQL Buddy ﴾http://www.sqlbuddy.com﴿ is an alternative to PhpMyAdmin. SQL Buddy is bundled in WampServer,under directory <WAMPSERVER_HOME>\apps\sqlbuddy1.3.x. SQL Buddy could be easier to use than PhpMyAdmin.

To use SQL Buddy, start a browser, and issue URL http://localhost/sqlbuddy.

[TODO] more user guide

6.  Debugging PHP Webapps

6.1  XDebug for Debugging Server‐side PHP Script

XDebug ﴾@ http://xdebug.org﴿ is an PHP extension, that allow you to debug server‐side PHP Script running underApache in Eclipse PDT.

Install xDebug Extension for PHP

For WampServer, xDebug module is installed as "<WAMPSERVER_HOME>/bin/php/php5.x.xx/zend_ext/php_xdebug‐2.x.x‐5.x‐vc11‐x86_64.dll".

For XAMPP ﴾Windows﴿, xDebug module is "<XAMPP_HOME>/php/ext/php_xdebug.dll".

For XAMPP ﴾Mac OS X﴿, xDebug module is ...... @@To check

For Ubuntu, read "Install XDebug extension for PHP" for Eclipse PDT".

To verify that xDebug is installed, search the phpinfo() output ﴾run "phpinfo.php" written earlier﴿ for "xdebug",which shall show up as follows:

Configure xDebug for Eclipse PDT1. Find the PHP configuration file for Apache from the phpinfo() output, under "Loaded Configuration File".

For WampServer, it is "<WAMPSERVER_HOME>\bin\apache\apache2.4.9\bin\php.ini".

For XAMPP ﴾Windows﴿, it is "<XAMPP_HOME>/php/php.ini".

For XAMPP ﴾Mac OS X﴿, it is "<XAMPP_HOME>/php/php.ini". ﴾@@ To Check﴿

For Ubuntu: See "Install XDebug extension for PHP" for Eclipse PDT".

2. Check if the following lines are included in the PHP configuration file ﴾include them otherwise﴿:

; For WampServerzend_extension = "<WAMPSERVER_HOME>/bin/php/php5.5.12/zend_ext/php_xdebug‐2.2.5‐5.5‐vc11‐x86_64.dll"; For Ubuntuzend_extension=xdebug.so; For XAMPP (For Windows)zend_extension = "<XAMPP_HOME>/php/ext/php_xdebug.dll"; For XAMPP (for Mac OS X)zend_extension = "<XAMPP_HOME>/......."

Page 14: How to Set Up Apache_MySQL_PHP for Linux (LAMP), Windows (WAMP) and Mac (MAMP)

6/24/2015 How to Set Up Apache/MySQL/PHP for Linux (LAMP), Windows (WAMP) and Mac (MAMP)

http://www.ntu.edu.sg/home/ehchua/programming/webprogramming/AMP_Setup.html 14/16

......

[xdebug]xdebug.remote_enable = Onxdebug.remote_port = 9000xdebug.remote_host = 127.0.0.1

Restart the Apache Server.

Example 1: Debugging PHP Server‐side Script

Let's trace through the "hello" PHP Webapp created earlier, which contains two PHP scripts: "HelloDriver.php"and "HelloObj.php".

1. Set a breakpoint at line 2 of "HelloDriver.php" by clicking on the left margin.

2. Right‐click on "HelloDriver.php" ⇒ "Debug As" ⇒ "PHP Web Application".

3. Switch to "Debug" perspective.

4. The program shall break at line 2 of "HelloDriver.php". Click "Step Into ﴾F5﴿" or "Step Over ﴾F6﴿" to tracethrough the program. Inspect the variables and observe the output at the web browser.

5. You need to terminate the debugging session by pushing the "Terminate" button.

Take note that if you check "Break at First Line" in the debug configuration, the program will pause at the first line ofa PHP file. You need to push "Resume" or "Step Over".

Example 2: Debugging PHP Webapp ﴾HTML+PHP﴿

Create the following two files "Query.php" and "ProcessQuery.php", saved under Apache's document rootdirectory.

<!DOCTYPE html><!‐‐  Query.php  ‐‐><html><head>  <title>Test HTML Form</title></head><body>  <form method="post" action="ProcessQuery.php">  What is your name? <input type="text" name="username" />  <input type="submit" />  </form></body></html>

<?php// ProcessQuery.phpecho '<h2>Thank you for your query</h2>';if (isset($_POST['username'])) {   echo '<h2>Hello, ' . htmlentities($_POST['username']) . '</h2>';}?>

Note: This code is meant for illustrating PHP webapp debugging. In practice, the two files are often merged into one.

To run the PHP webapp, right‐click on "Query.php" ⇒ Run As ⇒ PHP Web Application

To debug the PHP webapp:

1. right‐click on "Query.html" ⇒ Debug As ⇒ Debug Configuration ⇒ Select "Debugger" tab ⇒ Check "Break atFirst Line" ﴾which sets a breakpoint at the beginning of each file﴿ ⇒ "Debug".

Page 15: How to Set Up Apache_MySQL_PHP for Linux (LAMP), Windows (WAMP) and Mac (MAMP)

6/24/2015 How to Set Up Apache/MySQL/PHP for Linux (LAMP), Windows (WAMP) and Mac (MAMP)

http://www.ntu.edu.sg/home/ehchua/programming/webprogramming/AMP_Setup.html 15/16

2. Switch to "Debug" perspective.

3. Push "Resume ﴾F8﴿" button to run thru the HTML code.

4. Switch to the browser. Enter something in the textfield and click "submit".

5. Switch back to Eclipse, it now breaks at the first line of "ProcessQuery.php".

6. Click "Step Into ﴾F5﴿" or "Step Over ﴾F6﴿" to trace through the program. Inspect the variables and observe theoutput at the web browser.

7. You need to terminate the debugging session by pushing the "Terminate" button.

Take note that if your program contains HTML and PHP, your need to switch between the web browser ﴾to enterdata﴿ and eclipse ﴾to push "Resume" to run thru the HTML codes, or "Step Over/Into" to execute the PHP codes﴿. Attimes, the browser/eclipse icons on the taskbar brink to remind you to switch over.

Note: I actually intend to name "Query.php" and "Query.html", but the XDebug session does not seem to start onHTML ﴾although you could tailor the "Run configuration" to start running from an HTML file﴿?! Let me know if youhave an answer. For the time being, name all files ﴾may be only the starting page﴿ ".php" even they contains onlyHTML. This is not really a problem.

6.2  Zend Debugger for Debugging Server‐side PHP Script

[TODO] Can't install Zend Debugger long time ago. To try again and compare with XDebug. Not critical.

6.3  Firebug Plugin for Firefox for Debugging Client‐sideJavaScript/HTML/CSS

HERE

7.  PHP Webapp Exercises1. Read "PHP Basics".

2. Read "PHP MySQL webapps". Use "PDO" for database connection.

3. Convert the "Java Servlet Case Study ebookshop" from Java Servlet ﴾Tomcat/MySQL﴿ to PHP ﴾Apache/MySQL﴿.

4. Read HTML, CSS and JavaScript.

5. Proceed to "Advanced PHP Webapp Development".

REFERENCES & RESOURCES1. Robin Nixon, "Learning PHP, MySQL, JavaScript, and CSS", 2nd ed, O'Reilly, 2012.

2. Timothy Boronczyk, Elizabeth Naramore, Jason Gerner, Yann Le Scouarnec, Jeremy Stolz and Michael K. Glass,"Beginning PHP6 Apache MySQL Web Development", Wrox Programmer to Programmer, 2009.

3. Luke Welling and Laura Thomson, "PHP and MySQL Web Development", 4th edition, Addison‐Wesley, 2008.

4. Dirk Merkel, "Expert PHP 5 Tools", Packt Publishing, 2010.

Latest version tested: WampServer 2.5, XAMPP 1.8.3

Page 16: How to Set Up Apache_MySQL_PHP for Linux (LAMP), Windows (WAMP) and Mac (MAMP)

6/24/2015 How to Set Up Apache/MySQL/PHP for Linux (LAMP), Windows (WAMP) and Mac (MAMP)

http://www.ntu.edu.sg/home/ehchua/programming/webprogramming/AMP_Setup.html 16/16

Last modified: September, 2014

Feedback, comments, corrections, and errata can be sent to Chua Hock­Chuan ([email protected])   |   HOME