After following the documentation, my new OPCache settings are like this:
opcache.preload_user=www-data
opcache.preload=/var/www/vhosts/.../httpdocs/.../var/cache/prod/App_KernelProdContainer.preload.php
opcache.memory_consumption=1024
opcache.interned_strings_buffer=256
opcache.max_accelerated_files=20000
opcache.validate_timestamps=0
By default, inside var/cache/prod folder there is a file named srcApp_KernelProdContainer.preload.php.
After deleting /cache folder & restarting PHP-FPM, App_KernelProdContainer.preload.php is not created.
Should I rename App_KernelProdContainer.preload.php to srcApp_KernelProdContainer.preload.php or am I missing something else?
No, you shouldn't add this file directly to your PHP settings, since as you discovered it makes the whole thing very brittle. You should also not rename it or anything, since it's generated automatically.
What Symfony does in latter versions is create a "preload" file.
The Symfony 4 flex recipe includes this one.
<?php
if (file_exists(dirname(__DIR__).'/var/cache/prod/srcApp_KernelProdContainer.preload.php')) {
require dirname(__DIR__).'/var/cache/prod/srcApp_KernelProdContainer.preload.php';
}
if (file_exists(dirname(__DIR__).'/var/cache/prod/App_KernelProdContainer.preload.php')) {
require dirname(__DIR__).'/var/cache/prod/App_KernelProdContainer.preload.php';
}
On Symfony 5.1+ you have something like this.
Notice that what this file requires the preload script conditionally. This way, if it doesn't exist, it won't just kill the PHP interpreter.
If you do not currently have this file; you can create it manually, or just copy it from the recipe.
Add this file to your opcache.preload settings on php.ini, not the generated preloading script directly.
Related
I'm not satisfied by the Symfony Dotenv default behaviour, because I would like to have i.e. a .env.override which would override existing environment values.
So I would like to add the following code in config/bootstrap.php
$envLocal = dirname(__DIR__).'/.env.override';
if (file_exists($envLocal)) {
(new Dotenv(false))->overload($envLocal);
}
Is it a problem to edit this file (config/bootstrap.php)? Can it be erased by future Symfony updates?
You can modify bootstrap.php to your heart's content.
The file is created when you run create-project symfony/skeleton, but it's part of your application files (it's not a dependency), so it's your responsibility to maintain it, and use it as you see fit.
Actually, if you upgraded your application to a version of Symfony that expected a different behaviour of bootstrap.php (or public/index.php, or (bin/console) you may need to update these files (among others).
I have installed a security solution in my Joomla website,and it's suggest that to put the configuration.php file above the Public_html Folder,how could it be possible?
how to tell the CMS to recognize the new location?
is the solution would be valid in all versions of the Joomla CMS? ,if it's not,so please
write:
1st:Joomla 2.5 Solution.
2nd:Joomla 3 Solution.
you would need to modify the defines.php file located in the includes folder.
Specifically this line:
define('JPATH_CONFIGURATION', JPATH_ROOT);
And change JPATH_ROOT to the correct path.
But the problem with this is that you are modifying a core file so if an update changes the defines.php file it will overwrite your changes and will break your setup. You will need to reedit the file.
Also the JPATH_CONFIGURATION constant may be used for other things within the CMS that are not specifically trying to get the configuration.php file so make sure to check that it will not adversely affect other parts of the cms before doing this in production.
Alternatively you can change the frameworks.php file (also in the includes folder) directly to change from where the configuration is loaded from
ob_start();
require_once JPATH_CONFIGURATION . '/configuration.php';
ob_end_clean();
Just change the require_once line to the correct path.
Again since this is a core file it could be changed by an update. But this may also affect other parts if the config file is loaded manually in components or other parts of the cms.
Simply answer is don't do it. This would mean you would have to do what #Patrick has suggest which is correct and will work, however it means editing a core Joomla file. This is not a good idea as in your case, if you ever update Joomla, you will have to perform this change every time and it you forget (which is likely), your site will stop working completely.
I would strongly suggest you find a different "security solution" which does not involve having to modify any core Joomla files.
If you could define what you mean by "security solution", then maybe an alternative could be provided for you
I didn't dig for 'since when this has been implemented', But it can be done without changing the core.
Joomla looks for a defines.php in the root and if its present, imports it. And then if it finds a constant named _JDEFINES defined, it doesn't load the original file, effectively overriding it completely.
So, If you wish to override the defines its pretty easy and all you have to do is copy the contents of the defines.php file from under the webroot/includes/ path and paste it inside the one we created in the webroot. And you can change the following constant as per your taste.
define('JPATH_CONFIGURATION', JPATH_ROOT."/my/supersecret/directory");
Now there is one more thing left to be done and then we are good to go :)
You have to prepend the following lines to the top of our override file (the defines.php in the webroot).
define('JPATH_BASE', __DIR__);
define('_JDEFINES', 1);
This constant conveys to the framework that the defines have been overridden and to use the new file accordingly (Last time I checked, this flag/constant is checked at around 10 different places all over the framework eg. here, so its important)
Also I have seen this feature available with Joomla v2.5.0 and v3.8.8 as per your requirements in the question.
Edit: Remember you have to repeat the same procedure for administrator folder too if you want admin panel to work, and remember that administrator has its own /includes/defines.php
I know how to convert php file into phar file.
$phar = new PHAR('app.phar');
$phar->addFile('file1.php');
$phar->addFile('file2.php');
I thought it can be useful only for converting POPO to PHAR.
My question
Is it possible to convert entire Zend framework 2 web application to PHAR file? if yes, then How?
(or)
How to package Zend framework2 web application into a package? (except .zpk(zend studio package file) file format)
Updated: creating Phar from entire application
create-phar.php
$basePath = /path/to/;
$path = /path/to/application;
$phar = new Phar ('project.phar');
$phar->buildFromIterator(new RecursiveIteratorIterator(new RecursiveDirectoryIterator($path)), $basePath);
$phar->setStub("<?php
Phar::webPhar('project', 'public/index.php');
include 'phar://project/public/index.php';
__HALT_COMPILER();
?>");
index.php
<?php
include 'project.phar';
?>
Question:
When i run index.php it do not redirect to actual public/index.php file instead it shows blank page on the browser. How can I resolve this problem?
Thanks in advance
I deploy phorkie as a .phar file.
There are some things to consider:
Pack up all files in the .phar - php and static asset files (js, css, png, jpg), too. I use phing to do that. Do not forget the dependencies.
You need a stub file that runs Phar::webPhar() which takes care of sending out HTTP headers
Write your own .htaccess rewrite rule interpreter, because Phar::webPhar() does not do nice-path resolving on its own. I did that already.
Manually take care of sending out caching headers for static files
Hope that you (or your users) don't run into one of the Phar::webPhar bugs:
Symlinked files
No HEAD, PUT or DELETE support
Redirection loop with FPM (already fixed in git)
Hope that your user's web server handles .phar files (it will not; neither Debian nor Fedora ship that configuration)
Hope that the user's web server is correctly configured to handle .phar files with PATH_INFO appended (/path/to/file.phar/foo/bar.png), like in http://p.cweiske.de/122
Getting phorkie running from the .phar took me the evenings of two weeks. Now that it basically works it still is not a drop-phar-and-play solution, because the default configuration of web servers just doesn't play nice with .phar.
I have a php application that relies on several classes to function properly. If I take one of the application's class files
/my/folder/class.php
then move it somewhere else
mv /my/folder/class.php /my/other/folder/class.php
then in its place inside of
/my/folder/
I create a symlink to it called class.php via
ln -s /my/other/folder/class.php /my/folder/class.php
I would expect my application to be unaffected, but instead this is breaking it. I know the symlink is valid since at the command line I can do
nano /my/folder/class.php
and everything looks as I would expect it to. Am I missing something fundamental about the behavior of symlinks, and/or how apache or php processes them? Is it changing the working directory or $_SERVER['DOCUMENT_ROOT']? I can not figure out why this would have any affect on my application.
I am using Apache server in CentOs.
Thanks!
The only difference would be if you are using require_once or include_once and you are mixing the symlink path with the real file path. In this instance, the X_once is going to think those files are different and load it twice (which will of course cause problems if you define any classes or functions).
Would probably need an actual error message to guess any further.
How do I have Symfony 2 ignore hidden files? If I edit my source tree, my Mac puts all kinds of .AppleDouble directories everywhere and I get errors like this (when running a command via CLI):
The autoloader expected class
"Thing\CoreBundle\Command.AppleDouble\EnsureIndexesCommand" to
be defined in file
"/var/www/mysite.com/Symfony/app/../src/Thing/CoreBundle/Command/.AppleDouble/EnsureIndexesCommand.php".
The file was found but the class was not in it, the class name or
namespace probably has a typo.
The .AppleDouble directory contains a file that ends in "Command.php" which is picked up by Symfony which thinks it's a valid command file when it's just serving some OSX purpose.
I see that there's an ignoreDotFiles option that is set on by default in the Finder.php constructor, but it apparently has no effect:
https://github.com/symfony/symfony/commit/7ab3fdeb8325d5a72c44dc73214c97f366a11c4c
I have to clean the source tree before I run every command which gets old and makes the Mac filesystem & Eclipse unstable since those hidden files are there for a reason.