Pagespeed not running for PHP pages, only html

342 views
Skip to first unread message

cr...@thinkoptimised.com

unread,
Sep 29, 2016, 6:14:36 AM9/29/16
to mod-pagespeed-discuss

Just setup a new server and have installed mod_pagespeed.

It only seems to be working on html pages, not PHP. Below are the headers for two simple pages and apart from the Vary: Accept-Encoding I can't see any differences. Can anyone help me to get this working?

Below is a php page where you can see pagespeed is not working

HTTP/1.1 200 OK
Date: Thu, 29 Sep 2016 09:20:35 GMT
Content-Type: text/html;charset=UTF-8
Connection: keep-alive
Set-Cookie: __cfduid=d160aaa9e45a863e3a570263393bd44d41475140835; expires=Fri, 29-Sep-17 09:20:35 GMT; path=/; domain=.thinkoptimised.com; HttpOnly
Set-Cookie: grav-site-40d1b2d=eo47rrkp2bv5vo91fn8gjjqbs0; expires=Thu, 29-Sep-2016 09:50:35 GMT; Max-Age=1800; path=/; domain=www.thinkoptimised.com
Expires: Thu, 06 Oct 2016 09:20:35 GMT
Cache-Control: max-age=604800
Pragma: no-cache
Set-Cookie: grav-site-40d1b2d=eo47rrkp2bv5vo91fn8gjjqbs0; expires=Thu, 29-Sep-2016 09:50:35 GMT; Max-Age=1800; path=/; domain=www.thinkoptimised.com; HttpOnly
Content-Encoding: none
Server: cloudflare-nginx
CF-RAY: 2e9e5c2f16de1359-LHR

Below is the html page where you can see pagespeed is working

HTTP/1.1 200 OK
Date: Thu, 29 Sep 2016 09:21:20 GMT
Content-Type: text/html; charset=utf-8
Connection: keep-alive
Set-Cookie: __cfduid=dac868428de03c5593734cc0f9972f9421475140880; expires=Fri, 29-Sep-17 09:21:20 GMT; path=/; domain=.thinkoptimised.com; HttpOnly
Vary: Accept-Encoding
X-Mod-Pagespeed: 1.11.33.2-0
Cache-Control: max-age=0, no-cache
Server: cloudflare-nginx
CF-RAY: 2e9e5d4626f40a66-LHR

Jeff Kaufman

unread,
Sep 29, 2016, 6:27:03 AM9/29/16
to mod-pagespeed-discuss
What does your serving path look like? Are html and php both served
from the same (apache) server?

If you request pages directly from your site, and not via cloudflare,
is it any different?
> --
> You received this message because you are subscribed to the Google Groups
> "mod-pagespeed-discuss" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to mod-pagespeed-di...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/mod-pagespeed-discuss/3b1b130b-a1f5-4e83-af60-ae7025b9ec0b%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

cr...@thinkoptimised.com

unread,
Sep 29, 2016, 6:51:37 AM9/29/16
to mod-pagespeed-discuss
As a test I have created two files

example.html (contents of where are 1 line containing <h1>This is a test</h1>)
Headers received were 
HTTP/1.1 200 OK
Date: Thu, 29 Sep 2016 10:45:35 GMT
Server: Apache/2.4.18 (Ubuntu)
Accept-Ranges: bytes

X-Mod-Pagespeed: 1.11.33.2-0
Cache-Control: max-age=0, no-cache
Content-Length: 30
Content-Type: text/html; charset=utf-8
Which as you can see has page speed.

example.php (content of where are <?php echo '<h1>This is a test</h1>';?>)
Headers received were
HTTP/1.1 200 OK
Date: Thu, 29 Sep 2016 10:48:27 GMT
Server: Apache/2.4.18 (Ubuntu)
Cache-Control: max-age=0, no-cache
Content-Type: text/html; charset=UTF-8

No Pagespeed

Apache was a plain install, its running php7 and the same instance of apache serves both php and html. Everything is on one server. Turning off Cloudflare has no effect

Im completely stuck and Googling doesn't bring anything back, any help would be very much appreciated.





Jeff Kaufman

unread,
Sep 29, 2016, 7:11:45 AM9/29/16
to mod-pagespeed-discuss
Can you paste your apache configuration, or at least the sections
handling php and pagespeed?
>> > email to mod-pagespeed-di...@googlegroups.com.
> --
> You received this message because you are subscribed to the Google Groups
> "mod-pagespeed-discuss" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to mod-pagespeed-di...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/mod-pagespeed-discuss/89711a01-925d-4e48-9abd-b377c648e07c%40googlegroups.com.

