Results 1 to 7 of 7

Thread: 18.04LTS Apache2 PHP parsing

  1. #1
    Join Date
    Aug 2012
    Beans
    135

    18.04LTS Apache2 PHP parsing

    the following lines added to apache2.conf via IncludeOptional prevent indexing and allow parsing of php in html
    Code:
    Options FollowSymLinks
        AllowOverride None
    </Directory>
    
    <Directory /var/www/>
        Options -Indexes +FollowSymLinks
        AllowOverride None
        Order allow,deny
        Allow from all
    </Directory>
    
    AddType application/x-httpd-php .php .htm .html
    The same code added on a 18.04LTS server prevent indexing but wont parse php in html. It's a long time since I set up the 16.04 Is there a change in 18.04 or am I forgetting something.

    apache2 php


  2. #2
    Join Date
    Nov 2008
    Location
    Metro Boston
    Beans
    15,051
    Distro
    Kubuntu 20.04 Focal Fossa

    Re: 18.04LTS Apache2 PHP parsing

    You might be missing the libapache2-mod-php package. It adds the code to the Apache configuration that tells it to parse rather than display .php files. Does it correctly parse files ending in .php but not ones using .html? Or does it not parse PHP files at all?

    Also, are you using "short tags" (<? versus <?php)? If so, you might have to enable them in /etc/php/[version_number]/apache2/php.ini. Short tags are now disabled by default.
    Code:
    ; short_open_tag
    ; http://php.net/short-open-tag
    short_open_tag = On
    Last edited by SeijiSensei; 1 Week Ago at 02:39 PM.
    If you ask for help, do not abandon your request. Please have the courtesy to check for responses and thank the people who helped you.

    Blog · Linode System Administration Guides · Android Apps for Ubuntu Users

  3. #3
    Join Date
    Aug 2012
    Beans
    135

    Re: 18.04LTS Apache2 PHP parsing

    I didn't install the libapache2-mod-php package initially but I did later after going thru one of the tutorials. It runs php code if the file has a php extension; it ignores it in html files. Im using phpInfo() to test it
    Code:
     phpInfo.html
    <h1>Testing for parseing php code in html files</h1>
    <h3>If you can see results of phpInfo() then all is okay</h3>
    <?php
      phpinfo()
    ?>

  4. #4
    Join Date
    Nov 2008
    Location
    Metro Boston
    Beans
    15,051
    Distro
    Kubuntu 20.04 Focal Fossa

    Re: 18.04LTS Apache2 PHP parsing

    https://stackoverflow.com/questions/...tml-html-files

    You can try using AddHandler rather than AddType.

    Code:
    AddHandler application/x-httpd-php .html
    I haven't done this in years. Is there a strong reason why you don't simply use .php as the file extension?
    If you ask for help, do not abandon your request. Please have the courtesy to check for responses and thank the people who helped you.

    Blog · Linode System Administration Guides · Android Apps for Ubuntu Users

  5. #5
    Join Date
    Aug 2012
    Beans
    135

    Re: 18.04LTS Apache2 PHP parsing

    I added the handler; still not parsing. I'll try researching some more tutorials to see if can find anything and come back later.
    I have done that before but I find it easier to design and maintain if I keep the html and php in separate files and embed the php where I need it.
    Thanks
    Frank

  6. #6
    Join Date
    Nov 2008
    Location
    Metro Boston
    Beans
    15,051
    Distro
    Kubuntu 20.04 Focal Fossa

    Re: 18.04LTS Apache2 PHP parsing

    I separate code from content as well. On any website I build, I have an include/handlers and an include/content directory that are run via include() commands. The handlers directory consists of scripts that run before the page is displayed, for instance, to handle POST or GET requests. The handler can choose among a variety of pages in the content directory to display based on the handler's results.

    The content pages often contain PHP code as well, for instance, pages that iterate over records retrieved from a database.
    If you ask for help, do not abandon your request. Please have the courtesy to check for responses and thank the people who helped you.

    Blog · Linode System Administration Guides · Android Apps for Ubuntu Users

  7. #7
    Join Date
    Aug 2012
    Beans
    135

    Re: 18.04LTS Apache2 PHP parsing

    I'm doing roughly the same as you - using 'include' or 'require' in the html files to process the PHP

    Anyway - problem solved


    The line endings in my conf file had been set to windows; set back to Unix and everything works
    Thanks
    Frank

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •