Setting Up A PHP Development Environment For Dreamweaver by Charles Nadeau
Setting Up A PHP Development Environment For Dreamweaver by Charles Nadeau
Dreamweaver Article
Setting up a PHP development environment for Dreamweaver
Charles Nadeau
Adobe
This article describes how to set up a development environment on a Windows or a Macintosh computer that lets you
build PHP web applications with Adobe® Dreamweaver® and a MySQL database server.
Setting up a development environment for Dreamweaver is a three-part process. First, you set up a PHP application
server. Second, you define a Dreamweaver site. Third, you install and connect to your MySQL database. This article
follows this three-step process.
Requirements
To complete this tutorial you will need to install the following software and files:
Dreamweaver CS3
Try (www.adobe.com/go/devcenter_dw_try/) Buy (www.adobe.com/go/devcenter_dw_buy/)
Note: Adobe does not provide technical support for third-party products such as the MySQL database server.
Sample files:
cafe_php.zip (www.adobe.comhttp://download.macromedia.com/pub/developer/cafe_php.zip) (ZIP, 28K)
To set up a PHP development environment, you must first set up or get access to a PHP application server. An
application server is software that helps a web server process web pages containing server-side scripts or tags. When
such a page is requested by a browser, the web server hands the page off to the application server for processing
before sending the page to the browser.
This section describes how to install PHP 5 on your Windows computer. PHP is open source software that you can
use for developing, testing, and deploying web applications. For more information, see the PHP documentation at
www.php.net/download-docs.php.
If you're a Macintosh user, see Set up a PHP application server (Macintosh)
(www.adobe.comsetting_up_php_03.html) .
This section contains the following topics:
First, you need a web server. PHP installs as an extension to an existing web server, enabling the web server to
process PHP files. Windows XP Professional users can install and run the Microsoft Internet Information Server (IIS)
1 of 15 9/21/08 2:51 PM
Adobe - Developer Center : Setting up a PHP development environ... http://www.adobe.com/devnet/dreamweaver/articles/setting_up_php...
1. Select Start > Settings > Control Panel > Add or Remove Programs, or Start > Control Panel > Add or Remove
Programs.
2. Select Add/Remove Windows Components.
3. Select Internet Information Services (IIS) and click Next.
4. Follow the installation instructions and then test the server as described next.
1. In Dreamweaver or any text editor, create a plain text file called myTestFile.html and enter the following line in
the HTML code:
If the browser displays your page and the word "working" is in italics, the web server is running normally. If the page
doesn't open as expected, make sure the URL does not contain any errors.
1. If applicable, log into your Windows system using the Administrator account.
2. In Windows Vista, you must temporarily turn off User Account Control (UAC) before installing PHP or the files
will end up in the wrong folder. See this document on the Microsoft site.
3. Download the Windows PHP 5.x installer from the PHP website at www.php.net/downloads.php.
The correct download link is "PHP 5.x.x installer" under Windows Binaries.
4. Double-click the installer file you downloaded and follow the onscreen installation instructions.
5. At the Choose Items To Install screen, click the Plus (+) button next to Extensions, locate MySQL in the list, and
then select the Will Be Installed On Local Hard Drive option.
Many developers use a MySQL database server to build their PHP applications. With PHP 5, however, the
MySQL extension that allows PHP to work with a MySQL database server is not installed or enabled by default
by the Windows installer.
6. In the PHP installation folder (likely C:\Program Files\PHP), locate the file called php.ini and open it in
Notepad.
You must edit this file to enable the MySQL extension.
2 of 15 9/21/08 2:51 PM
Adobe - Developer Center : Setting up a PHP development environ... http://www.adobe.com/devnet/dreamweaver/articles/setting_up_php...
;extension=php_mysql.dll
The semicolon (;) at the start of the line tells PHP to ignore the line.
8. Delete the semicolon at the start of the line to enable the extension.
extension=php_mysql.dll
You can also restart IIS by selecting Start > Control Panel > Administrative Tools, and then double-clicking the Internet
Information Services icon to open the IIS console. In the directory tree in the console's left pane, select your default
web site and then select Actions > Stop. After a few moments, select Actions > Start.
After installing PHP, test the server as described next.
1. In Dreamweaver or any text editor, create a plain text file and name it timetest.php.
2. In the file, enter the following code:
This code displays the time when the page was processed on the server.
http://localhost/timetest.php
The test page should open and display the time of day. The specified time is known as dynamic content because it
changes every time you request the page. Click your browser's Refresh button to generate a new page with a different
time.
If the page doesn't work as expected, check for the following possible errors:
3 of 15 9/21/08 2:51 PM
Adobe - Developer Center : Setting up a PHP development environ... http://www.adobe.com/devnet/dreamweaver/articles/setting_up_php...
http://localhost/timetest.php) in the browser's address text box. If you type a file path in the browser
(as you might be used to doing with normal HTML pages), you bypass the web server and the application server.
As a result, your page never gets processed by the server.
The URL contains a typing mistake. Check for errors and make sure the filename is not followed by a slash, such
as http://localhost/timetest.php/.
The page code contains a typing mistake.
After successfully installing and testing the server software, create a root folder for your web application as described
in the next section.
You should create a root folder to store all the files of your web application. If IIS is running on your computer, a good
place to create the folder is in the Inetpub/wwwroot/ folder, as in the following example:
C:\Inetpub\wwwroot\MyWebApp
The IIS web server will serve any page in the wwwroot folder or in any of its subfolders in response to an HTTP
request from a web browser.
To set up a PHP development environment, you must first set up or get access to a PHP application server. An
application server is software that helps a web server process web pages containing server-side scripts or tags. When
such a page is requested by a browser, the web server hands the page off to the application server for processing
before sending the page to the browser.
This section describes how to install PHP 5 on your Macintosh computer. PHP is open source software that you can
use for developing, testing, and deploying web applications. For more information, see the PHP documentation at
www.php.net/download-docs.php.
If you're a Windows user, see Set up a PHP application server (Windows) (www.adobe.comsetting_up_php_02.html) .
This section contains the following topics:
First, you need a web server. PHP installs as an extension to an existing web server, enabling the web server to
process PHP files. Mac OS X users can use the Apache web server included with their operating system. This section
describes how to start the web server, and how to make sure it's working properly.
4 of 15 9/21/08 2:51 PM
Adobe - Developer Center : Setting up a PHP development environ... http://www.adobe.com/devnet/dreamweaver/articles/setting_up_php...
/Users/your_user_name/Sites/
http://localhost/~your_user_name/myTestFile.html
Note: Make sure to include the tilde (~) character with your user name.
If the browser displays your page and the word "working" is in italics, the web server is running normally. If the
browser fails to display the page properly, check the URL for errors. Also make sure you prefixed your Macintosh user
name with the tilde character.
1. If applicable, log into your Macintosh system using the Administrator account.
2. Create a folder named webapps in your main user folder, Users/your_user_name/webapps.
3. From the Entropy web site at www.entropy.ch/software/macosx/php/, download the PHP for 5.x for Apache 1.3
package (for example, entropy-php-5.2.0-3.tar.gz) and save it in your webapps folder.
4. On your Macintosh, open Terminal (Applications/Utilities) and change the default folder to webapps by typing
the following line on the command line and pressing Enter:
cd webapps
5. In Terminal, uncompress the gz file by typing gunzip followed by the name of the gz file in your webapps folder.
For example, if you downloaded entropy-php-5.2.0-3.tar.gz, enter the following command and press Enter:
gunzip entropy-php-5.2.0-3.tar.gz
6. In Terminal, open the tar archive that was uncompressed by typing tar xf followed by the name of the tar file.
Example:
tar xf entropy-php-5.2.0-3.tar
5 of 15 9/21/08 2:51 PM
Adobe - Developer Center : Setting up a PHP development environ... http://www.adobe.com/devnet/dreamweaver/articles/setting_up_php...
7. Double-click the installer package entropy-php.mpkg and follow the onscreen instructions.
1. In Dreamweaver or any text editor, create a plain text file and name it timetest.php.
2. In the file, enter the following code:
This code displays the time the page when was processed on the server.
/Users/your_user_name/Sites
The Sites folder is your personal root folder for the Apache web server.
4. In your web browser, enter the following URL and press Return:
http://localhost/~your_user_name/timetest.php
The test page should open and display the time of day. The specified time is known as dynamic content because it
changes every time you request the page. Click your browser's Refresh button to generate a new page with a different
time.
If the page doesn't work as expected, check for the following possible errors:
After successfully installing and testing the server software, create a root folder for your web application as described
in the next section.
6 of 15 9/21/08 2:51 PM
Adobe - Developer Center : Setting up a PHP development environ... http://www.adobe.com/devnet/dreamweaver/articles/setting_up_php...
You should create a root folder to store all the files of your web application. If you're using the Apache web server on
your Macintosh, a good place to create the folder is in the Sites folder, as in the following example:
/Users/your_user_name/Sites/MyWebApp
The Apache web server will serve any page in the Sites folder or in any of its subfolders in response to an HTTP
request from a web browser.
When you define a PHP site in Dreamweaver, you can specify the location of the site files on your hard disk as well as
on a remote server running PHP (for users). You can also specify the method for moving files and folders between the
two locations. However, if you're only interested in setting up a personal development environment, and PHP is
running on your local computer, then you don't need to specify a remote server for your site.
Topics covered in this section:
1. In Dreamweaver, select Site > Manage Sites. In the Manage Sites dialog box, click the New button, and then
select Site.
The Site Definition dialog box appears.
4. Click the folder icon next to the Local Root Folder text box and browse to the root folder you created for your
application in the previous section of this tutorial, Create a root folder for your application
(www.adobe.comsetting_up_php_04.html#local) , (anchor link to the section above) and then click Select.
If you used the suggestion in this tutorial, then the folder is a follows:
Windows - \Inetpub\wwwroot\MyWebApp
Macintosh - /Users/your_user_name/Sites/MyWebApp
5. In the HTTP Address text box, enter the URL you would enter in a web browser to open your web application.
For example, if you followed the folder naming suggestions in this tutorial, then the HTTP address is as follows:
Windows - http://localhost/MyWebApp/
Macintosh - http://localhost/~your_user_name/MyWebApp/
Note: On the Macintosh, make sure to include the tilde (~) before your user name.
Leave the Site Definition dialog box open. You will specify your testing server next.
7 of 15 9/21/08 2:51 PM
Adobe - Developer Center : Setting up a PHP development environ... http://www.adobe.com/devnet/dreamweaver/articles/setting_up_php...
In this section, you specify a testing server that Dreamweaver can use at design time. Because Dreamweaver does
not have an internal PHP server, it needs to use an external PHP server to generate and display dynamic content in
Design view and to connect to databases while you work.
1. In the advanced Site Definition dialog box, click Testing Server in the Category list.
The Testing Server screen appears.
4. In the URL Prefix text box, enter the URL you would enter in a web browser to request a page in your web
application.
To display live data in your pages while you work, Dreamweaver creates a temporary file, copies it to the
designated folder on the server, and attempts to request it using the URL prefix.
Dreamweaver makes a best guess at the URL prefix based on the information you provided in the Site
Definition dialog box. However, the suggested URL prefix may be incorrect. Correct or enter a new URL prefix if
the suggestion in Dreamweaver is incorrect.
For example, if you followed the folder naming suggestions in this tutorial, then the correct URL prefix is as
follows:
Windows - http://localhost/MyWebApp/
Macintosh - http://localhost/~your_user_name/MyWebApp/
The URL prefix should always specify a folder, rather than a particular page on the site. Also, be sure to use the
same capitalization you used when you created the folder.
5. Click OK to define the site and dismiss the Site Definition dialog box, then click Done to dismiss the Manage
Sites dialog box.
You can start developing your own PHP web applications in Dreamweaver. The following section describes how to set
up the sample PHP files included with this article.
If you like, you can copy the sample files included with this article to the working folder on your hard disk. Copying the
sample files and connecting to the sample database (described in the following sections) also sets up the files for a
follow-up tutorial, Developing a web application (www.adobe.com/go/learn_dw_webapp) , on the Developer Center.
1. Download and unzip the samples file included with this article.
2. Paste the folders and files in the cafe_php folder into the application root folder you specified when defining the
Dreamweaver site. Example:
/MyWebApp/
assets/
data/
send.php
view.php
The Dreamweaver site is now defined and the sample files installed. The next step is to connect to a MySQL
database server.
8 of 15 9/21/08 2:51 PM
Adobe - Developer Center : Setting up a PHP development environ... http://www.adobe.com/devnet/dreamweaver/articles/setting_up_php...
You can use a MySQL database server running on your computer to develop PHP applications in Dreamweaver. This
section describes how to install the MySQL Community Server 5.0 on your Windows or Macintosh computer. MySQL
is open source software that you can use for developing and testing web applications. For more information, see the
MySQL documentation at http://dev.mysql.com/doc/refman/5.0/en/index.html.
Topics covered in this section:
This section describes how to download and install the MySQL 5.0 Community Edition database server on your
Windows XP computer.
Note: The instructions in this section apply to the "Windows Essentials" installer for MySQL 5.0 in Windows XP. For
other versions, please see the MySQL documentation for possible differences in the installation procedure.
1. Download the "Windows Essentials (x86)" installer from the Windows Downloads category on the MySQL
download page:
http://dev.mysql.com/downloads/mysql/5.0.html#win32
2. Double-click the MSI file you downloaded and follow the onscreen instructions.
Note: Select Typical Install when prompted.
3. When the setup wizard is done, run the configuration wizard by making sure the Configure the MySQL Server
Now option is selected on the setup wizard's last page and clicking Finish.
Note: If you missed the option in the setup wizard, you can open the configuration wizard by selecting Start >
All Programs > MySQL > MySQL Server 5.x > MySQL Server Instance Config Wizard.
4. In the MySQL Server Instance Configuration Wizard, make the following choices:
6. Start the MySQL Command Line Client by selecting Start > All Programs > MySQL > MySQL Server 5.x >
MySQL Command Line Client.
9 of 15 9/21/08 2:51 PM
Adobe - Developer Center : Setting up a PHP development environ... http://www.adobe.com/devnet/dreamweaver/articles/setting_up_php...
7. Enter your password (if any) at the command line, and then press Enter.
The MySQL client's command prompt appears, as follows:
mysql>
8. To verify that MySQL is running, enter the following line at the MySQL command prompt:
SHOW DATABASES;
Note: Make sure to include the semi-colon and then press Enter.
If MySQL is working correctly, it should list three databases: information_schema, mysql, and test.
The next step is to create a fourth database in MySQL called CafeTownsend and populate it with sample data.
1. Locate the the SQL script file, tutorial.sql, in the sample files included with this tutorial and copy it in the bin
folder in your MySQL installation folder.
For a normal installation, the bin folder is located at the following path:
C:\Program Files\MySQL\MySQL Server 5.x\bin\
2. If not already done, start the MySQL database server.
To check to see if it's started, select Start > Control Panel > Administrative Tools, then double-click the Services
shortcut. In the Services dialog box, make sure the status of the MySQL item is listed as "Started". If not, select
the item, right-click, and select Start.
3. Start the MySQL Command Line Client by selecting Start > All Programs > MySQL > MySQL Server 5.x >
MySQL Command Line Client.
4. Enter your password (if any), and then press Enter.
The MySQL client's command prompt appears, as follows:
mysql>
5. Create a new database by entering the following command at the MySQL prompt:
Note: Make sure to end the line with a semi-colon and then press Enter.
MySQL creates a new database, but it doesn't contain any tables or records yet.
6. Log out of the MySQL client by entering quit; (with semi-colon) and pressing Enter.
7. Open the Windows command prompt by selecting Start > Run, and typing cmd in the Run dialog box.
8. At the system command prompt, populate the new CafeTownsend database by entering or pasting the
10 of 15 9/21/08 2:51 PM
Adobe - Developer Center : Setting up a PHP development environ... http://www.adobe.com/devnet/dreamweaver/articles/setting_up_php...
cd \
cd Program Files\MySQL\MySQL Server 5.0\bin
mysql -uroot -pPassword CafeTownsend < tutorial.sql
If you specified a username during the MySQL setup, replace root with your username. For example, if your
username is devdude, then enter -udevdude. If you didn't specify a username at setup, you must still enter
-uroot.
Make sure you replace Password with your MySQL password. For example, if your password is Te22y01, then
enter -pTe22y01. If you didn't specify a password, omit the -pPassword item completely.
This command uses the tutorial.sql file to insert tables and records to the CafeTownsend database.
9. To verify that the CafeTownsend database was populated, start the MySQL Command Line Client again (see
step 3) and then enter the following command at the MySQL prompt:
MySQL should list the comments, locations, and region tables as follows:
This section describes how to download and install the MySQL 5.0 Community Edition database server on your
Macintosh.
Note: The instructions in this section apply to the package format (DMG) installer of MySQL 5.0 for the Macintosh. For
other versions, please see the readme file that comes with the installer for possible differences in the installation
procedure.
1. Download an installer package from the "Mac OS X (package format) downloads" category on the MySQL
11 of 15 9/21/08 2:51 PM
Adobe - Developer Center : Setting up a PHP development environ... http://www.adobe.com/devnet/dreamweaver/articles/setting_up_php...
download page:
http://dev.mysql.com/downloads/mysql/5.0.html#macosx-dmg
If your Mac has an Intel processor, select the "Mac OS X 10.4 (x86)" package. Otherwise, select the "Mac OS
X 10.4 (PowerPC, 32-bit)" package.
Double-click the DMG file you downloaded (example, mysql-5.0.41-osx10.4-i686.dmg).
Your computer mounts the disk image and displays the contents, which include the installer file (example,
mysql-5.0.41-osx10.4-i686.pkg).
2. Double-click the installer file (PKG) and follow the onscreen instructions.
If you have an Intel Mac, you may see the following error message in the destination disk selection dialog box:
"You cannot install this software on this disk. (null)." If this error occurs, click the Go Back button once to return
to the previous screen, and then click Continue to advance to the dialog box again. You should now be able to
choose the destination disk.
3. After the installation of the database server is complete, install a button to start and stop the database server by
double-clicking the MySQL.prefPane file in the installation disk image, and then following the onscreen
instructions.
l l ams s i hT
4. On the Macintosh, open Terminal (in Applications > Utilities) and enter the following instructions at the
command line:
cd /usr/local/mysql
sudo ./bin/mysqld_safe
9. Start a new Terminal session and enter or paste the following instruction at the command prompt: /usr/local
/mysql/bin/mysql -uroot
The MySQL command prompt appears:
mysql >
10. To verify that MySQL is running, enter the following line at the MySQL command prompt:
SHOW DATABASES;
Note: Make sure to include the semi-colon and then press Return.
MySQL should list the following databases:
12 of 15 9/21/08 2:51 PM
Adobe - Developer Center : Setting up a PHP development environ... http://www.adobe.com/devnet/dreamweaver/articles/setting_up_php...
The next step is to create a fourth database in MySQL called CafeTownsend and populate it with sample data.
1. Locate the the SQL script file, tutorial.sql, in the sample files included with this tutorial and copy it into the
Documents folder in your home folder.
2. If not already done, start the MySQL database server by selecting Apple > System Preferences, then clicking
the MySQL button under the Other category of preferences. In the dialog box that appears, click the Start
MySQL Server button.
3. Start a new Terminal session and enter or paste the following instruction at the command prompt:
/usr/local/mysql/bin/mysql -uroot
mysql>
4. Create a new database by entering the following instruction at the MySQL prompt:
MySQL creates a new database, but it doesn't contain any tables or records yet.
5. Log out of the MySQL client by entering quit; (with semi-colon) and pressing Return.
6. At the system command prompt, populate the new CafeTownsend database by entering or pasting the
following command:
This command uses the tutorial.sql file to insert tables and records to the CafeTownsend database.
7. To verify that the CafeTownsend database was populated, return to the MySQL command line (see step 3) and
13 of 15 9/21/08 2:51 PM
Adobe - Developer Center : Setting up a PHP development environ... http://www.adobe.com/devnet/dreamweaver/articles/setting_up_php...
MySQL should list the comments, locations, and region tables as follows:
After creating the sample database in MySQL, connect to it in Dreamweaver as described next.
This section describes how to create a connection in Dreamweaver to the sample Cafe Townsend database.
1. In Dreamweaver, open one of the PHP pages in your site, such as view.php or send.php.
2. In the Databases panel (Window > Databases), click the Plus (+) button on the panel and select MySQL
Connection from the pop-up menu.
The MySQL Connection dialog box appears.
7. Click Test.
Dreamweaver attempts to connect to the database. If the connection fails, do the following:
Double-check the server name, user name, and password.
Check the settings for the folder Dreamweaver uses to process dynamic pages (see Specify a testing
server for Dreamweaver)
8. Click OK.
The new connection appears in the Databases panel. Expand the connTownsend connection, and then expand the
14 of 15 9/21/08 2:51 PM
Adobe - Developer Center : Setting up a PHP development environ... http://www.adobe.com/devnet/dreamweaver/articles/setting_up_php...
Tables branch. The three tables in the database should appear, as follows:
For more articles and tutorials on developing for PHP using Dreamweaver, visit the Dreamweaver Developer Center's
web application development page (www.adobe.com/devnet/dreamweaver/application_development.html#php)
(www.adobe.com/devnet/dreamweaver/php.html) .
Charles Nadeau is a documentation manager at Adobe, where he leads the development of end-user content for
Dreamweaver and acts as the Web Suite content architect. He also managed the documentation for Flex Builder 1
and 2, Fireworks 8, and the last few releases of Dreamweaver. Charles started at the company by writing the help for
Dreamweaver UltraDev 1 and 4 as well as numerous articles and tutorials. Charlesʼ interests include web design and
development, motorcycling, and history.
15 of 15 9/21/08 2:51 PM