Weird nginx caching - caching

I'm trying to set up a development server with PuPHPet, which is essentially just a pre-made build of Vagrant with PHP, Nginx and a few other things pre-installed.
I'm having a weird caching issue with my .css files.
When I access my .css file directly at my dev URL, it shows part of the file. This is the file as it was originally before I started editing it. You will notice from my screenshot that I've deleted the entire contents of the file and replaced it with the numbers "12345". When I refresh the .css file in my browser, I see the first 5 characters of the old file. Adding an extra character restores an additional character from the old file.
Restarting nginx does not clear the cache. Ctrl+F5 does not clear the cache. Checking the file contents from vagrant ssh:
[08:11 PM]-[vagrant#precise64]-[/var/www/public/css]-[hg default] B
B$ cat main.css
12345
I can see the file is up to date. The file it's partially displaying simply does not exist. My best guess is it's reading the length of the file on disk, and then pulling the actual contents from memory.
The built-in PHP 5.4 development server does not have this problem, so I'm pretty sure Nginx is the culprit.
How can I get Nginx to behave in a sane fashion?

Most probably it's this know VirtualBox bug with the sendfile system call.
Try disabling sendfile in nginx config:
sendfile off;
(In apache EnableSendfile off)

Related

Phoenix Caches Indefinitely

I'm writing a project with a lot of static files
Whenever I change a custom.js file, even thought it get changed both in
web/static/assets/custom.js and priv/static/assets/custom.js
When I try to reach the resource I get the old version, which is also most of the times corrupted
I tried:
restarting the server
running brunch build
removing the whole _build directory
changing the files further
clearing browsers cache
using url localhost:4000/assets/js/custom.js -H 'Pragma: no-cache'
Still the server serves old file
Edit
It seems to be an issue with mtime difference between vagrant VM and host.
So the real question is:
How to eliminate that issue?

"DocumentRoot must be a directory" error in Apache on Windows XP

I try to setup Apache (part of EnterpriseDB ApachePHP package) for localhost. But Apache won't start since the first restart (after initial configuration). Httpd.exe complains that "DocumentRoot must be a directory" - but it IS a directory, and Apache even recognized it as such before the first restart. This problem persists even when I change the DocumentRoot back to its default directory.
The problematic line looks like this: DocumentRoot "d:\www\" When changing the backslashes to slashes or deleting the trailing backslash httpd.exe works forever and never reaches any result, so I understand that this is the correct format.
There is a good question on this: Apache restart causes DocumentRoot must be a directory, even though it is a directory and there seem to be no privilege issues. Unfortunately, I believe its solution is not applicable to my case: on Windows XP (32 bit) there is no SELinux to disable.
The last action I did before the restart was enabling (uncommenting) php_gd2 library in php.ini. Reverting this didn't make Apache work, so I guess this is not the reason. This (and the root directory in httpd.conf) was the only change I did, otherwise I accepted EDB's defaults.
Any ideas what to do now?
I have reinstalled EnterpriseDB Apache PHP and now it seems to work fine. The correct format is with no trailing slash - under this configuration server is running now, and when I execute httpd.exe in command line, it shows some log in less than a minute (not "still working after an hour"). I don't know what caused the problem, but it is solved.

Where does MAMP keep its php.ini?

I have recently got a mac an am not used to developing on a mac at all.
I have MAMP Pro 1.9.6.1. I did a locate on php.ini and got this:
$ locate php.ini
/Applications/MAMP/conf/php5.2/php.ini
/Applications/MAMP/conf/php5.3/php.ini
/Library/Application Support/appsolute/MAMP PRO/conf/php.ini
/private/etc/php.ini.default
I changed the name of all of them. Restarted MAMP. It loaded without a hitch (I know odd right?). I am using PHP version 5.2.
All of these files are now different names (done one by one for process of elimination).
So I figure restart the mac. Same, MAMP loaded no problems, even though all of the php.ini files had been move. On Lamp this that wouldn't even load. But either there is another php.ini file I'm missing (quite possible I don't know how to updatedb), MAMP is really intelligent and just pulls in all of them (less likely) or it doesn't use one.
Note: If this doesn't help, check below for Ricardo Martins' answer.
Create a PHP script with <?php phpinfo() ?> in it, run that from your browser, and look for the value Loaded Configuration File. This tells you which php.ini file PHP is using in the context of the web server.
I'm not sure if in MAMP (non-PRO) is the same, but MAMP overrides the modified php.ini everytime it starts.
In my case, I needed to use the MAMP menu to change my php.ini file (File -> Edit Template -> PHP -> PHP 5.xx -> php.ini).
To be clearer (as i read this thread but didn't SEE the solution, also if it was here!), I have the same problem and found the cause: I were modifying the wrong php.ini!
Yes, there are 2 php.ini files in MAMP:
Applications/MAMP/conf/php5.5.10/php.ini
Applications/MAMP/bin/php/php5.5.10/conf/php.ini
The right php.ini file is the second: Applications/MAMP/bin/php/php5.5.10/conf/php.ini
To prove this, create a .php file (call it as you like, for example "info.php") and put into it a simple phpinfo()
<?php
echo phpinfo();
Open it in your browser and search for "Loaded Configuration File": mine is "/Applications/MAMP/bin/php/php5.5.10/conf/php.ini"
The error was here; i edited Applications/MAMP/conf/php5.5.10/php.ini but this is the wrong file to modify! Infact, the right php.ini file is the one in the bin directory.
Take care of this so small difference that caused me literally 1 and a half hours of headaches!
The file you have to edit is in MAMP Pro and uses the php.ini file everytime it starts up.
Start MAMP PRO
Edit File > Edit Templates > PHP 5.3.2 php.ini
Restart MAMP Pro
Your changes should stick.
I don't know if you ever found an answer to this but I DIDN'T need MAMP PRO to do this. Simply goto the correct path by following what others have said. It's something like...
MAMP-> bin-> php-> php(your php version)-> conf-> php.ini
The key here is where you're editing the file. I was making the mistake of editing the commented part of the ini file. You actually have to scroll down to LINE #472 where it says "display_errors = Off and change it to On. Hope this helps any
Just run the following command from your terminal, it will show you your Loaded Configuration File easiest way I have ever found.
php --ini
Change /Applications/MAMP/conf/php5.2/php.ini if you are using 5.2 version of php. If you are using the 5.3 php version, edit the /Applications/MAMP/conf/php5.3/php.ini.
If you are using OSX Lion or OSX Mountain Lion, I recommend you using the default installation of apache and php.
Greets!
After running the MAMP server, you have php info link in toolbar
Once click, You will get all information about php
Probably the fastest way to access the PHP.ini for the currently loaded version of PHP in MAMP PRO (v.4.2.1):
Open MAMP Pro
Click on "PHP" under the "Languages" section on the sidebar
Tap on the arrow button right next to the drop-down that lets you select the "Default Version" of PHP.
It depends on which version of PHP your MAMP is using. You can find it out on: /Applications/MAMP/conf/apache/httpd.conf looking for the configured php5_module.
After that, as someone said before, you have to go to the bin folder. There you'll find a conf folder with a php.ini inside.
example: /Applications/MAMP/bin/php/php5.4.10/conf
Leo
After going through all the solutions here, the easiest way to find the loaded php.ini file is to go into phpinfo on the loaded MAMP webpage, which will show you the loaded php.ini file.
This will also confirm if the parameters you change, like max_file_size, have updated correctly.
On my Mac, running MAMP I have a few locations that would be the likely php.ini, so I edited the memory_limit to different values in the 2 suspected files, to test which one effected the actual MAMP PHP INFO page details.
By doing that I was able to determine that this was the correct php.ini:
/Applications/MAMP/bin/php/php7.2.10/conf/php.ini
I only have the non-pro version of MAMP but just because it loads it doesn't mean the PHP file is being found/without errors.
I renamed my php.ini files and MAMP still started but Apache returned several errors.
What are you trying to change in your php.ini file?
I have checked all answers and of course I have used phpinfo() to check the exact location of php.ini. I don't see a File option in the menu bar on my mac. I changed both php.ini and php.ini.temp files in that folder. No vail.
Until I realized that I forgot to uncomment the modified always_populate_raw_post_data line.
I was struggling with this too. My changes weren't being reflected in phpInfo. It wasn't until I stopped my servers and then restarted them again that my changes actually took effect.

install wordpress locally on OS X without MAMP (permission error)

I'm trying to install wordpress locally on a mac with the built in stuff (apache/php) without installing MAMP. basically I'm following this tutorial:
https://gist.github.com/1500117
after editing the httpd.conf file, and restarting apache, I get this error in the browser:
Forbidden
You don't have permission to access / on this server.
Any ideas?
I'm using Snow Leopard
well it seams I found what caused the problem.
the Sites folder, where I put the wordpress folder had permissions 750, after changing it to 751, now it works.
is this a proper solution or I should keep digging?
While there are a lot of variables to check here, the two biggest are the server root (make sure the case of all the path elements is correct) and the user permissions/owner of the WordPress files themselves.
All that said, why not use MAMP for this kind of situation?
Try typing http://your-host-name/index.php
If that fixes it, then your DirectoryIndex directive (in httpd.conf) needs to be changed to DirectoryIndex index.html index.php
If that does not fix it, type tail -f /var/log/apache2/error_log at the console and look at the terminal screen while you hit http://your-host-name/index.php in your browser. It may tell you what the problem is. If not, paste the last few lines of the log file up here and I'll look at it for you.

php-fpm for Windows?

The PHP-FPM's homepage http://php-fpm.org/ states that it is part of PHP since PHP 5.3.3. Now, I was wondering, when I download the newest PHP binaries from php.net, there is no php-fpm in it. How do I get it? Is it even available for Windows?
Here how to setup php-fpm on Windows:
Download the .zip file from http://windows.php.net/download/. The .zip file should be VC9 which has the FastCGI file (php-cgi.exe). Don't download VC6, and don't download the .msi file because it requires that you have IIS setup already in order to install php-fpm. The zip file contains the php-cgi.exe which is what you need for php-fpm. I downloaded a slightly older version, php-5.3.10-Win32-VC9-x86.zip, from here http://windows.php.net/downloads/releases/archives/ because I wanted to match the version running on my production server.
Unzip the file, e.g. unzip into C:\php-5.3.10-Win32-VC9-x86
Edit the php.ini file as needed. What I did:
# nginx security setting
cgi.fix_pathinfo=0
extension_dir = "C:\php-5.3.10-Win32-VC9-x86\ext"
enable the following modules by uncommenting them:
extension=php_curl.dll
extension=php_mbstring.dll
extension=php_mysqli.dll
Create a .bat file somewhere, e.g. start-php-fcgi.bat in webserver directory or in the PHP directory:
#ECHO OFF
ECHO Starting PHP FastCGI...
set PATH=C:\php-5.3.10-Win32-VC9-x86;%PATH%
C:\php-5.3.10-Win32-VC9-x86\php-cgi.exe -b 127.0.0.1:9123 -c C:\php-5.3.10-Win32-VC9-x86\php.ini
Double click the .bat file to start php-fpm. A window will popup and stay open while its running. Its kind of annoying, but just haven't looked into setting it up as service yet.
Configure your webserver. If you wish to use it with nginx, here a config sample for 127.0.0.1:9123:
location ~ \.php$ {
fastcgi_pass 127.0.0.1:9123;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
Old as this post is I have to weigh in here because what has been posted here is not PHP-FPM, it's running PHP using Fast-CGI.
Yes PHP-FPM stands for PHP-FastCGI Process Manager and so implements FastCGI but you are forgetting that FPM is much more than that as it contains process management features that are not managed by the webserver.
On *nix systems PHP-FPM has a separate process that manages the PHP child processes and has a detailed configuration to specify how these processes are managed. For details on these features read here
Launching a CGI process on windows is not the same thing. It does not spaw worker processes or dynamically scale them or allow multi-threading.
There is no PHP-FPM for windows yet.
http://php.net/manual/en/install.fpm.php#121725
However as suggested, you may launch a CGI process if you wish.
Alan's answer is a great start. However, for Apache 2.4 and later you do not need to run PHP-FPM as a separate service, you can use mod_fcgid to handle everything within Apache.
Here is an example configuration:
LoadModule fcgid_module modules/mod_fcgid.so
FcgidInitialEnv PHPRC "c:/php"
FcgidInitialEnv PATH "c:/php;C:/WINDOWS/system32;C:/WINDOWS;C:/WINDOWS/System32/Wbem;"
FcgidInitialEnv SystemRoot "C:/Windows"
FcgidInitialEnv SystemDrive "C:"
FcgidInitialEnv TEMP "C:/WINDOWS/Temp"
FcgidInitialEnv TMP "C:/WINDOWS/Temp"
FcgidInitialEnv windir "C:/WINDOWS"
FcgidIOTimeout 64
FcgidConnectTimeout 16
FcgidMaxRequestsPerProcess 500
<Files ~ "\.php$">
AddHandler fcgid-script .php
FcgidWrapper c:/php/php-cgi.exe .php
</Files>
Note, this is based on a post in Apache Lounge. As helpful as it was, their version had quotes around c:/php/php-cgi.exe and if you do that it WILL NOT START php-cgi.exe, at least on Windows Server 2012, and you get HTTP 500. Took me a painful few days to figure that out.
Starting PHP v5.3.3, FPM Server-API [SAPI] support has been integrated into core PHP. This means, you can take PHP's source codes and compile and build them with FPM-SAPI [using --enable-fpm configuration parameter] support, instead of let's say Apache SAPI [--enable-apx2]. As shown in PHP-Wiki you can build PHP almost the same way you do in *nix systems - that is, configuration-wise. I would suggest you learn the ins and outs of building PHP in *nix systems first, and even try to do it yourself [usual configure, make and make install pattern], and then try to utilize the experience gained from it to build on Windows environment.
In addition to --enable-fpm configuration parameter, there are two additional parameters as well: --with-fpm-user=USERNAME_HERE and --with-fpm-group=USERGROUPNAME_HERE. These two work in *nix environment, but may not be available in Windows.
Overall, I am pretty sure you can build your own PHP-FPM server app on Windows using Visual Studio IDE. There are no official PHP-FPM builds as of the date of this writing.
EDIT 1: Ok, guess I might be wrong re the possibility of building PHP-FPM on Windows, since this SAPI uses libevent component from *nix environment. Guess you will have to stick with Cygwin-bundled installation after all.
PHP-FPM is only available to linux as of now. There are some sites that provides a tutorial on how to get php-fpm to run on windows, under cygwin. You can try those guides.
On Windows, when you run PHP with IIS and install the "PHP FastCGI" module, you get similar functionality to what is explained about PHP-FPM. In other words, this is not the official PHP-FPM code base, but just similar functionality.
For one, IIS would spawn multiple php-cgi.exe processes (worker processes). And any PHP requests that come in will be handed down to a worker, IIS will dynamically spawn more workers depending on the server resources. These settings are configurable under the "Fast CGI" options for the server tree node on IIS.
That said, I believe performance-wise the php-cgi.exe is not on par with Apache servers.
You can view the installation procedure for IIS 7 here: https://learn.microsoft.com/en-us/iis/application-frameworks/install-and-configure-php-applications-on-iis/using-fastcgi-to-host-php-applications-on-iis
FastCGI addresses the performance issues that are inherent in CGI by providing a mechanism to reuse a single process over and over again for many requests. Additionally, FastCGI maintains compatibility with non-thread-safe libraries by providing a pool of reusable processes and ensuring that each process handles only one request at a time.
PHP-FPM uses mainly *NIX specific features and is not likely to ever be ported to Windows. In the end there really isn't the motivation, especially when considering php-cgi was developed to allow Windows specific services to configure it as a fork pool. Yes, they have their differences, but not enough so to push the community into a complete rewrite of PHP-FPM.
Keep in mind that php-cgi on Windows is not just multiple instances of a CGI, but uses a Windows managed pool of forked FastCGI processors which use the same architecture of PHP-FPM. Multiple processes complete the module initialization of PHP, and from these multiple forks are maintained (and restarted when needed) to handle requests. php-cgi hasn't been a CGI since at least as early as PHP3.

Resources