Web Hosting Providers and php.ini
The php.ini is the primary configuration file for the PHP – a popular scripting language used for Web development. Most Web hosting providers offer preinstalled PHP on their servers. However, not many hosting providers explain where to find and how to use the php.ini file. The following is a quick how-to designed for Linux-based hosting environments.
To follow the instructions below you will need to connect to your Web hosting provider via SSH. Most hosting providers offer access to a Unix shell. In some cases, however, you need to activate Unix shell access before you can use it. Contact your provider’s tech support for instruction on how to do this. If you are connecting from a Windows PC, you can use the free PuTTY terminal client to connect to your hosting provider.
When you sign up for a Web hosting plan, the root folder of your Web server is likely to be ${HOME}/public_html or ${HOME}/www, where $HOME is your home directory and “www” is usually a soft link to “public_html”. If your $HOME variable is not set (if entering “echo $HOME” produces no result – unlikely but possible), you can try the following command to determine your home directory:
grep `whoami | awk '{print $1}'` /etc/passwd | awk -F':' '{print $6}'
The default php.ini file can usually be found in /usr/local/lib/php.ini. If it is not there, you can search for it (usually in /usr) by running the following command:
find /usr -type f -name "php.ini"
Once you found the file, you need to copy it to your Web server’s root folder:
cp -p /usr/local/lib/php.ini ${HOME}/public_html/
Certain Web applications that use PHP require a copy of php.ini in every application subfolder containing *.php files. For example, many WordPress plugins would not work correctly unless there is a copy of php.ini in every plugin directory. As you may imagine, with so many copies of php.ini, making changes to this file can get very tedious. A better solution is to place a link from every directory to the php.ini located in the Web server’s home folder.
Below is the script that will analyze your Web server’s home directory, find every subfolder with *.php files, determine which ones do not already have a php.ini file or link, and create a link to the main php.ini file that you copied earlier. This way you will only need to modify the single php.ini file located in the Web server’s home folder.
#!/bin/ksh username=$(whoami | awk '{print $1}') homedir=$(grep $username /etc/passwd | awk -F':' '{print $6}') webhome="${homedir}/public_html" if [ ! -r "${webhome}/php.ini" ] then if [ -f /usr/local/lib/php.ini ] then cp -p /usr/local/lib/php.ini ${webhome}/php.ini else echo "File php.ini not found" exit 1 fi fi find "$webhome" -type d | while read dir do if [ `ls -als "$dir" | grep -c ".php"` -gt 0 ] && [ `ls "$dir" | grep -c "php.ini"` -eq 0 ] then echo "Linking ${dir}/php.ini" ln -s "${webhome}/php.ini" "${dir}/php.ini" fi done
Download the default php.ini
Download the above script. Before using, make the script executable: chown +x link_phpini.ksh
Popularity: 4% [?]




