Академический Документы
Профессиональный Документы
Культура Документы
HowtoSetUpApache/MySQL/PHPforLinux(LAMP),Windows(WAMP)andMac(MAMP)
Setting Up
Apache/MySQL/PHP
(AMP) for Linux,
Windows and Mac
1.Introduction
2.LAMP/WAMP/MAMP Server
2.1WampServer 2.5 For Windows
2.2XAMPP For Windows/Mac OS X/Linux
2.3LAMP Server For Ubuntu
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 Crossplatform for Windows, Mac OS X and Linux.
Zend Server @ http://files.zend.com/help/ZendServerCommunityEdition/zendservercommunityedition.htm
Crossplatform 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".
1/16
6/24/2015
HowtoSetUpApache/MySQL/PHPforLinux(LAMP),Windows(WAMP)andMac(MAMP)
Programming Languages
I shall assume that you have some basic knowledge on these programming languages. Otherwise, read the relevant
sections.
1. Database programming: SQL or PostgreSQL. Read the "SQL Section".
2. Severside programming: PHP or Python, or Perl. Read "PHP Section"
3. Clientside programming: HTML, CSS and JavaScript. Read "Clientside Programming: HTML/CSS/JavaScript
Section". In addition, BootStrap and jQuery for advanced programming.
2.LAMP/WAMP/MAMP Server
In this section, I shall briefly describe how to install and customize some of the AMP bundles. To install individual
components, read "How to install and get start with Apache", "How to install and get started with MySQL".
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 32bit or 64bit Download the installation file e.g.,
wampserver2.5Apache2.4.9Mysql5.6.17php5.5.1264b.exe.
2. Install: To install the WampServer, simply run the downloaded installation file. Choose your installation
directory. I shall assume that WampServer is installed in "d:\WampServer", denoted as <WAMPSERVER_HOME>, in
this article.
Starting/Stopping WampServer
To start the WampServer, choose "Start WampServer" from the "Start" menu; or run "wampmanager.exe" from the
WampServer installed directory.
An little icon will appear on the icon tray. "Green" indicates that all the services have started; while "Red" indicates
that 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.
http://www.ntu.edu.sg/home/ehchua/programming/webprogramming/AMP_Setup.html
2/16
6/24/2015
HowtoSetUpApache/MySQL/PHPforLinux(LAMP),Windows(WAMP)andMac(MAMP)
To run this script, start a browser and issue URL http://localhost/hello.php, assuming that the Apache server
has been started.
Another Example : Write another PHP script called "phpinfo.php" saved under "www" to display the PHP
settings under Apache, as follows:
<?php
phpinfo();
?>
3/16
6/24/2015
HowtoSetUpApache/MySQL/PHPforLinux(LAMP),Windows(WAMP)andMac(MAMP)
bin : contains binaries for Apache, MySQL, and PHP, in their respectively subdirectory. For each component, you
can install multiple versions and select one of them in operation.
apps : contains serverside tools such as PhpMyAdmin, SQL Buddy, and WebGrind.
tools : contains clientside 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
"
The ServerRoot specifies the apache's installed directory. Listen specifies the TCP port number for Apache web
server, 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:
#
#EachdirectorytowhichApachehasaccesscanbeconfiguredwithrespect
#towhichservicesandfeaturesareallowedand/ordisabledinthat
#directory(anditssubdirectories).
#
#First,weconfigurethe"default"tobeaveryrestrictivesetof
#features.
#
<Directory/>
OptionsFollowSymLinks
AllowOverrideNone
Orderdeny,allow
Denyfromall
</Directory>
#
#ThisshouldbechangedtowhateveryousetDocumentRootto.
#
DocumentRoot"<WAMPSERVER_HOME>/www/"
<Directory"<WAMPSERVER_HOME>/www/">
OptionsIndexesFollowSymLinks
AllowOverrideall
OrderDeny,Allow
Denyfromall
Allowfrom127.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
http://www.ntu.edu.sg/home/ehchua/programming/webprogramming/AMP_Setup.html
4/16
6/24/2015
HowtoSetUpApache/MySQL/PHPforLinux(LAMP),Windows(WAMP)andMac(MAMP)
PHP Configuration
The
PHP's
main
configuration
for
Apache2
"php.ini"
is
located
at
"
MySQL Configuration
The MySQL's main configuration file "my.ini" is located at "<WAMPSERVER_HOME>\bin\mysql\mysql5.x.xx". Take
note of the following settings:
MySQL Server
[wampmysqld]
port=3306
socket=/tmp/mysql.sock
basedir=<WAMPSERVER_HOME>/bin/mysql/mysql5.x.xx
logerror=<WAMPSERVER_HOME>/logs/mysql.log
datadir=<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 the
MySQL installed directory. The datadir specifies the databases directory. The logerror specifies the MySQL
error log file.
MySQL Server Daemon mysqld.exe
[mysqld]
port=3306
Customizing MySQL
The default MySQL installation creates a superuser "root" without password. It also creates an anonymous user 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 wampuser
for operational use.
There are many ways to administer MySQL, via the graphical client "PhpMyAdmin" or "SQL Buddy"; or commandline
client "mysql.exe".
PhpMyAdmin: login to PhpMyAdmin via "http://localhost/phpmyadmin". Click the "Users" tab Set
password for root for all hosts Select Edit Privilege Change Password GO Refresh. Delete the
anonymous 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 with
the 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
http://www.ntu.edu.sg/home/ehchua/programming/webprogramming/AMP_Setup.html
5/16
6/24/2015
HowtoSetUpApache/MySQL/PHPforLinux(LAMP),Windows(WAMP)andMac(MAMP)
User". Grant all privileges except the "Grant option" to begin with.
MySQL commandline client "mysql.exe": Read "How to setup MySQL".
2. Install: Simply run the downloaded Installer. Choose your installation directory. I shall assume that XAMPP is
installed in "d:\xampp", denoted as <XAMPP_HOME>, in this article.
2. Install: Simply run the downloaded Installer. Choose your installation directory. I shall assume that XAMPP is
installed in "......", denoted as <XAMPP_HOME>, in this article.
6/16
6/24/2015
HowtoSetUpApache/MySQL/PHPforLinux(LAMP),Windows(WAMP)andMac(MAMP)
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 also
click the "Admin" button under MySQL to launch PhpMyAdmin.
To shutdown XAMPP, stop all the services and press "Quit".
To run this PHP script, start a browser and issue URL http://localhost/hello.php, assuming that Apache server
has been started.
Another Example : Write another PHP script called "phpinfo.php" saved under "htdocs" to display the PHP
settings under Apache, as follows:
<?php
phpinfo();
?>
The ServerRoot specifies the apache's installed directory. Listen specifies the TCP port number for Apache web
server, in this case, default of TCP port 80. The DocumentRoot specifies the root directory of the web server.
http://www.ntu.edu.sg/home/ehchua/programming/webprogramming/AMP_Setup.html
7/16
6/24/2015
HowtoSetUpApache/MySQL/PHPforLinux(LAMP),Windows(WAMP)andMac(MAMP)
#
#DocumentRoot:Thedirectoryoutofwhichyouwillserveyour
#documents.Bydefault,allrequestsaretakenfromthisdirectory,but
#symboliclinksandaliasesmaybeusedtopointtootherlocations.
#
DocumentRoot"<XAMPP_HOME>/htdocs"
<Directory"<XAMPP_HOME>/htdocs">
OptionsIndexesFollowSymLinksIncludesExecCGI
AllowOverrideAll
#
#Controlswhocangetstufffromthisserver.
#
Requireallgranted
</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 following
settings:
MySQL Server Daemon mysqld.exe
[mysqld]
port=3306
socket="<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 the
MySQL installed directory. The datadir specifies the databases directory. The logerror specifies the MySQL
error log file.
http://www.ntu.edu.sg/home/ehchua/programming/webprogramming/AMP_Setup.html
8/16
6/24/2015
HowtoSetUpApache/MySQL/PHPforLinux(LAMP),Windows(WAMP)andMac(MAMP)
Customizing MySQL
The default MySQL installation creates a superuser called "root" without password. It also provides an anonymous
user 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 commandline client "mysql".
PhpMyAdmin: login to PhpMyAdmin via "http://localhost/phpmyadmin". Click the "Users" tab Set
password for root for all hosts Select Edit Privilege Change Password GO Refresh. Delete the
anonymous 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 with
the new password. See "PhpMyAdmin PHP Configuration".
MySQL commandline client "mysql.exe": Read "How to setup MySQL".
9/16
6/24/2015
HowtoSetUpApache/MySQL/PHPforLinux(LAMP),Windows(WAMP)andMac(MAMP)
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".
"Executable
Path",
enter
the
location
of
PHP
executable
"php.exe"
e.g.,
"
used
by
for
"
"
10/16
6/24/2015
HowtoSetUpApache/MySQL/PHPforLinux(LAMP),Windows(WAMP)andMac(MAMP)
//Constructor
function__construct(){
$this>message="HelloWorld!";
}
/**
*Functionthatprintsthevalueoftheinstancevariable$message
*/
functionprintMessage(){
echo$this>message;
}
}
?>
Again, create a new PHP file for the following driver program "HelloDriver.php":
<?php
include_once('HelloObj.php');
$hello=newhello();
$hello>printMessage();
?>
4. To run the program, rightclick anywhere on "HelloDriver.php" "Run As" "PHP Web Application"
output shown in Eclipse internal browser or external browser
http://localhost/hello/HelloDriver.php.
The
launch
URL
shall
be
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 commandline interface program
instead of serverside script, as the above program are purely PHP, with no HTML statements.
4.PhpMyAdmin
PhpMyAdmin http://www.phpmyadmin.net is a popular open source webbase tool intended to handle the
administration of MySQL database system.
Installing PhpMyAdmin
PhpMyAdmin is bundled in WampServer, installed under "<WAMPSERVER_HOME>\apps\phpmyadmin4.x.xx". It is also
bundled in XAMPP, under "<XAMPP_HOME>\phpmyadmin".
For Ubuntu, read "Install PhpMyAdmin for Ubuntu".
http://www.ntu.edu.sg/home/ehchua/programming/webprogramming/AMP_Setup.html
11/16
6/24/2015
HowtoSetUpApache/MySQL/PHPforLinux(LAMP),Windows(WAMP)andMac(MAMP)
Launching PhpMyAdmin
PhpMyAdmin is an Apache PHP application. Typically, an alias called "phpmyadmin" is defined which maps to its
installed directory.
To launch PhpMyAdmin, start
http://localhost/phpmyadmin.
Apache
and
MySQL
servers.
Then,
start
browser
and
issue
URL
Using PhpMyAdmin
[TODO]
file
"Include
"
"
If you change MySQL root's password, you need to enter the new password into this file, in order to login into
MySQL.
I recommend that you change the authentication type to "cookie", which prompts you to for the login user and
password.
//$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 Errors
Cannot 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/connectionforcontroluserasdefinedinyourconfiguration
failedphpmyadminxa". I encountered this error for XAMPP.
http://www.ntu.edu.sg/home/ehchua/programming/webprogramming/AMP_Setup.html
12/16
6/24/2015
HowtoSetUpApache/MySQL/PHPforLinux(LAMP),Windows(WAMP)andMac(MAMP)
5.SQL Buddy
SQL 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
"
13/16
6/24/2015
HowtoSetUpApache/MySQL/PHPforLinux(LAMP),Windows(WAMP)andMac(MAMP)
......
[xdebug]
xdebug.remote_enable=On
xdebug.remote_port=9000
xdebug.remote_host=127.0.0.1
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, rightclick on "Query.php" Run As PHP Web Application
To debug the PHP webapp:
1. rightclick on "Query.html" Debug As Debug Configuration Select "Debugger" tab Check "Break at
First Line" which sets a breakpoint at the beginning of each file "Debug".
http://www.ntu.edu.sg/home/ehchua/programming/webprogramming/AMP_Setup.html
14/16
6/24/2015
HowtoSetUpApache/MySQL/PHPforLinux(LAMP),Windows(WAMP)andMac(MAMP)
15/16
6/24/2015
HowtoSetUpApache/MySQL/PHPforLinux(LAMP),Windows(WAMP)andMac(MAMP)
Feedback, comments, corrections, and errata can be sent to Chua HockChuan (ehchua@ntu.edu.sg) | HOME
http://www.ntu.edu.sg/home/ehchua/programming/webprogramming/AMP_Setup.html
16/16