How to install PHP extensions on nginx? - php

I recently discovered NginX, and decided to try it out on my server. I have NginX running and able to serve PHP and HTML files. But now I want to try to install drupal. When trying to install it and check the requirements, I am stopped by one requirement.
PHP extensions Disabled
Drupal requires you to enable the PHP extensions in the following list (see the system requirements page for more information):
gd
I have tried to install gd by doing apt-get install php5-gd, and it says it is already installed. So I created a phpinfo() file, and checked to see if gd was enabled and I wasn't able to find it. Does this have to do with NginX or PHP? What do I do to fix this?

Since you are using Nginx - that must mean you are running PHP with PHP-FPM.
After you install stuff you need to:
sudo /etc/init.d/php-fpm restart
or
service php5-fpm restart
in newer ubuntu versions
so that PHP will pickup the new extensions.

If your web server setup is in order, only install the php gd extension and restart php scripting interpreter and web server.
sudo apt-get install php5-gd
sudo /etc/init.d/php-fastcgi stop
sudo /etc/init.d/php-fastcgi start
sudo /etc/init.d/nginx stop
sudo /etc/init.d/nginx start
Here's a great LEMP tutorial http://library.linode.com/web-servers/nginx/php-fastcgi/ubuntu-10.04-lucid

For future me if I forget this.
If you've been messing around with /etc/php/fpm then you may have accidentally lost the symlink to conf.d which means the gd and PDO load files won't be booted with FPM.
This will be an issue if you're just using the basic config that comes with PHP5-FPM. If you have a custom config you may included the files in a different place.
Solution: Recreate the sym-link.
cd /etc/php5/fpm
sudo ln -s /etc/php5/conf.d /etc/php5/fpm/conf.d

PHP extensions have only to do with PHP. Your choice of webserver (apache, nginx, etc) do not affect them. Most likely you just need to enable the gd extension. If you are on Ubuntu, check /etc/php5/conf.d folder and add a gd.ini with the following line:
extension=gd.so

if you are using centos 7 and you can't find /etc/init.d/php-fpm, you may try systemctl restart php-fpm, that worked for me.

I encountered the same problem with making sudo apt-get install php5-gd to work. Console output suggested to do sudo apt-get update. Just basic updating on all your packages.
After updating, I run sudo apt-get instal php5-gd and it did all heavy lifting for me, including restarting php5-fpm and correctly installing everything in between.

Related

Warning: mCrypt extension needs to be loaded for OpenCart to work

