Posts Tagged ‘Http’

PHP Fatal Error: Call To Undefined Function Json_encode()

I just run into a problem, I deployed my php application on one of the production sever and a link started throwing the error PHP Fatal error: Call to undefined function json_encode()in the apache error logs. Here is what I did to fix it.

The code was working fine on my localhost machine because the local machine contained php of version 5.2.4 and php versions greater than 5.2 have json module built in. But on my production sever, Php version was 5.1.6. It was hactic process to upgrade the php version on non managed server.

Dont go around, the module can easily be installed via Pecl Module. But for Pecl module, its necessary that pear should be already present on your server. Install Pear Library with the following command:

yum install php-pear

Once the installation is over, you are ready to rock, run the following command to install json.

pecl install json

Once the installation is over, you will find json.so file located in you php modules directory. Normally php modules directory is /usr/lib/php/modules. Once you are sure that this module is available, simple add the following line to you /etc/php.ini file.

extension=json.so;

Now dont forget to restart apache service.

service httpd restart

Type php -m and you will find json loaded along with other modules of the php. Now your code will also work fine. Cheer!

How To Password Protect Directory Access Via Apache (HTTP)

I ran into a problem today, my team member asked me to password protect a directory in such a way that when someone access it via Web URL, it should first ask for password. Once user is validated then it should lead him/her to the actual web page.

Guess what is the most easy way to do it, I followed the following method and it worked perfectly. Since Apache is the web server and usually it is handling hundreds of websites on a single server so it is not a wise way to make changes in its configuration file often. We will achieve it via .htaccess.

Now go into the directory in which you wish to apply this restriction and create a .htaccess file (off-course if this does not exist already) and add the following lines with necessary modifications ( The only modification will be that you will need to change the path of the root directory of your applicaton).

AuthType Basic

AuthName “Admin”

AuthUserFile “/var/www/html/MYAPP/passwd”

require valid-user

Now create a file with name passwd at /var/www/html/MYAPP/ path and add the username and password in the following formate:

admin:K1/BaQTbqe0Eo

where admin is the username and the encrypted value after: is the password.

Restart apache service and you will be seeing the login prompt appearing on application launch.