HTML Styling for Developer Code
Note: If you were running apache2 on Snow Leopard (Mac OS X 10.6.x) and then upgraded to Lion, there are some issues that need to be corrected. See separate instructions for Re-enabling apache2 on Lion upgrade from Snow Leopard
Legend:
Placeholder for your terminal (shell cmd) prompt – you do not type this in…
>
After a command line prompt, this is what you would actually type…
commandlineinput
Within a command line, values that you would have to substitute from your own specific environment…
putyourvaluehere
Example command line input…
>
sudo mycommand -r
somecustominput
| grep coolwhatever
Icons courtesy of function
Setting up the httpd.conf and php.ini file to enable php on your local Mac
- Open the “Terminal” application from your Applications folder, or your dock (or where ever) to begin a “shell” environment.
- Make a backup copy of your httpd.conffileNavigate to the file’s location
At the shell’s prompt >, type
> cd /private/etc/apache2
To make a backup copy of the httpd.conf file, enter the command…
> sudo cp httpd.conf httpd.conf_bu_YYYYMMDD
Where
YYYY is the year,
MM is the month,
DD is the day of the month (just a suggested naming convention). - Edit the httpd.conf file to enable php scripting (vi editor shown but most any editor will work)
To open httpd.conf in the vi editor, enter the following command in Terminal…
> sudo vi httpd.conf
(NOTE: If prompted for your login password, reply as requested.)
Editing the httpd.conf file
- Find the line that enables/disables php scripting
Within vi, search for “libphp5.so” by typing
/libphp5.so and then enter/returnThe / causes vi to enter search mode
The line found should read
#LoadModule php5_module libexec/apache2/libphp5.so
If the line does not begin with a # then PHP is already enabled and you can exit your editor by entering
:q to continue with the next command line. So, skip past the rest of these editor steps.The : causes vi to enter command mode
If the line you found doesn’t match for any other reason, first check your search command and/or search the internet for an answer to why and drop me an email to let me know what you found instead. I appreciate input that makes these instructions more useful. Thanks.
- Delete the # in column 1 of the text
Type the number zero key 0 to position the cursor over column 1
Type a lowercase x once to delete the #
If you make a mistake, type ESC and then :quit! to exit the editor without saving changes by typing :quit! and try again.
The line should now read…
LoadModule php5_module libexec/apache2/libphp5.so
- Exit the editor
Type :wq to save (write) and quit
If it doesn’t let you save, try typing :write!
If that doesn’t work, perhaps you didn’t enter the editor with the sudo command. So, exit without saving by typing :quit! and try again
- Find the line that enables/disables php scripting
- Make a backup copy of your php.ini file
To navigate to the file’s location, at the shell’s prompt >, type
> cd /etc
To make a backup copy of the php.ini file, enter the command…
> sudo cp php.ini php.ini_bu_YYYYMMDD
Where
YYYY is the year,
MM is the month,
DD is the day of the month (just a suggested naming convention). - Edit the php.ini file to enable and set a correct timezone (vi editor shown in this example)
To open php.ini in the vi editor, enter the following command in Terminal…
> sudo vi php.ini
(NOTE: If prompted for your login password, reply as requested.)
Editing the php.ini file
- Find and edit the line that sets the timezone
Within vi, search for “date.timezone” by typing
/date.timezone and then enter/returnThe line found should read
; http://php.net/date.timezone
or it may read
;date.timezone={may blank or set to some existing timezone value}
If the line does not begin with a ; then timezone is already enabled.
If the line does begin with a ; then delete the ; using the vi command x with the cursor on top of the ;
If the line is blank after the = then enter a timezone value by typing the following vi commands
$aAmerica/Central and then ESCThe command $a causes vi to jump to the end of the line then begin “append” mode. Pressing the ESC key ends any append or insert mode.
Ensure that you have a valid timezone value. Many former values are now invalid and obsolete.
If the line has an existing value that needs to be changed, then position the cursor over the 1st character after the = then type the following vi commands
DaaValidCountry/aValidTimeZone and then ESCThe command Da causes vi to delete the rest of the line and enter append mode. Note: the case of the letters used as vi commands is significant.
- Find and edit the line that sets the maximum size of file uploads to 8 Megabytes
Within vi, search for “upload_max_filesize” by typing
/upload_max_filesize and then enter/returnThe line found should read:
upload_max_filesize = 4M
Position the cursor over the 4 then replace it with an 8 by typing the vi commands
r8The line should now read:
upload_max_filesize = 8M
Other values can be set but it would be good to learn more about how to use vi if you wish to do so. Search google for “learn vi editor” or for “vi cheat sheet” or see a example vi cheat sheet
- Exit the editor
Type :wq to save (write) and quit
If it doesn’t let you save, try typing :write!
If that doesn’t work, perhaps you didn’t enter the editor with the sudo command. So, exit without saving by typing :quit! and try again.
- Find and edit the line that sets the timezone
- Restart (or start) the apache web serverTo restart the localhost web server (example shown here for doing so from a Terminal command line) type the following:
> sudo apachectl -k restart
The localhost web server may also be restarted (started) from the System Preferences‘ “Sharing” pane by setting/toggling the “Web Sharing” checkbox.
