Php newb help

Discussion in 'Web Design and Development' started by macmanmatty, May 12, 2007.

  1. macmanmatty macrumors regular

    Jul 10, 2005
    I have recently installed php on my mac and Have few hopefully simple questions about making it work. When I embed php into an html file it only works if the extension is .php and not .html is their anyway to configure my web server to parse php in .html files?? or is this not reccomended to do? If ever my site should files containg php code be .php or .html??


  2. SDDave2007 macrumors regular

    Apr 12, 2007
    PHP File Extensions

    PHP files can contain HTML, but HTML files cannot contain PHP. By that I mean a file containing PHP code must end in .PHP or another series of file extensions that are registered with APACHE (httpd.config)
    You might be able to configure YOUR server to use .HTM/.HTML but I would advise against it, as nobody else will support that and you may wish to make your code portable
  3. Aranince macrumors 65816

    Apr 18, 2007
    To be able to run php code in your browser you'll need a web Apache. And you can use normal HTML in a .php file just as you would in .html, but because it is a .php file the web server will recognize that it has php in it and will be sure to run the php code appropriately. There is also .phtml I belive.
  4. Winterfell macrumors regular

    Apr 3, 2007
    Tulsa, Oklahoma
    The main reason this is done is to keep people from knowing that a server is using PHP (or any other scripting language for that matter) by hiding the code in a seemingly static .html file.

    To tell your webserver to parse .html files as PHP, find the relevant line in your Apache configuration file. For the default Apache installation on OSX, it will look something like the following:
    <IfModule mod_php4.c>
        # If php is turned on, we repsect .php and .phps files.
        AddType application/x-httpd-php .php [B][COLOR="Red"].html[/COLOR][/B]
        AddType application/x-httpd-php-source .phps
        # Since most users will want index.php to work we
        # also automatically enable index.php
        <IfModule mod_dir.c>
            DirectoryIndex index.html index.php
    Just add the .html extension (in bold, red above).

    The default Apache configuration file is stored in /etc/httpd/httpd.conf. If you installed Apache yourself, the file names and locations might be different.

    After you make the changes, just restart Apache and you will be in business.

Share This Page