In this artice you will find out how to set required PHP options in Magento 2. Firstly, you need to make the following prerequisites before configuring the required PHP options:
Step 1. Make sure PHP is installed by entering the following command:
php -v
Step 2. Check installed extensions by entering the following command:
php -m
You need following modules to be installed:
Step 3. Check PHP settings:
realpath_cache_size=10M
realpath_cache_ttl=7200
It is recommended to enable PHP OPcache for performance reasons.
Now follow these steps to update the required PHP settings:
Step 1. When configuring Magento 2 PHP at this point, you need to find the php ini file to proceed with the settings.
Run the phpinfo.php file in your web browser and find the downloaded config file like this:
To locate the PHP command-line configuration, enter the following command:
php --ini | grep "Loaded Configuration File"
Now you need to find OPcache configuration settings:
These files are usually located in php.ini or opcache.ini. Their location may depend on your operating system and PHP version.
Here's how to find them:
For Ubuntu, OPcache settings are usually located in php.ini.
For CentOS with Apache or Nginx, OPcache settings are usually located in /etc/php.d/opcache.ini.
If not, use the following command to find it:
sudo find / -name 'opcache.ini'
nginx web server with PHP-FPM: /etc/php/7.2/fpm/php.ini
Modify all of the opcache.ini if you have more than one.
Step 2. Setting PHP options.
date.timezone =
;
; Increase realpath cache size
;
realpath_cache_size = 10 MB
;
; Increase ttl cache realpath
;
realpath_cache_ttl = 7200
Step 3. Set OPcache options.
Open the OPcache configuration file in a text editor:
What about running external PHP files in Magento 2?
Due to one of the security features of Magento 2, you cannot run the external PHP files by default.
The file names need to be added in the Nginx configuration to execute or you can allow all external files to run but it can break the security of Magento 2. So we don’t recommend doing it.
Want to get a custom solution without having to design and configure everything yourself? Use our Magento Custom Development Service. Experts will help you develop a high-quality individual solution for your business. Our developers are proficient in a wide stack of technologies, including PHP: Zend (2), YII (2), Laravel (2), Symfony (2), and other well?known frameworks.
Login and Registration Form