30 April 2010
Beginning
This tutorial describes how to set up a development environment on a Windows or a Macintosh computer for building PHP web applications with Adobe Dreamweaver and a MySQL database server.
Setting up a PHP development environment for Dreamweaver requires a web server (such as Apache or IIS), PHP, and a MySQL database. Although you can install all three separately, it's usually much simpler to use an all-in-one solution, such as XAMPP for Windows or MAMP for Mac OS X.
Note: PHP can be used with most database systems. However, Dreamweaver's PHP server behaviors support only MySQL.
This setup tutorial shows you how to complete the following tasks:
PHP pages need to be processed through a web server. So, to develop with PHP in Dreamweaver, you need access to a PHP-enabled web server and the MySQL database. It's also useful to have phpMyAdmin, a graphical interface to MySQL. All three components are open source software that you can use for developing, testing, and deploying web applications–and they are free!
You can install each one independently, but the quickest and easiest way is to use an all-in-one solution. The one chosen for this tutorial is XAMPP. If you already have a working PHP/MySQL environment, or want to use a different all-in-one installer, such as WampServer (http://www.wampserver.com/en/), go straight to Defining a PHP site in Dreamweaver.
If you're a Mac user, see Setting up PHP for Mac OS X.
XAMPP installs the Apache web server, which listens for requests on port 80. This is the default port used by most web servers, including Microsoft Internet Information Services (IIS). Only one web server at a time can listen on port 80.
If you have installed IIS on your computer to develop with ASP or ASP.NET, you must stop the IIS web server before installing XAMPP. Alternatively, you can install PHP in IIS using the Microsoft Web Platform Installer as described in Setting up an ASP development environment for Dreamweaver. However, if you install PHP in IIS, you need to install MySQL and phpMyAdmin separately; see Installing MySQL and phpMyAdmin on Windows (for IIS only) for more details.
Installing and configuring XAMPP is usually quick and trouble-free, but things do sometimes go wrong. If you run into problems, the best place to get help is in the XAMPP forum.
You must be logged into Windows in an administrator account.
After you have set the options, you should see a message telling you that XAMPP is ready. This is followed by a screen with a short menu (see Figure 1). Type 1 and press Enter to start the XAMPP Control Panel. Then type x and press Enter to close the Command Prompt window.
To start the Apache and MySQL servers, launch the XAMPP Control Panel from the Windows Start menu (if it's not already open), and click the Start button alongside Apache and MySQL. Confirmation that they have started successfully is displayed alongside, and the label on the Start buttons changes to Stop (see Figure 2).
Note: If a Windows Security alert pops up asking whether to keep blocking the program mysql or apache, choose Unblock for both programs.
Note the following in case of errors:
If you want to enable Apache or MySQL as Windows services so they start automatically, select the Svc check box alongside each one. (FileZilla and Mercury are FTP and mail programs, which are not required to develop with PHP in Dreamweaver. They are not covered in this article.)
To secure the database:
Note: Even if you are the only person using the computer, it's good practice to password protect the MySQL database.
After installing XAMPP and securing the database, it's a good idea to test the PHP installation:
If PHP has been installed successfully you'll see a page showing detailed information on your PHP setup (see Figure 5).
Although this screen might feel like information overload at this stage, it contains a wealth of information about your PHP setup. Return to this screen whenever you need to check how PHP is configured.
Note: You can display the same information by creating a PHP file containing the following script and loading it into a browser:
<?php phpinfo(); ?>
Follow these steps to verify your MySQL and phpMyAdmin setup:
After successfully logging in, you'll see the main phpMyAdmin screen (see Figure 7).
Congratulations! You now have a working installation of PHP, MySQL, and phpMyAdmin.
The next section covers instaling MySQL and phpMyAdmin separately for use with IIS, so you can skip directly to Defining a PHP site in Dreamweaver CS5 or return to Part 1 of the tutorial series Creating your first dynamic site in Dreamweaver (if that's where you started).
If you are using PHP in IIS, you need tinstall MySQL and phpMyAdmin separately.
Note: These instructions only if you are using IIS as your web server. MySQL and phpMyAdmin are already installed in XAMPP and WampServer.
The next step is tinstall phpMyAdmin, a graphic front end for MySQL. Since phpMyAdmin is PHP based, installation is a straightforward three-step process: download the files, unzip them to the website in your local testing environment, and create a simple configuration file.
The next screen will probably warn you that you didn't set up a phpMyAdmin database, syou won't be able tuse all the phpMyAdmin features. This is not important. You can set up one later if you decide tuse the advanced features of phpMyAdmin.
You now have a PHP development environment. The next page describes how to set up PHP on a Mac, so you can skip it and proceed directly to Defining a PHP site in Dreamweaver CS5.
PHP pages need to be processed through a web server. So, to develop with PHP in Dreamweaver, you need access to a PHP-enabled web server and the MySQL database. It's also useful to have phpMyAdmin, a graphical interface to MySQL. All three components are open source software that you can use for developing, testing, and deploying web applications. What's more, they're free.
The Apache web server and PHP are preinstalled in Mac OS X. However, they're not enabled by default. Moreover, the preinstalled version of PHP lacks a lot of useful features, and you need to install and configure MySQL separately. Unless you're very comfortable working with the command line in Terminal, it's much easier to install the all-in-one solution MAMP.
This section describes how to install MAMP on your Mac. This installs the Apache web server, MySQL, and phpMyAdmin in a single operation.
If you already have working versions of Apache, MySQL, and phpMyAdmin, there is no need to install MAMP. Go straight to Defining a PHP site in Dreamweaver CS5.
Note: You can also purchase a license for a commercial add-on called MAMP PRO. This makes it easier to organize your sites. However, the free version is perfectly adequate for developing PHP pages with Dreamweaver, so MAMP PRO is not covered here.
If you're a Windows user, see Setting up PHP for Windows.
Instead of using the preinstalled versions of Apache and PHP, MAMP installs separate versions in a different location on your hard disk. This makes it easier to uninstall everything by simply dragging the MAMP folder to the trash if you decide you no longer want MAMP on your computer. MAMP also avoids conflicts with the preinstalled version of Apache by using a non-standard port (8888) to listen for requests for web pages.
To make it easier to deploy your PHP pages on the Internet, it's a good idea to configure MAMP to use the standard port for web servers (80). Instructions for how to do this are given later, but you should first check that the preinstalled versions are not running.
As long as MySQL has never been installed on your computer, you're good to go.
Note: Installing MAMP is usually very quick (just a couple of minutes) and trouble-free. However, things do sometimes go wrong. If you run into difficulties, the best place to look for help is in the MAMP forum.
To install MAMP on your Mac:
For the purposes of this article, you need to install only the free version of MAMP. The commercial version is an add-on that you can add later if you want to use its advanced features. To learn more about the commercial version, visit the MAMP PRO website.
To test and configure MAMP:
The numbers change to the standard ports: 80 for Apache and 3306 for MySQL. This will make your development with Dreamweaver easier.
MAMP stops and restarts both servers.
Note: This is the most likely place for something to go wrong. If any other program is using port 80, Apache won't restart. If that happens, check that Web Sharing is not selected in Internet & Sharing in System Preferences. Another possibility is that Skype is using port 80. You can change the port in the Advanced section of Skype Preferences–try 42815 as the incoming port. If you can't find what's preventing Apache from using port 80, open the MAMP preference panel, and click Reset MAMP ports.
You only need the colon followed by a number when you use nonstandard ports.
Congratulations! You have a working installation of PHP, MySQL, and phpMyAdmin. Although this screen might feel like information overload at this stage, it contains a wealth of information about your PHP setup. Return to this screen whenever you need to check details of the way PHP is configured.
Note: You can display the same information by creating a PHP file containing the following script and loading it into a browser:
<?php phpinfo(); ?>
Now that you have a PHP testing environment on your computer, you can proceed to Defining a PHP site in Dreamweaver so you can start developing.
Because PHP files need to be processed by a web server, you need to tell Dreamweaver where the testing server is located. You also need to tell Dreamweaver the correct URL to use when testing your files. The following instructions assume you have established a local testing environment on your computer as described in the preceding sections.
In theory, you can locate your PHP files anywhere on your computer, and Dreamweaver will copy them to the testing server when you use Live view or Preview In Browser. However, this results in two identical copies of every file. Instead it's common practice to store project files in a folder inside the document root of the testing server, which is what you'll do in this tutorial.
The document root is the top-level folder where the server looks for web pages. Its location depends on where and how you installed your PHP testing environment.
Here are the default locations for common PHP setups:
The URL for the document root is http://localhost/.
Note: If you are using the MAMP default ports, use http://localhost:8888/ for the URL.
To specify a working folder:
Note: The folder name should not include any spaces or special characters. You should never use spaces or special characters in folder or file names for a website, because they cause problems on most PHP servers.
That's all you need to do to define a site in Dreamweaver. You don't need to define the remote or testing servers until you want to use them. However, since you're going to test the site right away, leave the Site Setup dialog box open.
To specify a testing server:
Note: If you're using the MAMP default ports, the Web URL should be http://localhost:8888/php_test/.
Now that you have defined the site in Dreamweaver, you can test that everything works.
<body> tags:<p>The time is now <?php echo date('H:i:s'); ?>.</p>
The code between the <?php ?> tags displays the current time.
<p> tags is displayed as normal, but the PHP code is replaced by a gold shield (see Figure 16).
Note that the value in the Address text box now displays the Web URL rather than the physical location of the file.
If the time did not display in Live view, check the following:
The PHP site is now defined and working. The next step is to add the sample files to the test site in preparation for connecting to a database.
If you haven't already done so, download the sample files for this tutorial, unzip them, and copy them to the php_test folder in your server's document root. You should now see the sample files in the Files panel (see Figure 18). You may need to click the Refresh icon at the top of the Files panel to see the files.
MySQL is not a single database, but a database management system. You create individual databases within MySQL. The superuser, root, has complete control over all databases, so it's necessary to set up user accounts with restricted privileges to prevent unauthorized users gaining access to other people's data.
In this section, you'll use the phpMyAdmin front end to MySQL to create a database, import sample data, and create a MySQL user account. The instructions assume that you have installed XAMPP on Windows, MAMP on a Mac, or that you have created your own PHP testing environment with a web server, PHP, MySQL, and phpMyAdmin.
To perform this task:
If you're using MAMP in Mac OS X, use http://localhost/MAMP/ or http:localhost:8888/MAMP/, and then click the link for phpMyAdmin.
You should see the phpMyAdmin welcome screen (see Figure 19).
Note: The default list of databases shown in the menu on the left of the screen is slightly different in XAMPP and MAMP, but this is not important.
Note: When choosing names for databases and database columns (fields), do not use spaces or hyphens; use only alphanumeric and underscore characters (for example, feedback_demo). Although phpMyAdmin accepts spaces and hyphens, they require special handling and are likely to cause problems. It's also a good idea to use lowercase throughout, because the Windows version of MySQL automatically converts names to lowercase and treats them as case-insensitive. Most PHP sites are hosted on Linux servers, which are case-sensitive. If your names include uppercase characters, everything will break when you upload your web application from Windows to a Linux server.
Note: You can ignore the Collation setting, unless you are using a language other than English. Collation determines the sort order of records. The default setting is fine for English.
The root superuser should be used only for administrative tasks inside phpMyAdmin, because it has the power to wipe out all of your data. After data has been deleted, you cannot restore it! There is no equivalent of the Windows Recycle Bin or Mac Trash in MySQL. So, the next task is to create a MySQL user account with restricted privileges. Follow these steps to create an account that has access only to the php_test database:
Note: Many of the features in phpMyAdmin are context-sensitive. There is a Privileges tab at the top of every screen, but to create a new user account, you must return to the welcome page and click the Privileges tab there.
The next screen confirms that the new user has been added. The Global privileges section gives the user account the same privileges on all databases. For the purposes of this tutorial, you're going to limit the user to the php_test database.
Note: The underscore in the database name is preceded by a backslash. In certain circumstances, the underscore can be used as a wildcard character in MySQL, and the backslash is needed here to ensure that the underscore is treated as a literal character. However, this is an exceptional case. Normally, you should not precede the underscore in database, table, or column names with a backslash.
You now have a MySQL user account ready to access the php_test database. In the next section, you'll learn how to create a MySQL connection in Dreamweaver.
The sample files contain include comments.php, which queries the php_test database and displays the results. Dynamic text objects in the Customer Comments section in the center of the page (see Figure 22) indicate where the results will be shown. Before you can view the results, you need to create a connection to the database.
The MySQL Connection dialog box appears.
If you are using the MAMP default ports on a Mac, use localhost:8889.
Note: You don't need to precede the underscore with a backslash here. It was inserted by phpMyAdmin in the previous section (see Figure 20) only because phpMyAdmin uses a query that permits wildcard characters.
Dreamweaver attempts to connect to the database. If the connection fails, do the following:
Congratulations! Your PHP development environment and site are now set up and you are ready to start developing PHP web applications in Dreamweaver.
This tutorial has shown you how to set up a PHP development environment, define a PHP site, and connect to a MySQL database. Defining the site and testing server, and establishing a MySQL connection are fundamental to developing PHP web applications in Dreamweaver. You are now set to start developing dynamic websites with PHP in Dreamweaver.
For more articles and tutorials on developing for PHP using Dreamweaver, visit the Web application development page in the Dreamweaver Developer Center.

This work is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 Unported License
Tutorials and samples |
| 04/23/2012 | Resolution/Compatibility/liquid layout |
|---|---|
| 04/20/2012 | using local/testing server with cs5 inserting images look fine in the split screen but do not show |
| 04/18/2012 | Ap Div help |
| 04/23/2012 | Updating |