Zend Server "Caching" of JS and CSS files - php

I'm running Zend Server in a CentOS VM on Vitrualbox and I'm having a problem with linked JS and CSS assets being "cached". I say "cached" because they aren't, in the true sense, being cached, but rather when I add content to a JS or CSS file they become corrupted and the changes do not appear. Instead the file is appended with a bunch of bad characters eg.
layout.phtml (zend framework template)
$this->headScript()->appendFile ('/js/admin/product.js', 'text/javascript' );
This renders:
<script type="text/javascript" src="/js/admin/product.js"></script>
products.js
//re-add scrolling handles
scrollThumbs.reSortThumbs(ul);
product.moveFileInput(ul);
};
};��������������������������������������������������
If I remove content from the JS or CSS file the result is an incomplete file and not the addition of bad characters as outlined above.
I've turned off all forms of Zend caching and even turned off Zend Optimizer. I've deleted browser cache and tried several browsers.
I have ssh'd into the server and double checked the file and it is perfectly formatted and contains the changes. I've tried restarting Zend Server (/usr/local/zend/bin/zendctl.sh restart) and Apache (service httpd restart)
The only way to fix it is to restart the entire OS (reboot). Interestingly, if I remove the changes, it goes back to working correctly. I can only assume that there is some form of caching happening somewhere on the server side.

It turns out that it is a Virtualbox shared folder issue and not one uniquely related to Zend Server, but Apache in general.
The fix came from Shared folder in VirtualBox for Apache
Add EnableSendfile off to your vhost file eg.
<VirtualHost *:80>
DocumentRoot "/mnt/your/shared/dir"
ServerName Default
<Directory "/mnt/your/shared/dir/public">
EnableSendfile off
Options FollowSymLinks
AllowOverride All
Order allow,deny
Allow from all
</Directory>
</VirtualHost>

It is because you have a browser cache turned on and the file name stays the same.
This can be avoided by using md5_file() on you scripts and saving this to cookies,
and on each request check if the cookie changed - in this case you will be able to manage cases when your front-end files are changed.

I tried the EnableSendfile off thing but it does not work on my Centos virtual machine with ZendServer. So I moved to my ubuntu virtual machine with apache installed manually (without ZendServer) and it worked perfectly. What seems to me, is that it is a issue on ZendServer, at least on ZendServer configuration.

Related

W7, apache, php: 403 Forbidden You don't have permission to access /phptest/phpinfo.php