I'm trying to install OpenCart but get the following warning:
"Warning: mCrypt extension needs to be loaded for OpenCart to work!"
Since I'm a noob on this, could someone point me in the right direction on how to solve this? Google don't really help me out here :(
Thanks!
I solved this issue by put in COMMENT the error message validation for mCrypt inside the file
/install/controller/install/step_2.php change inside private function validate()
//if (!function_exists('mcrypt_encrypt')) {
// $this->error['warning'] = $this->language->get('error_mcrypt');
//}
and voila
and after install this extension
Then, you may want to try this extension:
(https://www.opencart.com/index.php?rout ... n_id=35487)
So you said you have FTP access and you can edit php.ini.
If the server has mcrypt installed but not enabled then if you add:
extension=mcrypt.so
then save php.ini and upload, this should work.
Note that some servers don't load user's php.ini, instead they are looking for a .user.ini file in root folder.
I would suggest you, if my above answer doesn't help you to contact your hosting provider.
If you're using a linux system and you have access to the console, you can just activate the mcrypt module in the php.ini.
Type into your console:
$ sudo php5enmod mcrypt
This will enable the module. If you are using PHP 7 instead of PHP 5 use phpenmod instead.
If you get an error, install the module first with
$ sudo apt-get install php5-mcrypt
or for PHP 7 with
$ sudo apt-get install php7.0-mcrypt
After this you have to restart your webserver. Use this command for apache2
$ sudo service apache2 restart
or this command for nginx
$ sudo service nginx restart
If you dont have access to your terminal by any reason, it could be possible to enable it trough the control panel (cPanel, Plesk, ...). In the most cases it's a one-click activation and not really complicated.
In case you are using apache2 on ubuntu :
First try to enable mcrypt using command:
sudo phpenmod mcrypt
If mcrypt is not installed, install it using below commands for PHP
PHP 5.6 :
sudo apt-get install php5.6-mcrypt
PHP 7.0:
sudo apt-get install php5.6-mcrypt
Enable mcrypt after insatallation and restart apache
sudo phpenmod mcrypt
sudo service apache2 restart
The only solution that always works with me it to use PHP 5 & mySQL 5 (5.x anything)
And in the hosting, assign the php version 5 (outdated) to the website, also make sure that the database is mySQL (5.x)
Thanks

call to undefined function mb_strimwidth

Months ago I made a short code that uses mb_strimwidth() to exactly fit some text into a table cell, putting dots at the end of a truncated string.
Now, after some times, I tried to execute that same code and it went out with this error:
Fatal error: Call to undefined function mb_strimwidth() in ...
I tried to find the mbstring.php file, and when I found the mb_strimwidth() function, I discovered that it is not implemented anymore. How is that possible?
But my main question is: how can I get the same result as mb_strimwidth()?
I thought to rewrite the function using a loop and mb_strwidth(), but ALL the functions in that mbstring.php file are empty.
All mb_* functions are provided by a PHP extension called Multibyte String, internal name mbstring
You probably don't have the extension active or installed. On most Linux distros you can install the package php-mbstring to install and activate this extension.
Apache needs to be restarted afterwards if you are using mod_php
Just got this issue, if you are using linux just install the package php-mbstringand restart Apache.
sudo apt-get install php-mbstring
sudo service apache2 restart
If you are using specific PHP version, you may need to run the following:
sudo apt-get install php7.x-mbstring
sudo service apache2 restart
Replace 7.x by the exact PHP version.
u need to install php-mbstring package try.
check php version
php -v
then check mbstring already install and enable
php -i | grep mbstring
if not installed run this command
sudo apt-get install php-mbstring
if you are php other version example : 7.1, 7.2, 7.0 based on
run command like this :
sudo apt-get install php7.1-mbstring
if you are using nginx server for run laravel .. then check nginx configration file which version u have loaded in conf file..
go to cd /etc/nginx/sites-available and open your configuration file..
if you are loading php7.2 version in nginx conf file..
fastcgi_pass unix:/var/run/php/php7.1-fpm.sock;
then u need to install 7.2 mbstring package..
sudo apt-get install php7.2-mbstring
and restart apache2 server
sudo service apache2 restart
if you already installed mbstring then you have to call this extension on php.ini file.
First, detect where is your php-fpm.ini file or php.ini.
run command
php -i | grep php.ini
it returns you path of php.ini file.
for example
/etc/php.ini
then open file with VIM or another editor
vim /etc/php.ini
and then add mbstring extension to php.ini file
extension=mbstring.so;
finally, restart php-fpm
systemctl restart php-fpm

How can I run things off Netbeans on Ubuntu? Localhost not working

When I try to run something on Netbeans using Ubuntu, a window opens but nothing actually works. I'm pretty sure it's because my http://localhost/ isn't working. So, how do I get that to work so I run files on Netbeans? Any specific step-by-step instructions would be great. I heard I had to install Apache, but I'm not sure.
If you want to run PHP stuff outside NetBeans, there are several steps you have to take:
Install apache web server - sudo apt-get install apache2
Install PHP and connect it with apache - sudo apt-get install php5 sudo apt-get install libapache2-mod-php5
Restart apache - sudo /etc/init.d/apache2 restart
Now, your Document Root (web root) should be at /var/www.
Place your files there and access them with http://localhost/desired_file.php with some web browser or just execute them with php compiler on the command line.
Depending on your distro/version, there might be some configurations to be done, but that's the basic stuff you need to run PHP outside NetBeans

Install Tidy, PHP

I guess when php was installed on my box --with-tidy arg was not included.
When browsing my php.ini the line:
;extension=php_tidy.dll
is missing.
How can I add the module to my php install? Note I tried adding:
extension=php_tidy.dll
but with no luck.
I checked the docs but all they say is:
This extension is bundled with PHP 5 and greater, and is installed using the --with-tidy configure option.
On Ubuntu, you can add tidy to your php5 installation by running this command in a terminal:
$ sudo apt-get install php5-tidy
If you want to check if it is already installed or validate that the command above worked:
$ php -i | grep libTidy
libTidy Release => 25 March 2009 // means tidy is installed
To install both php5 and tidy at the same time, use this command (as an alternative to the "--with-tidy" configuration option):
$ sudo apt-get install php5 php5-tidy
For PHP 7 just run
sudo apt-get install php-tidy
And restart Apache, That's it :)
Update: Thanks to #Arnis Juraga
For the version above PHP 7, you can mention the version code as follows.
apt-get install php7.4-tidy
I was having the same trouble, and wrote up my solution here:
Installing Tidy 2.0 PHP extension on Ubuntu 10.10
http://web.onassar.com/blog/2010/11/16/installing-tidy-2-0-php-extension-on-ubuntu-10-10/
It works on newer versions of Ubuntu as well.
While it may not be the most direct route, it works well.
I hope it helps others.
Put that line in php.ini next to the other extension=...dll lines and make sure php_tidy.dll is in the directory configured in php.ini under extension_dir.
In ubuntu: you need to run the following command in terminal
sudo apt-get install php5-tidy
and the restart the server
sudo service apache2 restart.
For those who are having trouble enabling Tidy extension for PHP (using PHP handler for Apache server) on Windows (WAMP server), please note that you may be editing the wrong php.ini file. Assuming that WAMP server is installed in C:\wamp[ver]\ where [ver] is a variable version number.
File that you're probably editing:
C:\wamp[ver]\bin\php\php[ver]\php.ini
File that you must edit:
C:\wamp[ver]\bin\apache\apache[ver]\bin\php.ini
You also might want to make sure what's the correct php.ini file to edit by creating an info php file and add this code to it:
<?php phpinfo();
Then look for Loaded Configuration File string.
Finally make sure you uncomment this line within the correct php.ini file:
extension=tidy

What's needed for PHP's mcrypt_decrypt()?

I have a script that uses mcrypt_decrypt() function, but I get the following error
Fatal error: Call to undefined function mcrypt_decrypt()
What modules/libraries do I need to include to use this function? Or is there another reason I'm getting the error?
Thanks
sudo apt-get install php5-mcrypt
works on ubuntu.
Please see:
Mcrypt Requirements
Mcrypt Installation
You need to compile your PHP with --with-mcrypt[=DIR] and have libmcrypt Version 2.5.6 or greater on your machine.
Configure php5-mcrypt with php5-fpm (Ubuntu 14.04)
I’m going to assume you already have nginx and php-fpm installed and running.
php5-mcrypt should be installed already (it comes bundled with php5-fpm). Just for safety,
apt-get install php5-mcrypt
Create symlink to mods-avaliable,
ln -s /etc/php5/conf.d/mcrypt.ini /etc/php5/mods-available/mcrypt.ini
Enable it.
php5enmod mcrypt
Restart php-fpm,
service php5-fpm restart
Restart nginx,
service nginx restart
Done!
From the manual:
You need to compile PHP with the
--with-mcrypt[=DIR] parameter to enable this extension. DIR is the
mcrypt install directory. Make sure
you compile libmcrypt with the option
--disable-posix-threads.
Generally if PHP says a function is undefined, it means you need to compile in some library.
I above doesn't work, you can try this:
create mcrypt.ini file in /etc/php5/conf.d with content
extension=mcrypt.so
I upgraded PHP to 5.4 via http://php-osx.liip.ch/ and it worked.
for php 5.3.X
depends on availability of yum mcrypt package , you could use yum packeages
like this :
yum install php53-mcrypt
and restart httpd
And be carefull about the folder in the phpinfo page : "Scan this dir for additional .ini files" and the next : "Additional .ini files parsed ".
After upgrading to php 5.4 running (Works)
sudo php5enmod mcrypt
sudo service apache2 restart

Categories