In order to work with PHP, we must ensure that the prerequisites necessary for the implementation of programs. In the development context of web applications, a web server with PHP is mandatory. The MAMP software (short for Macintosh, Apache, MySQL and PHP) will launch a local web server on a machine running on the Mac OS X. It is a software for brand users with apple and which contains the following free components: Apache (server daemon), PHP5, MySQL (DBMS, SQLite (DBMS), and PHPMyAdmin SQLiteManage (administration tools BDD).
We will show in this course how to install this software on Mac OS and use it for our first PHP applications.
We’ll be covering the following topics in this tutorial:
Download MAMP Software
MAMP is available for Macintosh equipped with Motorola PowerPC or Intel chip.
After unzipping the Zip archive disk image (.dmg file). It is the installer software.
Just do a “drag and drop” the MAMP folder window and drop it into the Applications directory thereof. That’s it MAMP is installed correctly. We note the MAMP folder (fitted gray logo) in the Applications directory MacOS (shortcut Command + Shift + A).
First start of the software
The launch of MAMP is done by clicking on the icon MAMP.app. A new window launches.
This window allows you to control the web server (Apache) and database server (MySQL) have been launched. The green lights show a good operation. The Preferences tab allows you to configure MAMP.
The modifiable parameters are for example the ports behind which the server processes or the working directory where the projects are located (eg websites).
It is recommended that the configuration imposed by MAMP for people without sufficient computer knowledge.
The startup MAMP also involves opening a new window in the web browser (Safari by default). This is the home page of MAMP. It also attests to the proper functioning of the local Web server.
Note first that to access the local web server, we use the URL http: // localhost: 8888 / MAMP. The localhost can be replaced with the IP address 127.0.0.1. The Web server listens for the LAN information on port 8888. Port 80 is reserved by default to the Web through the Internet.
The menu at the top provides access to phpinfo () (PHP configuration), utilities database management (PHPMyAdmin and SQLiteManager) as well as to a performance optimization PHP application (eAccelerator).
The important directories MAMP
The six important directories of MAMP are:
• / bin: directory containing executable Apache, PHP4, PHP5, MySQL5 and SQLite.
• / conf: directory containing Apache configuration file (httpd.conf), PHP (php.ini) and SQLiteManager (config.db).
• / tmp: directory containing the temporary files created by the executables. The / tmp / php include contains temporary files of PHP sessions.
• / db: directory containing MySQL5 and SQLite databases.
• / logs: directory containing the files of PHP error logs, Apache and MySQL.
• / htdocs: directory containing various website projects.
PHP first test
We will test our first PHP application: the traditional “hello world”. For this, we first create a new directory called PHP-Code in the / htdocs.
Then we put in this directory a file named hello.php that contains the following code:
Listing of hello.php: first PHP program
<title> Hello World PHP </title>
<?php echo 'Hello World!'; ?>
In our browser, we call the file by entering the following URL: http: // localhost: 8888 /PHP-Code/hello.php. The PHP script is executed and displayed on the screen the text Hello World!. So PHP works perfectly.
Database managers: PHPMyAdmin and SQLiteManager
The free utility PHPMyAdmin is located at the following address: http: // localhost: 8888 / phpMyAdmin /. It allows to manage databases and tables MySQL SQL type.
We return to this application when next tutorielss requiring the use of MySQL databases.
The free utility SQLiteManager is located at the following address: http: // localhost: 8888 / SQLiteManager /. It allows to manage databases and SQL tables SQLite.
We will return to this application at upcoming tutorials require the use of SQLite databases.
MAMP also offers a small widget to place in the Dashboard MacOS. This allows to monitor the status of Web servers and SQL; and restart them if necessary.
By clicking on the little exclamation point, it is possible to switch to 1 second PHP5 to PHP4. This is handy when you want to test the compatibility of an application.