Setting up Mac OS X Web Server and PHP
As of WebDesign 2.5 you can not only have side by side web page previews, you can also preview both client side scripts such as javascript, as well as server side scripts such as PHP or CGI on Mac OS X 10.2. To do this, you have to set up personal web sharing as well as install PHP. Fortunately, this is very easy to do, and PHP is installed by default in Mac OS X 10.3 or later, it just has to be enabled.
To use Personal Web Sharing do the following;
- Make sure you have a working network connection.
- Open System Preferences and select the Sharing preference pane. Turn on Web Sharing by clicking the start button. Note the IP Address that appears under Network Identity in the preferences pane. (Be sure to copy the address exactly as it appears. If you see two addresses, you can use either one.)
- Go back to WebDesign and select 'Open Web Site' from the File menu. Your web site will be listed in WebDesign's Site Manager. Then use the 'Move to Sites Folder' button in the Site Manager to move the entire web site to your Sites Folder located in your home directory. If it is already in your Sites Folder the button will be disabled and you can go on to the next step.
- Your new websites URL is: http://yourIPAddress/~yourshortusername/. Youll find your short user name by opening System Preferences and selecting the Users Preference pane. Click on your name and then click on Edit User. For example, if your IP address is 127.0.0.1 and your user name is steve, your web site will be accessible by typing http://127.0.0.1/~steve/ into your web browser.
- Give this address to the people on your intranet (make sure they dont forget that last /). They can connect to your server and view your published documents by typing this address in their web browser.
Now that you have successfully set up your Personal File Sharing, you can now enable PHP so that you will be able to preview PHP code locally. To do this you must do the following;
- Launch the Terminal. You can do this by in WebDesign by selecting Open Terminal from Text->Terminal menu.
- Type 'sudo pico /etc/httpd/httpd.conf' into the terminal to edit your Apache configuration file. It will be opened in a text editor within your terminal. You will need to enter your Admin password.
- Press Control-W to search the configuration file and type 'php' and hit enter. You should be taken to line that starts with #LoadModule php4_module. You must uncomment this line by removing the # sign at the beginning of the line. To do this, use the arrow keys to navigate to the 'L' and press the delete key.
- Press Control-W again to search the document for '#AddModule mod_php4.c'. Uncomment this line again by removing the # sign. If you are using Mac OS X 10.3 you can skip to the last step, otherwise, you must add a few lines to this document in OS X 10.2.
- If you want to be able to load index.php as the default page when your personal web sharing URL is entered in a web browser, you must add index.php to the default document list. To do this, press control-W again and enter 'DirectoryIndex'. If index.php is already there, you do not have to do anything else. Otherwise, go to the end of the line type a space followed by index.php. The whole line should look like this 'DirectoryIndex index.html index.php'.
- Now scroll down to the bottom of the file, and just before the Include /private/etc/httpd/users statement insert the following lines:
<IfModule mod_php4.c>
AddType application/x-httpd-php .php
AddType application/x-httpd-php .php4
AddType application/x-httpd-php-source .phps
</IfModule>
- Lastly, save the document by pressing Control-O and quit pico by pressing Control-X. Finally, restart Apache by typing 'sudo /System/Library/StartupItems/Apache/Apache restart' into the terminal or by turning Personal web sharing off then on again in the System Preferences. You can now place PHP files within your Sites folder and view them in your browser using http://yourIPAddress/~yourshortusername/.