cr...@thinkoptimised.com

unread,
Sep 29, 2016, 7:42:30 AM9/29/16
to mod-pagespeed-discuss
Do you mean the Apache2.conf? I haven't altered that since the install
>> > To view this discussion on the web visit
>> >
>> > https://groups.google.com/d/msgid/mod-pagespeed-discuss/3b1b130b-a1f5-4e83-af60-ae7025b9ec0b%40googlegroups.com.
>> > For more options, visit https://groups.google.com/d/optout.
>
> --
> You received this message because you are subscribed to the Google Groups
> "mod-pagespeed-discuss" group.
> To unsubscribe from this group and stop receiving emails from it, send an

Jeff Kaufman

unread,
Sep 29, 2016, 7:52:17 AM9/29/16
to mod-pagespeed-discuss
You have some apache configuration that sets up php, right? Does it look like:

<FilesMatch \.php$>
SetHandler application/x-httpd-php
</FilesMatch>

or something else?
>> >> > email to mod-pagespeed-di...@googlegroups.com.
>> >> > To view this discussion on the web visit
>> >> >
>> >> >
>> >> > https://groups.google.com/d/msgid/mod-pagespeed-discuss/3b1b130b-a1f5-4e83-af60-ae7025b9ec0b%40googlegroups.com.
>> >> > For more options, visit https://groups.google.com/d/optout.
>> >
>> > --
>> > You received this message because you are subscribed to the Google
>> > Groups
>> > "mod-pagespeed-discuss" group.
>> > To unsubscribe from this group and stop receiving emails from it, send
>> > an
>> > email to mod-pagespeed-di...@googlegroups.com.
> --
> You received this message because you are subscribed to the Google Groups
> "mod-pagespeed-discuss" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to mod-pagespeed-di...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/mod-pagespeed-discuss/bb9a3ab0-5698-4b30-9d4b-f29267ee0457%40googlegroups.com.

cr...@thinkoptimised.com

unread,
Sep 29, 2016, 8:03:04 AM9/29/16
to mod-pagespeed-discuss
Inside php7.0.conf I have 

<FilesMatch ".+\.ph(p[3457]?|t|tml)$">
    SetHandler application/x-httpd-php
</FilesMatch>
<FilesMatch ".+\.phps$">
    SetHandler application/x-httpd-php-source
    # Deny access to raw php sources by default
    # To re-enable it's recommended to enable access to the files
    # only in specific virtual host or directory
    Require all denied
</FilesMatch>
# Deny access to files without filename (e.g. '.php')
<FilesMatch "^\.ph(p[3457]?|t|tml|ps)$">
    Require all denied
</FilesMatch>

