Configuring for a remote Web Server
Although the PhpED web server is great for testing simple scripts, it has limitations and is unlikely that you would ever use it to service your PHP scripts. Instead you would more than likely use Apache or some other web server. However, just because you are going to use a remote web server doesn't mean that you won't want to debug your scripts from time to time. Fortunately PhpED has made it possible to debug script running a on remote web server. In order to do this it is necessary to modify the /etc/php.ini file to include debug modules and define which IP addresses to grant access.
Make sure the extension_dir points to the PHP extensions directory. On SUSE this is done by default.
extension_dir = /usr/lib/php/extensions
Copy the correct debugger module for the Linux platform and PHP version from the phped/debugger subdirectory to /usr/lib/php/extensions. Rename the module to dbg.so as you copy it.
cp phpded/debugger/dbg.so-4.3.4 /usr/lib/php/extensions/dbg.so
Append the following lines to the /etc/php.ini file and substitute any addresses for the correct IP address of the system you will use to debug with.
extension=dbg.so
[debugger]
debugger.enabled=on
debugger.profiler_enabled=on
debugger.hosts_allow=localhost 137.65.137.126
debugger.hosts_deny=ALL
debugger.ports=7869, 10000/16
Restart your web server, if you are using Apache that can be done by the following command:
/etc/init.d/apache restart
Open a web browser and browse to
http://localhost/misc/test.php. You know that debugger is working if you see
DBG v2.16.14, (C) 2000,2004, by Dmitri Dmitrienko added to the Powered by Zend frame.
Right click on the project1 icon in the left window pane and select properties. In the mapping section change the Run mode from
System default to HTTP mode (3rd party WEB server), enter
We'll Have More Soon for the Root URL, and
/srv/www/htdocs/misc for the Remote root directory. Click on the mapping tab at the top of this dialog and notice that remote directory is mapped to the local directory. Click OK to close the window.
Copy the projects/project1/sample1.php to /srv/www/htdocs/misc directory, or to get a little more exposure to some of the PHP API enter the following example. This example basically does the same thing as the previous example except that it allows you to upload a comma delimited text file which is then used to populate the database instead of entering records one at a time.
<HTML><BODY><?php $db = mysql_connect("localhost", "root", ""); mysql_select_db("test", $db); if(isset($_REQUEST['Submit'])) { if (is_uploaded_file($_FILES['uploadedfile']['tmp_name'])) { $handle = fopen($_FILES['uploadedfile']['tmp_name'], "r"); for($string = fgets($handle, 128); !feof($handle); $string = fgets ($handle, 128)) { list($fname, $lname, $address, $city, $state, $zip, $phone, $email) = explode(",", $string); $sql = "INSERT INTO employees VALUES (0,'$fname','$lname','$address', '$city','$state','$zip','$phone','$email')"; $result = mysql_query($sql, $db); } fclose($handle); unlink($_FILES['uploadedfile']['tmp_name']); } } $result = mysql_query("SELECT * FROM employees ORDER BY lastname", $db); while ($myrow = mysql_fetch_array($result)) { // display list if there are records to display printf("%s %s<BR>%s<BR>%s, %s %s<BR>%s<BR>%s<BR><BR>", $myrow ["firstname"], $myrow["lastname"], $myrow["address"], $myrow["city"], $myrow["state"], $myrow["zipcode"], $myrow["telephone"], $myrow["email"]); } printf("<FORM method='POST' enctype='multipart/form-data' action='%s'>", $_SERVER ["PHP_SELF"]);?> <INPUT type="hidden" name="MAX_FILE_SIZE" value="20000" /> <P> Import a coma delimited file with the following format:<br/> <b>First Name, Last name, Address, City, State, Zip Code, Phone, Email Address</b><br/> </P> File <INPUT type="file" name="uploadedfile" size="20"> <BR/> <BR/> <INPUT type="submit" value="Import File" name="Submit"> <BR/></FORM></BODY></HTML>
Once again put a break point on the line after the if statement and debug the script. Notice that this time the browser is addressing the Apache web server instead of PhpEd's web server (No port 8080 in URL).
Publishing to the Web remote server
Being able to debug on the remote web server is really powerful, but having to copy files from the project directory to the htdocs directory could get old really fast. If your remote web server is on the same system that you are developing on which is often the case for doing development, you might want to point your root directory to the /srv/www/htdocs directory. However, at some point it will be necessary to put your files in the htdocs directory that can be seen by the rest of the world. PhpEd allows you to create either a Web DAV or FTP account for the server you wish to publish your files to, and then with the click of a button publishes your files to that account.
Enabling the pure FTP server on SUSE
Using Yast select the
Network Services (inetd) from the
Network Services option and enable the
/usr/sbin/pure-ftpd ftp server.
In the PhpED IDE select Tools, then Accounts from the main menu. Right click on
File transfer accounts and select new and then FTP. Enter
localhost for the
Hostname or
IP address,
/ for the
Initial directory,
<your username> for the
Login Name, and
<your password> for
Password, and click OK.
Right click on the project1 icon in the left window pane and select properties. In the publishing section select the
ftp1 account you just created. Enter
/srv/www/htdocs/misc for the
Top publishing directory, and click OK. At this point you can select Project, then Upload from the main menu and upload either an entire project or single file.
Conclusion
SUSE Linux is basically pre-configured to be a great platform for developing PHP scripts, and as was seen by the steps in this article setup of Apache, PHP and MySQL was extremely simple, basically starting a few services. With what you have learned from this article you have everything you need to get started developing PHP scripts on the SUSE Linux line of products. In addition, I have also introduced you to a third-party product, NuSphere's PhpEd, that can greatly simplify the development and debugging of PHP scripts.