There are lots of questions on this but I still cannot get it to work.
I am installing Apache 2.4 and PHP 5.4.37 on a W7 Pro PC. PHP is running as a load module. If installed respectively in c:\apache24 and c:\php, with the document root as default at c:\apache24\htdocs, it all works fine.
However, I then decided I wanted the document root at f:\webroot (local drive), making necessary changes to document root in httpd.conf. webroot has all the same permissions as c:\apache24\htdocs, but I get the error message in the title.
A normal index.html file in webroot is served OK, it is just any PHP file that isn't.
I noted that the Apache service is started with user LocalSystem. So I tried various others. I even tried running Apache from the command line (instead of as a service) logged in as Administrator, which should have had access to anything, and it made no difference - same message.
Don't understand what is going on. I can go back to the default document root, but at some point will need to access folders elsewhere on the system, so I will be back with the same problem, I guess.
Further info:
Tried various combinations of the commands in <directory "f:/webroot"> to no effect, BUT have found that if in <directory /> I set 'Require all granted' instead of 'Require all denied', it works. However, not sure (a) if that is wise (it probably isn't) and (b) why it is needed anyway. Any suggestions about what I should set it to?
Solved this:
Not only do you have to set Document root and the matching <DIRECTORY ...> section entry in httpd.conf, but also DocumentRoot in the <VirtualHost _default_:80> section of the ...\conf\extras\httpd-vhosts.conf file.
Setting 'Require all granted' in <DIRECTORY /> was a mistake.

Display all files in MAMP htdocs through browser

I recently purchased a new MacBook Pro (10.8 OS) and installed MAMP 3.0 (not MAMP-Pro) but I have been searching the web on how to display all files when viewing a folder within the htdocs directory such as: htdocs/stackoverflow VIA the browser (Chrome or Firefox). This is a feature that I do not have a problem with in Windows using either WAMP or XAMPP when navigating to the localhost/directory/contents. I do understand that localhost must be accessed through locahost:8888 or whatever port it has been modified to. I do not have an issue starting or stopping the MAMP server and everything is executable through NetBeans 8.0 when I set a .php file as the index:
So just to be clear, if I have a directory under htdocs (htdocs/foobar/) filled with several .php files I want to be able to view them in the sub-directory of htdocs instead of a blank browser (tested within Chrome and Firefox). I would imagine this is a security setting I am missing in the configuration? How would I enable, for local development, the ability to view all files, directories, and contents VIA the web browser? If it helps or may be an issue I am using NetBeans 8.0 as my IDE for PHP.
Windows:
localhost
-stackoverflow
--foo.php
--bar.php
--humpday.php
Mac:
localhost:8888
-stackoverflow
--empty in browser (chrome or Firefox)
I have searched to see if this a php.ini feature, MAMP 3 documentation has nothing on this, and Netbeans shows nothing per the search.
Ok after much research and the help from Kevbot and Matt Thompson I was able to figure out what to do and it is as followed:
You should enable all hidden files in Mac that are default hidden. To do this open a terminal (Finder > Applications > Utilities > Terminal) I originally referenced this site but it was wrong in regards to showing hidden files for OSX 10.8:
WRONG:
defaults write com.apple.Finder AppleShowAllFiles YES
RIGHT:
defaults write com.apple.finder AppleShowAllFiles YES
After doing so I held down the option + clicking Finder at the same time to prompt Relaunch of Finder.
You will need to navigate to MAMP (in this case MAMP 3.0 non-pro) in the Applications folder to MAMP > conf > apache > httpd.conf.
Open file in a text editor and search for Options Indexes. It was line 202 for me.
Change:
<Directory />
Options Indexes FollowSymLinks
AllowOveride None
</Directory>
TO:
<Directory />
Options Indexes FollowSymLinks
AllowOveride All
</Directory>
Create an .htaccess file in the desired directory and add:
Options +Indexes
IndexOptions +FancyIndexing
Launch/relaunch MAMP. Do note that if you have an index anything (.php, .html. .xhtml, etc. etc.) will show this instead of the directory listing
Actual Answer:
You need to modify the .htaccess file in your root directory.
I was able to get this to work with no issues. In your .htaccess, add the following:
Options +Indexes
IndexOptions +FancyIndexing
DirectoryIndex somethingRandom.html
Here is what each line does:
Line 1 specifies to allow the indexing of files.
Line 2 tells the browser to display more information regarding the files
Line 3 tells the browser the default index file is not index.php or index.html. Just set the file to something that will never exist.
Old Answer:
There are several things you can do to configure MAMP.
You don't have to access MAMP with localhost:8888, you can access it with just localhost with the following changes. If you open the MAMP program, and select:
Preferences
Ports
Set to default Apache and MySQL ports
Then, you can access your server through localhost in the web browser. Also, if you want to switch development folders (using a subfolder of htdocs as it's own site) you can configure those as well. Select the following from the MAMP program window:
Preferences
Apache
Select (a folder inside of htdocs)
Now, when you access localhost in the browser, that folder will be your root folder until you change it back to htdocs.
And just to make sure, did you remember to "Start Servers?"
Hope this helps.

Apache 2 and .htaccess are downloading, not running, PHP files

I'm trying to use .htaccess files with PHP on OS X (Snow Leopard, 10.6.8), but when I go to localhost/ the browser just downloads whatever file it's lead to by the rewrite rules (rather than getting the output of the server-side execution of the PHP).
I've confirmed that PHP runs with Apache on other, simpler installations. For debugging I'm targetting check.php script so that should be good.
The web is full of guidance to hunt down and replace all AllowOverride None statements with AllowOverride All, but my apache configuration for this differs from the base OS X installation and doesn't include any of the various files with the AllowOverride None directives. I've set all of those touched by my configuration.
This same configuration runs the php scripts just fine when they're hit by the URL.
I've confirmed that mod_rewrite.so is available and loaded.
I'd appreciate help diagnosing / debugging this.
EDIT:
Also, when I hit the page from Firefox, I get a dialog saying "You have chosen to open [blank, for the index url] which is a: application/x-httpd-php5" and the choice to save or run. That x-httpd-php5 value is the string I use in the AddType directive in the .htaccess file.
Make sure Web Sharing is turned on in the preferences.

Running PHP file outside of documentroot (cgi-bin folder)

I am working with a colleague to set up their local environment on a MAC in XAMPP, on windows my vhost looks like the one below.
When I access a URL like http://domain.local/cgi-bin/handler.php the web server processes the PHP correctly but on his we get a 500 server error and this message...
The server encountered an internal error and was unable to complete your request.
Error message:
Premature end of script headers:
We tried changing the name of the cgi-bin folder to something else as I noticed there was another alias in httpd.conf but this had no effect...so it seems to me like the issue is permissions related.
We believe the alias is setup ok as accessing http://domain.local/cgi-bin/filenothere.php which doesn't exist throws a 404 as expected, any .html/.pl files fail to execute.
The permissions that exist on the cgi-bin folder are...
rwxrwxrwx dave staff
and is owned by the user and group....
dave staff
Vhost
<VirtualHost *:80>
ServerAdmin webmaster#example.com
ServerName www.domain.local
ServerAlias domain.local
ServerAlias api.domain.local
# Indexes + Directory Root.
DirectoryIndex index.php
DocumentRoot E:/home/www/www.domain.co.uk/htdocs/
# CGI Directory
ScriptAlias /cgi-bin/ E:/home/www/www.domain.co.uk/cgi-bin/
<Location /cgi-bin>
Options +ExecCGI
</Location>
# Logfiles
ErrorLog E:/home/www/www.domain.co.uk/logs/error.log
CustomLog E:/home/www/www.domain.co.uk/logs/access.log combined
</VirtualHost>
Any idea what is causing this PHP file to not be executed?
UPDATE
Tried adding a header to say that the content is PHP to the start of the PHP file and this now simply outputs the PHP code.
It's as if any path specified in as an Alias is accessible but the server doesn't know how to execute the content, this is for HTML as well as PHP
I think you need a section for your cgi-bin.
The fact that your server can show you the script sources means the server has at least read permissions on /file/system/path/to/cgi-bin and IIRC that clashes with ScriptAlias b/c ScriptAlias expects /file/system/path/to/cgi-bin to be unaccessible for security reasons. I think your solution should look something along the lines of:
<Directory /file/system/path/to/cgi-bin>
Options ExecCGI
SetHandler cgi-script
</Directory
There is (very) rarely a need to run PHP scripts as CGIs given that the PHP module for Apache can execute them directly. Try adding this to your Apache config:
<FilesMatch \.php$>
SetHandler application/x-httpd-php
</FilesMatch>
Afterwards simply place the PHP scripts into the document root for the site and see if they work. You'll want to remove the /cgi-bin/ part of the URL.
You say you're setting XAMMP on a Mac, but you have a drive letter (E:) prefixing your paths. OS X does not have drive letters like Windows, and this may also be causing (part of) your issue.
I don't know much about settings used. But I think you should go through following links. Might get some help.
http://www.sean-barton.co.uk/2009/02/setting-up-a-phpmysql-local-development-environment-on-a-mac-doing-it-properly/
http://docs.joomlabamboo.com/using-joomla/setting-up-a-quick-start-package-on-your-local-server-xampp-pc
http://www.adobe.com/devnet/dreamweaver/articles/setup_php.html
How to create Mac OS X dev environment for legacy PHP app?
Assuming that PHP is running in Safe Mode you may need to "open" your cgi-bin directory, as the execution of user (PHP) scripts is limited to the DocumentRoot and it's subfolders.
For all I know you could do that in two ways
1. Edit your php.ini
Locate the line containing open_basedir. If there's a comment at the beginning of the line - a semicolon - remove it. Then add your cgi-bin directory.
open_basedir = "E:\home\www\www.domain.co.uk\cgi-bin\"
If you need to open more than one directories you can use semicolon ; as a separator. On Linux based server, use a colon :
open_basedir = "E:\home\www\www.domain.co.uk\cgi-bin\;E:\home\www\www.domain.co.uk\another_dir\"
In cases like mine, where your server is hosted by third party, you'd need the second option (well sort of)
2. Edit your VirtualHost
Add the following to your VirtualHost, i.e. after DocumentRoot:
php_admin_value open_basedir "E:\home\www\www.domain.co.uk\cgi-bin\"
Same rules apply here for multiple directories and difference between Linux and Windows systems as above.
Hope that helps
Do you know whether PHP is running as a CGI program or as a webserver module? You should be able to find this out if you can get a phpinfo() page working (maybe from a regular folder inside the website root). If you're running as a webserver module then you should have a section near the top with a heading of Server API which says Apache 2.0 Handler (or equivalent).
From these pages:
https://bugs.php.net/bug.php?id=13316
http://php.net/manual/en/install.unix.commandline.php
http://gallery.menalto.com/node/8955
... it seems that it may be either due to PHP running as a CGI script, or else a conflict between PHP and another CGI handler.
One of the posters on the third linked page found that their similar-sounding end of script headers issue was resolved by removing / commenting out the Options +ExecCGI line in their .htconfig / vhosts file.
Might be worth having a read through the above links to see if your problem is related.

Apache is redirecting to a non-existant virtual host

Earlier today I tried installing the MyImouto image board software on my Apache server. I already have the full MediaWiki engine installed on port 80 (localhost/wiki/) and the MyImouto board installed in a virtual host on port 3000, running completely separate from the main web server.
After fiddling around a little, I made a mistake with a php-based upload on the main server and had to reinstall apache and php both, which I did, and upgraded to the latest versions (Apache 2.2.22 and PHP 5.4.0). I managed to get my setup up and running successfully, both with the port 3000 virtual host and without. And MediaWiki functions fine, except for one thing.
NOW when I type in http://localhost/wiki/index.php as I have always done in the past, something is redirecting it to http://localhost:3000/wiki/index.php/Main_Page and shifting it to the other virtual host, where there is no wiki at all. However http://localhost/wiki/index.php/Main_Page does work perfectly.
There's an .htaccess file in localhost:3000 which I renamed to something else, but that doesn't seem to do the trick. I also tried clearing the browser cache as well as running a session_destroy via php. It didn't fix it.
I even turned off the second virtual host in Apache's httpd.conf, but it still redirects me which tells me that it is something in the main webserver. I did not touch the MediaWiki configuration or code during this entire time.
I also attempted accessing http://localhost/phpMyAdmin and THAT redirected me to http://localhost:3000/phpMyAdmin/, as well as http://localhost/AdminTools which does the same type of thing. Httpd.conf now no longer has any references at all to the virtual host *:3000.
However, my main index (http://localhost/index.php) has the following header redirect, which successfully lets it work even when http://localhost is typed into the address bar.
header("Location: index.php?content=main");
I tried disabling expires_module and headers_module in Apache, thinking there might be some weird caching issue due to that now-renamed .htaccess file. That did not help either. In addition, I checked my hosts file and there is nothing odd in there, nor am I proxying through anything (this -is- localhost after all).
Would appreciate any help in figuring out what's causing this and how to fix it.
Windows XP SP3
Enabled Modules in Apache:
actions, alias, asis, auth_basic, authn_default, authn_file, authz_default, authz_groupfile, authz_host, authz_user, cgi, dir, env, expires, headers, include, isapi, log, mime, negotiation, rewrite, setenvif, php5
Enabled extensions in PHP:
curl, fileinfo, gd2, mbstring, exif, mysql, mysqli, openssl, pdo_mysql, sockets
I managed to figure it out. After fiddling a little bit with .htaccess and Rewrite Rules (none of which did anything), I took a look inside my httpd.conf file again and found that I had typo'd my port-80 Virtual Host:
<VirtualHost *:80>
ServerAdmin -myemail-#gmail.com
ServerName -blahblah-.no-ip.org:3000
DocumentRoot "C:/wwwroot/tfg"
<Directory "C:/wwwroot/tfg">
OptionsIndexes FollowSymLinks
AllowOverride All
Allow from all
Deny from 186
Deny from 187
</Directory>
</VirtualHost>
When in fact it should have been ServerName -blahblah-.no-ip.org:80.
Simple typos: always the ones that slip by the easiest.

Categories