# Running PHP scripts in user directories is disabled by default
# To re-enable PHP in user directories comment the following lines
# (from <IfModule ...> to </IfModule>.) Do NOT set it to On as it
# prevents .htaccess files from disabling it.
<IfModule mod_userdir.c>
    <Directory /home/*/public_html>
        php_admin_flag engine Off
    </Directory>
</IfModule>


and inside apache2.conf the only FilesMatch I can find is

<FilesMatch "^\.ht">
Require all denied
</FilesMatch>
>> >> > To view this discussion on the web visit
>> >> >
>> >> >
>> >> > https://groups.google.com/d/msgid/mod-pagespeed-discuss/3b1b130b-a1f5-4e83-af60-ae7025b9ec0b%40googlegroups.com.
>> >> > For more options, visit https://groups.google.com/d/optout.
>> >
>> > --
>> > You received this message because you are subscribed to the Google
>> > Groups
>> > "mod-pagespeed-discuss" group.
>> > To unsubscribe from this group and stop receiving emails from it, send
>> > an
>> > To view this discussion on the web visit
>> >
>> > https://groups.google.com/d/msgid/mod-pagespeed-discuss/89711a01-925d-4e48-9abd-b377c648e07c%40googlegroups.com.
>> >
>> > For more options, visit https://groups.google.com/d/optout.
>
> --
> You received this message because you are subscribed to the Google Groups
> "mod-pagespeed-discuss" group.
> To unsubscribe from this group and stop receiving emails from it, send an

Jeff Kaufman

unread,
Sep 29, 2016, 8:15:04 AM9/29/16
to mod-pagespeed-discuss
There's something in your conf that I don't understand. With:

<FilesMatch "^\.ph(p[3457]?|t|tml|ps)$">
Require all denied
</FilesMatch>

It looks like apache should only be willing to serve files named:

*.php
*.php3
*.php4
*.php5
*.php6
*.php7
*.pht
*.phtml
*.phps

and it will reject all others. But you're saying it's serving html
files as well, which means there's something else in your conf that's
interacting with this.
>> >> >> > email to mod-pagespeed-di...@googlegroups.com.
>> >> >> > To view this discussion on the web visit
>> >> >> >
>> >> >> >
>> >> >> >
>> >> >> > https://groups.google.com/d/msgid/mod-pagespeed-discuss/3b1b130b-a1f5-4e83-af60-ae7025b9ec0b%40googlegroups.com.
>> >> >> > For more options, visit https://groups.google.com/d/optout.
>> >> >
>> >> > --
>> >> > You received this message because you are subscribed to the Google
>> >> > Groups
>> >> > "mod-pagespeed-discuss" group.
>> >> > To unsubscribe from this group and stop receiving emails from it,
>> >> > send
>> >> > an
>> >> > email to mod-pagespeed-di...@googlegroups.com.
>> >> > To view this discussion on the web visit
>> >> >
>> >> >
>> >> > https://groups.google.com/d/msgid/mod-pagespeed-discuss/89711a01-925d-4e48-9abd-b377c648e07c%40googlegroups.com.
>> >> >
>> >> > For more options, visit https://groups.google.com/d/optout.
>> >
>> > --
>> > You received this message because you are subscribed to the Google
>> > Groups
>> > "mod-pagespeed-discuss" group.
>> > To unsubscribe from this group and stop receiving emails from it, send
>> > an
>> > email to mod-pagespeed-di...@googlegroups.com.
> --
> You received this message because you are subscribed to the Google Groups
> "mod-pagespeed-discuss" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to mod-pagespeed-di...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/mod-pagespeed-discuss/092ab413-bd48-419c-9cf8-219e27de8566%40googlegroups.com.

cr...@thinkoptimised.com

unread,
Sep 29, 2016, 8:30:14 AM9/29/16
to mod-pagespeed-discuss
The server was built from a base install of Ubuntu 16.04 from Digital Ocean. I added PHP etc. But yes its serving html and php.

Is there anything else I can check?

>> >> >> > To view this discussion on the web visit
>> >> >> >
>> >> >> >
>> >> >> >
>> >> >> > https://groups.google.com/d/msgid/mod-pagespeed-discuss/3b1b130b-a1f5-4e83-af60-ae7025b9ec0b%40googlegroups.com.
>> >> >> > For more options, visit https://groups.google.com/d/optout.
>> >> >
>> >> > --
>> >> > You received this message because you are subscribed to the Google
>> >> > Groups
>> >> > "mod-pagespeed-discuss" group.
>> >> > To unsubscribe from this group and stop receiving emails from it,
>> >> > send
>> >> > an
>> >> > To view this discussion on the web visit
>> >> >
>> >> >
>> >> > https://groups.google.com/d/msgid/mod-pagespeed-discuss/89711a01-925d-4e48-9abd-b377c648e07c%40googlegroups.com.
>> >> >
>> >> > For more options, visit https://groups.google.com/d/optout.
>> >
>> > --
>> > You received this message because you are subscribed to the Google
>> > Groups
>> > "mod-pagespeed-discuss" group.
>> > To unsubscribe from this group and stop receiving emails from it, send
>> > an
>> > To view this discussion on the web visit
>> >
>> > https://groups.google.com/d/msgid/mod-pagespeed-discuss/bb9a3ab0-5698-4b30-9d4b-f29267ee0457%40googlegroups.com.
>> >
>> > For more options, visit https://groups.google.com/d/optout.
>
> --
> You received this message because you are subscribed to the Google Groups
> "mod-pagespeed-discuss" group.
> To unsubscribe from this group and stop receiving emails from it, send an

Jeff Kaufman

unread,
Sep 29, 2016, 8:32:27 AM9/29/16
to mod-pagespeed-discuss
I'm going to need to see more of your configuration to understand
what's going on here. With the piece of configuration you showed me
apache shouldn't be able to serve html at all, yet it clearly is about
to do it, so there's some missing piece. Ideally that piece can show
why pagespeed isn't applying to your php files.
>> >> >> >> > email to mod-pagespeed-di...@googlegroups.com.
>> >> >> >> > To view this discussion on the web visit
>> >> >> >> >
>> >> >> >> >
>> >> >> >> >
>> >> >> >> >
>> >> >> >> > https://groups.google.com/d/msgid/mod-pagespeed-discuss/3b1b130b-a1f5-4e83-af60-ae7025b9ec0b%40googlegroups.com.
>> >> >> >> > For more options, visit https://groups.google.com/d/optout.
>> >> >> >
>> >> >> > --
>> >> >> > You received this message because you are subscribed to the Google
>> >> >> > Groups
>> >> >> > "mod-pagespeed-discuss" group.
>> >> >> > To unsubscribe from this group and stop receiving emails from it,
>> >> >> > send
>> >> >> > an
>> >> >> > email to mod-pagespeed-di...@googlegroups.com.
>> >> >> > To view this discussion on the web visit
>> >> >> >
>> >> >> >
>> >> >> >
>> >> >> > https://groups.google.com/d/msgid/mod-pagespeed-discuss/89711a01-925d-4e48-9abd-b377c648e07c%40googlegroups.com.
>> >> >> >
>> >> >> > For more options, visit https://groups.google.com/d/optout.
>> >> >
>> >> > --
>> >> > You received this message because you are subscribed to the Google
>> >> > Groups
>> >> > "mod-pagespeed-discuss" group.
>> >> > To unsubscribe from this group and stop receiving emails from it,
>> >> > send
>> >> > an
>> >> > email to mod-pagespeed-di...@googlegroups.com.
>> >> > To view this discussion on the web visit
>> >> >
>> >> >
>> >> > https://groups.google.com/d/msgid/mod-pagespeed-discuss/bb9a3ab0-5698-4b30-9d4b-f29267ee0457%40googlegroups.com.
>> >> >
>> >> > For more options, visit https://groups.google.com/d/optout.
>> >
>> > --
>> > You received this message because you are subscribed to the Google
>> > Groups
>> > "mod-pagespeed-discuss" group.
>> > To unsubscribe from this group and stop receiving emails from it, send
>> > an
>> > email to mod-pagespeed-di...@googlegroups.com.
> --
> You received this message because you are subscribed to the Google Groups
> "mod-pagespeed-discuss" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to mod-pagespeed-di...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/mod-pagespeed-discuss/7a5ec3d0-3b9d-4b54-8292-bc137cd9c09b%40googlegroups.com.

cr...@thinkoptimised.com

unread,
Sep 29, 2016, 8:37:08 AM9/29/16
to mod-pagespeed-discuss
I can supply anything, I'm just not sure what to show. I didn't setup Apache as it was already installed as part of Ubuntu and I haven't changed anything with it.
>> >> >> >> > To view this discussion on the web visit
>> >> >> >> >
>> >> >> >> >
>> >> >> >> >
>> >> >> >> >
>> >> >> >> > https://groups.google.com/d/msgid/mod-pagespeed-discuss/3b1b130b-a1f5-4e83-af60-ae7025b9ec0b%40googlegroups.com.
>> >> >> >> > For more options, visit https://groups.google.com/d/optout.
>> >> >> >
>> >> >> > --
>> >> >> > You received this message because you are subscribed to the Google
>> >> >> > Groups
>> >> >> > "mod-pagespeed-discuss" group.
>> >> >> > To unsubscribe from this group and stop receiving emails from it,
>> >> >> > send
>> >> >> > an
>> >> >> > To view this discussion on the web visit
>> >> >> >
>> >> >> >
>> >> >> >
>> >> >> > https://groups.google.com/d/msgid/mod-pagespeed-discuss/89711a01-925d-4e48-9abd-b377c648e07c%40googlegroups.com.
>> >> >> >
>> >> >> > For more options, visit https://groups.google.com/d/optout.
>> >> >
>> >> > --
>> >> > You received this message because you are subscribed to the Google
>> >> > Groups
>> >> > "mod-pagespeed-discuss" group.
>> >> > To unsubscribe from this group and stop receiving emails from it,
>> >> > send
>> >> > an
>> >> > To view this discussion on the web visit
>> >> >
>> >> >
>> >> > https://groups.google.com/d/msgid/mod-pagespeed-discuss/bb9a3ab0-5698-4b30-9d4b-f29267ee0457%40googlegroups.com.
>> >> >
>> >> > For more options, visit https://groups.google.com/d/optout.
>> >
>> > --
>> > You received this message because you are subscribed to the Google
>> > Groups
>> > "mod-pagespeed-discuss" group.
>> > To unsubscribe from this group and stop receiving emails from it, send
>> > an
>> > To view this discussion on the web visit
>> >
>> > https://groups.google.com/d/msgid/mod-pagespeed-discuss/092ab413-bd48-419c-9cf8-219e27de8566%40googlegroups.com.
>> >
>> > For more options, visit https://groups.google.com/d/optout.
>
> --
> You received this message because you are subscribed to the Google Groups
> "mod-pagespeed-discuss" group.
> To unsubscribe from this group and stop receiving emails from it, send an

cr...@thinkoptimised.com

unread,
Sep 29, 2016, 8:55:19 AM9/29/16
to mod-pagespeed-discuss
Here is the entire apache2.conf (I have removed the commented out lines)


Mutex file:${APACHE_LOCK_DIR} default
PidFile ${APACHE_PID_FILE}
Timeout 300
KeepAlive On
MaxKeepAliveRequests 100
KeepAliveTimeout 5
User ${APACHE_RUN_USER}
Group ${APACHE_RUN_GROUP}
HostnameLookups Off
ErrorLog ${APACHE_LOG_DIR}/error.log
LogLevel warn
IncludeOptional mods-enabled/*.load
IncludeOptional mods-enabled/*.conf
Include ports.conf

<Directory />
  Options FollowSymLinks
  AllowOverride None
  Require all denied
</Directory>

<Directory /usr/share>
  AllowOverride None
  Require all granted
</Directory>

<Directory /var/www/>
  Options Indexes FollowSymLinks
  AllowOverride None
  Require all granted
</Directory>

<Directory /srv/>
</Directory>

AccessFileName .htaccess

<FilesMatch "^\.ht">
  Require all denied
</FilesMatch>

LogFormat "%v:%p %h %l %u %t \"%r\" %>s %O \"%{Referer}i\" \"%{User-Agent}i\"" vhost_combined
LogFormat "%h %l %u %t \"%r\" %>s %O \"%{Referer}i\" \"%{User-Agent}i\"" combined
LogFormat "%h %l %u %t \"%r\" %>s %O" common
LogFormat "%{Referer}i -> %U" referer
LogFormat "%{User-agent}i" agent

IncludeOptional conf-enabled/*.conf

IncludeOptional sites-enabled/*.conf

cr...@thinkoptimised.com

unread,
Sep 29, 2016, 9:52:16 AM9/29/16
to mod-pagespeed-discuss
I've been trying to singe out what the issue is. I was using https://ismodpagespeedworking.com that website to check if page speed was working on two urls 


and it says no to both.

Inspecting the headers in Safari I can actually see "X-Mod-Pagespeed : 1.11.33.2-0" header present for both urls, whereas ismodpagespeedworking.com says it wasn't

For the main url http://www.thinkoptimised.com/ I can see that "X-Mod-Pagespeed : 1.11.33.2-0" isn't present. The only difference in the headers are the main url also sends "Pragma : no-cache"

Im going to guess this is the issue, but I haven't managed to find out how its being added yet. Do you think I am on the right track?

Jeff Kaufman

unread,
Sep 29, 2016, 10:11:42 AM9/29/16
to mod-pagespeed-discuss
Weirdly I now see the X-Mod-Pagespeed: header for both your html and
php, while in your php example upthread I only saw the header on html.
So it looks like PageSpeed is working for you now.

Still, it's weird that it wasn't working earlier. I'm going to bring
up a test box with ubuntu 16, apache, pagespeed, and php, and see if I
can repro.
> --
> You received this message because you are subscribed to the Google Groups
> "mod-pagespeed-discuss" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to mod-pagespeed-di...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/mod-pagespeed-discuss/3ba66f13-4a21-4849-bd7d-379c787dc8ee%40googlegroups.com.

Jeff Kaufman

unread,
Sep 29, 2016, 10:14:54 AM9/29/16
to mod-pagespeed-discuss
Ok, I set up the test server, and I see mod_pagespeed running for both
php and html files. Sorry!

One way to make sure PageSpeed is running is to append
?PageSpeedFilters=+debug to your html, look a the source, and scroll
all the way to the bottom. You should see debug comments confirming
that PageSpeed is enabled.

cr...@thinkoptimised.com

unread,
Sep 29, 2016, 12:19:26 PM9/29/16
to mod-pagespeed-discuss
I still don't see it working on the main site. Only for the examples.

Im sure it has something to do with that Pragma?

cr...@thinkoptimised.com

unread,
Sep 29, 2016, 12:21:43 PM9/29/16
to mod-pagespeed-discuss
I've just tried the +debug but that only works for the example pages. Still having issues with the main site :(

cr...@thinkoptimised.com

unread,
Sep 30, 2016, 4:31:33 AM9/30/16
to mod-pagespeed-discuss
So after a lot of digging I think its the CMS inserting the header. Im seeing if I can get an answer over there. 

Thanks for all the help Jeff
Reply all
Reply to author
Forward
0 new messages