Networking

Unix and Linux network configuration. Multiple network interfaces. Bridged NICs. High-availability network configurations.

Applications

Reviews of latest Unix and Linux software. Helpful tips for application support admins. Automating application support.

Data

Disk partitioning, filesystems, directories, and files. Volume management, logical volumes, HA filesystems. Backups and disaster recovery.

Monitoring

Distributed server monitoring. Server performance and capacity planning. Monitoring applications, network status and user activity.

Commands & Shells

Cool Unix shell commands and options. Command-line tools and application. Things every Unix sysadmin needs to know.

Home » Commands & Shells, Web Design, WordPress

Web Hosting Providers and php.ini

Submitted by on October 9, 2009 – 4:07 pm 3 Comments

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. If your search on PHP has bought you here, then you might as well check out servermania.com/kb/articles/build-your-own-cloud/ on how you can access PHP on a server. 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. You could also check out Hostens.

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 like the WordPress Hosting, 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

Print Friendly, PDF & Email

3 Comments »

  • morbiusdog says:

    Hi ,
    I have downloaded a flash template and edited it as per my requirement. but contact form is not working well. There is php file for contact form the coding of php file is as follows.

    I want that when visitor fill the cotact form and click on send the data of contact of should be delivered on my email id which is gouri92@yahoo.com

    I have checked the action script of contact form toroughly every thing is ok. I am unable to understand why my contact form is not working. Pls help me…………..

  • toysruslover says:

    I have yahoo webhoisting and I am trying to install PHPMyDirectory, but first I need to install ionCube. I installed it in a couple different plaes in the directory though the installer provided, but I get this message when I try to go ahead and install PHPMyDirectory:

    Extensions Dir: /usr/lib/php/extensions/no-debug-non-zts-20020429 (NOT FOUND).
    The directory set for the extension_dir entry in the php.ini file may not exist, and run time loading will not be possible.
    Please ask your hosting provider or system administrator to create the /usr/lib/php/extensions/no-debug-non-zts-20020429 ensuring that it is accessible by the web server software or install ionCube in the php.ini file.

    I am an amateur so I don’t understand this, but I would appreciate yout help.

  • SKATEskum says:

    Hey guys, I have just installed a php download script from http://www.rwscripts.com. My web host is netfirms.com, and I’ve set it to PHP4 (same as the php script I got). However, after the installation was completed, I’m getting this error messege. “extension_dir does not exists /usr/local/nf/lib/extensions/no-debug-non-zts-20020429”

    I just googled extension_dir does not exists
    and found the FAQ from the site you got the script from:
    http://www.rwscripts.com/docs/index.php?title=Frequently_Asked_Support_Questions

    The extension_dir setting in php.ini should point to the real directory for SourceGuardian loaders to work (as well as any other dynamic PHP extension). This may be any directory on server. Common setting is /usr/local/lib/php/extensions. Please contact your server provider about this issue. They need to create this directory and alter the setting in php.ini and then restart the webserver. ”

    How do I get the php.ini from? I can’t find it in FTP. I don’t really understand

Leave a Reply

%d bloggers like this: