Install and enable fileinfo extension in PHP 7 linux (centos,ubuntu)
- 24-07-2022
- trienkhaiweb
- 0 Comments
Preface: If you are a php coder and work with laravel, even when your code is under local, your code runs fine but in the environment dev linux (centos,ubuntu) if you have encountered InterventionImage in laravel error "unable to load dynamic library 'fileinfo'", then this is the article for you.
Mục lục
1. Check if the FileInfo extension is installed in the current environment:
php -i | grep fileinfo
If terminal says: fileinfo fileinfo support => enabled
Everything ok ! If not, go to step 2.
2. Check php version: if you don't have php, please install, if the command returns php's version, continue to step 3
php -v
3. Find the path of extension file info
find / -name fileinfo Câu lệnh này sẽ trả ra kết quả đường dẫn của fileinfo như sau tùy thuộc vào môi trường bạn cài đặt: /www/server/php/72/src/ext/fileinfo /svr-setup/php-7.4.16/ext/fileinfo
4. Move to the folder containing the fileinfo . extension
cd /www/server/php/72/src/ext/fileinfo Hoặc cd /svr-setup/php-7.4.16/ext/fileinfo
5. Find the path phpize
Phpize is a tool to compile PHP extensions, based on system information to create the corresponding configuration file. find / -name phpize Câu lệnh này sẽ trả ra kết quả đường dẫn của phpize như sau tùy thuộc vào môi trường bạn cài đặt: /www/server/php/72/src/scripts/phpize /www/server/php/72/bin/phpize
After getting the path information of phpize, make sure you are currently in the fileinfo directory using the cd command in part 3
6. Initialize extended settings
Gõ lệnh: /www/server/php/72/src/scripts/phpize hoặc /www/server/php/72/bin/phpize tùy đường dẫn phpize trong môi trường của bạn, nếu đúng, kết quả sẽ trả ra dạng như thế này: Configuring for: PHP Api Version: 20190902 Zend Module Api No: 20190902 Zend Extension Api No: 320190902
7. Find and create compilation configuration
Type the following command to find the path for php-config php-config
Once the path is found, type the following command: ./configure --with-php-config=/www/server/php/72/bin/php-config Với tham số "/www/server/php/72/bin/php-config" tương ứng với đường dẫn file php-config trong môi trường của bạn Nếu đúng, kết quả sẽ trả ra với dòng cuối tương tự như sau: configure: creating ./config.status config.status: creating config.h
8. Compile and install
Type the following command: make && make install Nếu thành công, kết quả sẽ trả về dạng: Build complete. Don't forget to run 'make test'. Installing shared extensions: /usr/local/lib/php/extensions/no-debug-non-zts-20190902/
8. Find the file php.ini and active extension fileinfo
;extension=fileinfo
(Uncomment – ";" in front of extension=fileinfo to enable extension
9. Type the command restart php-fpm
service php-fpm restart
After restarting php, run the command again to check fileinfo php -i | grep fileinfo
Good luck!