Announcement

Collapse
No announcement yet.

mod_pagespeed and php selector

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • mod_pagespeed and php selector

    I've installed mod_pagespeed from easyapache4. I followed these instructions https://support.cpanel.net/hc/en-us/...ividual-domain to enable mod_pagespeed for specific accounts only.

    I'm using cloudlinux php selector to set php version.

    mod_pagespeed is working for html such as index.html, css, and js files served by apache.

    However, mod_pagespeed is not working for php pages served by cloudlinux php_selector such as index.php

    Is there a way to get mod_pagespeed to work with php pages with php_selector secure php version?


  • #2
    We tried reproducing the issue on our lab servers and seems the issue is not related to PHP packages, and is not related to the CageFS enabled/disabled. We were not able to make the individual mod_pagespeed working for any domain if it is disabled globally even with native PHP. Can you please confirm it's working with PHP when enabled globally? Do you use mod_lsapi as PHP engine?

    Comment


    • #3
      Thanks very much for taking a look.

      Yes, mod_pagespeed is working with PHP when enabled globally.

      I'm running php as fcgi, php selector with php 7.3/7.4, and cagefs enabled.

      With /etc/apache2/conf.modules.d/510_pagespeed.conf set to ModPagespeed on, multiple individual css and js files called from index.php are combined into an optimized css / optimized js file and the html lines in the index.php output then have a call to the mod_pagespeed-combined css and combined js file; mod_pagespeed is altering the html of the php file to optimize and optimizing the called js/css components.The X-modpagespeed header appears when viewing the php file in chrome developer tools -> network -> headers
      (sub-note: ModPageSpeedEnableFilters rewrite_css, ModPageSpeedEnableFilters rewrite_javascript, ModPageSpeedEnableFilters combine_css, ModPageSpeedEnableFilters combine_javascript work when enabled in .htaccess for a single site for php files with mod_pagespeed enabled globally, but ModPageSpeedEnableFilters remove_comments and ModPageSpeedEnableFilters collapse_whitespace only work for php files when enabled in global 510_pagespeed.conf; these latter two work for html files when enabled in .htaccess.)

      With ​ModPagespeed off in the /etc/apache2/conf.modules.d/510_pagespeed.conf and ModPagespeed on in /home/site/www/.htaccess, the html source of index.php is not altered to combine multiple css / js files.
      (sub-note: testing was inconsistent in the following regard: the html within a php file was never optimized with mod_pagespeed disabled globally and enabled with .htaccess, and multiple css/js files were not combined, but in some tests the js and css files called by the index.php file were optimized rewritten by mod_pagespeed; In other tests it was necessary to add text/css and text/javascript to the AddOutputFilterByType MOD_PAGESPEED_OUTPUT_FILTER text/html in 510_pagespeed.conf and it required several reloads; I'm not clear why it optimized the called js and css files in some tests without those added and in other tests not until text/javascript and text/css were added; with it enabled globally it optimizes and combines the called files without having to add the additional types to the OUTPUT_FILTER line.)

      mod_pagespeed is interesting as it gives the mobile lighthouse score a noticeable improvement on some sites where scripts are complicated and have lots of individual css/js calls/comments, etc.,

      But it would be great if it were possible to enable it on a per-account basis as I don't want to risk introducing glitches to all accounts unless the site could benefit in a noticeable way. (and much easier to enable on an account-by-account basis to give time to spot any possible glitches it could introduce)

      I'm also not sure if mod_pagespeed would introduce security concerns the way it caches all sites in a cache directory outside of cagefs... (?)


      Easyapache settings:
      Code:
      {
      "name" : "mod_pagespeed enabled",
      "pkgs" : [
      "ea-apache24",
      "ea-apache24-config",
      "ea-apache24-config-runtime",
      "ea-apache24-mod_bwlimited",
      "ea-apache24-mod_cgid",
      "ea-apache24-mod_deflate",
      "ea-apache24-mod_expires",
      "ea-apache24-mod_headers",
      "ea-apache24-mod_hostinglimits",
      "ea-apache24-mod_http2",
      "ea-apache24-mod_mpm_event",
      "ea-apache24-mod_pagespeed",
      "ea-apache24-mod_proxy",
      "ea-apache24-mod_proxy_fcgi",
      "ea-apache24-mod_proxy_http",
      "ea-apache24-mod_proxy_wstunnel",
      "ea-apache24-mod_security2",
      "ea-apache24-mod_ssl",
      "ea-apache24-mod_suexec",
      "ea-apache24-mod_unique_id",
      "ea-apache24-mod_version",
      "ea-apache24-tools",
      "ea-apr",
      "ea-apr-util",
      "ea-brotli",
      "ea-cpanel-tools",
      "ea-documentroot",
      "ea-freetds",
      "ea-freetds-libs",
      "ea-libargon2",
      "ea-libcurl",
      "ea-libicu",
      "ea-libmcrypt",
      "ea-libnghttp2",
      "ea-libtidy",
      "ea-libxml2",
      "ea-libzip",
      "ea-modsec-sdbm-util",
      "ea-nghttp2",
      "ea-oniguruma",
      "ea-oniguruma-devel",
      "ea-php-cli",
      "ea-php-cli-lsphp",
      "ea-php83",
      "ea-php83-pear",
      "ea-php83-php-bcmath",
      "ea-php83-php-bz2",
      "ea-php83-php-cli",
      "ea-php83-php-common",
      "ea-php83-php-curl",
      "ea-php83-php-dba",
      "ea-php83-php-devel",
      "ea-php83-php-enchant",
      "ea-php83-php-exif",
      "ea-php83-php-fileinfo",
      "ea-php83-php-ftp",
      "ea-php83-php-gd",
      "ea-php83-php-gettext",
      "ea-php83-php-gmp",
      "ea-php83-php-iconv",
      "ea-php83-php-ldap",
      "ea-php83-php-litespeed",
      "ea-php83-php-mbstring",
      "ea-php83-php-odbc",
      "ea-php83-php-pdo",
      "ea-php83-php-pgsql",
      "ea-php83-php-posix",
      "ea-php83-php-process",
      "ea-php83-php-pspell",
      "ea-php83-php-snmp",
      "ea-php83-php-soap",
      "ea-php83-php-sockets",
      "ea-php83-php-tidy",
      "ea-php83-php-xml",
      "ea-php83-runtime",
      "ea-profiles-cloudlinux",
      "ea-profiles-cpanel"
      ],
      "tags" : [],
      "version" : "0.1",
      "desc" : "pagespeed on for individual sites"
      }​

      Comment


      • #4
        We've done some more tests and have some doubts the article provided is correct, we were not able to get the "X-Mod-Pagespeed" header when pagespeed is disabled globally, but enabled for single domain over .htaccess . However, the testdomain/mod_pagespeed_statistics is working and showing some hits (you would have to allow your desktop IP in /etc/apache2/conf.modules.d/510_pagespeed.conf to be able to see them). How were you testing it?

        Comment


        • #5
          After reading a couple of discussions on disabling it globally I have a strong feeling they cover rewritten options from .htaccess in a different way other than VirtualHost. And they always recommend omitting the .htaccess and do all with apache config file. Most likely the header is just not being added while pagespeed seems to be working in our case.

          Some old but interesting read:
          This is related to Issue 809, but is not the same. This is a thought experiment and I haven't verified this is really a problem. But I'm pretty sure there are two situations where .pagespeed. resou...

          When modpagespeed is set to off in the global config and only enabled for some virtual domains, purging will not work. To duplicate... set ModPagespeed off in the global config set ModPagespeed on ...



          And the workaround is to use custom includes per VirtualHost with https://docs.cpanel.net/ea4/apache/m...include-files/ guide. Having mod_Pagespeed disabled globally I created /etc/apache2/conf.d/userdata/std/2_4/bogdan4/bogdan4.com/pagespeed_customconf with just:

          Code:
          <IfModule pagespeed_module>
          ModPagespeed on
          </IfModule>


          Followed by /usr/local/cpanel/scripts/rebuildhttpdconf and /usr/local/cpanel/scripts/restartsrv_httpd I see the headers again now.

          Comment


          • #6
            Thank you very, very much for testing this. And I am sorry for my slow reply. Oddly, my testing results got less consistent.

            On the first day, I enabled the pagespeed module in easyapache and then followed the cpanel article on disabling globally and enabling for one site through htaccess. I toggled it a few times from local to global to local to observe and a few times on (and not on) in htaccess and on the first day it seemed consistent; when enabled with htaccess it seemed to be optimizing the js and css files called in the php index file, but not the php source. However on days 2 and 3, with no mod_pagespeed config changes, it stopped consistently optimizing the js and css files. Possibly the mod_pagespeed cache is/was coming into play here showing me things that were not actually occurring.

            I will give the workaround a try now. Thank you very much!

            Comment

            Working...
            X