Search This Blog

Wednesday, November 15, 2017

How to Find/Edit Location/Path of php.ini File in your Ubuntu/LAMP Setup

In some cases, you might have two PHP configuration files: one for the PHP command line and for the web server. If so, make the change in both php.ini files.

1. To Edit web server's php.ini file

Open any text editor of you choice like Gedit and Copy/Paste the following PHP code and Save the file as 'info.php' inside the Document Root folder of your Web Server. Usually the path to your Document Root should be something like '/var/www/html/'. Make sure to save your file under the 'html' folder.


Now access this file from a browser using the following URL: http://localhost/info.php

You should be seeing a page open as shown in the image below. The path to your 'php.ini' file will be under Loaded Configuration File. In my case the path was as follows: Loaded Configuration File    /etc/php/5.6/apache2/php.ini

How to Find/Edit Location/Path of php.ini File in your Ubuntu/LAMP Setup
Click on image to enlarge

2. To Edit CLI's 'php.ini' file

Open your Terminal (CTRL+ALT+T) and enter the following command:
 php --ini  

You should get output as shown in the image below. Here too you should be looking for the Loaded Configuration File path. In my case it was /etc/php/5.6/cli/php.ini.

Edit CLI's 'php.ini' file
Click on image to enlarge

Sunday, November 12, 2017

Type Juggling and Type Casting in PHP

Type juggling and type casting can be used to change a value's type. While programming, it's important to know the type of the value and use type casting or juggling to convert it to compatible types.

Type Juggling:

When PHP converts a value from one type of value to another, it is called type juggling. PHP does not require (or support) explicit type definition in variable declaration; a variable's type is determined by the context in which the variable is used. That is to say, if a string value is assigned to variable $var, $var becomes a string. If an integer value is then assigned to $var, it becomes an integer.

 $foo = "0"; // $foo is string (ASCII 48)  
 $foo += 2; // $foo is now an integer (2)  
 $foo = $foo + 1.3; // $foo is now a float (3.3)  

Type Casting:

When you explicitly set a type to change the value into another type, it is called type casting. PHP is a loosely typed language and assigns types to variables depending what is assigned to it. Variables coming from get/post and cookies etc are generally cast as strings rather than other types and there are often other times when you need to specifically cast a type in PHP as e.g. an integer.

An example of this in action is as follows, where $foo starts off as a string value and is then cast into an integer:

 $foo = '1';  
 echo gettype($foo); // outputs 'string'  
 settype($foo, 'integer');  
 echo gettype($foo); // outputs 'integer'   

Tuesday, November 7, 2017

Restarting Pulse Audio from Terminal

For whatever reason(s), you would like to restart our Pulse Audio, the following are the steps that will help you just do that:

In a standard setup running pulseaudio -k restarts the daemon. Nothing else to do.

In case PA is not running typing pulseaudio without further options will start the daemon using defaults in /etc/pulse/daemon.conf and /etc/pulse/

User-defined settings in 'home/.pulse/ ' or 'home/.config/pulse/' will override system-wide settings.

NOTE: In case of issues it will often help to delete these directories before restarting pulseaudio.

For details see PulseAudio Wiki.

Finally to restart PA from your terminal:

 sudo service pulseaudio restart  

With inputs from: How can I restart pulseaudio without logout?

Suspend Your Ubuntu System From The Terminal

If you would like to suspend your Ubuntu system from the terminal, then use the following command:

 sudo pm-suspend  

Top Magento Hosting:

Top 5 Posts (Weekly)