Controlling PHP settings with a custom php.ini file

Posted on by Liquid Web
Reading Time: 7 minutes

WordPress and cPanel are common web applications providing fast and customizable online experiences. If you’re running a website for your business that uses PHP, then you understand the benefits of the scripting language. Generally, websites have specific functions and features resulting from the scripting languages they use.

Website owners can control their applications' backend and frontend instructions depending on their business needs. With PHP, web admins can control their server’s functions by using custom files they create. So, let's learn how to control PHP settings with a custom php.ini file and configuring PHP in cPanel.

Key points found in this article

The key points found in this post will answer the following questions about the server-side scripting language known as PHP (the "P" in the acronym "LAMP") that many websites employ and its settings that can be managed in php.ini files:

  • What is PHP and which version of it is commonly used in web development?
  • What can PHP do for your web server?
  • What is a php.ini file and where can you find php.ini files?
  • How can you create a php.ini file?
  • Why do you need to use a custom php.ini file to control PHP?
  • What is a PHP directive?
  • Common PHP directives for web servers
  • How can you configure PHP to control settings using cPanel?

What is PHP?

To understand why controlling PHP settings with custom php.ini files might be necessary, you should first learn about PHP. PHP: Hypertext Preprocessor (PHP) is a free, open-source, server-related language popular for developing web applications. Web development uses two main types of languages: programming and scripting languages.

While scripting languages are technically programming languages, they add a specific function and run inside another program. Scripting languages are more straightforward and simple, and there are separate languages for the server side and client side of an application.

With PHP being a server-side scripting language, it follows instructions in a script format and sends a result to the web browser, usually in HTML format. PHP is primarily used for web servers, and it has been around for a while.

What PHP version is commonly used in web development?

If you know your computer history well, then you know that PHP was created in 1995. It’s expected that programming languages evolve as technology demands it, so PHP is at version 8 as of 2020. See our PHP 7 vs PHP 8 comparison article for more details.

PHP version 7 is the most widely used version and popular with content management system (CMS) platforms, like WordPress, which require at least 7.4 to function. That rule will change once WordPress enforces the minimum requirements for version 8. However, as of time of this article's publication, PHP 7.0 still had 77.5% of the market share.

Why do many companies prefer to use PHP when it comes to web development? Let's examine the reasons why.

What can PHP do for your web server?

There are many reasons PHP is an ideal scripting language for your server. PHP is updated regularly to support any changes in online technology, keeping the language fresh and versatile. Since WordPress still operates over 43% of websites running content management systems, it obviously has many benefits that businesses want.

Other benefits of PHP include:

  • Easy to learn — while some learning curves may be too steep, PHP makes it easier for beginners.
  • It’s multi-functional — as an independent platform, PHP works on any operating system. The scripting language works well for ecommerce, blogs, and social media websites.
  • It’s fast — thanks to PHP’s versatility, it’s faster than most other server-side languages. This makes PHP ideal for WordPress websites and search engine optimization (SEO).
  • PHP supports databasesdatabases store information for web servers, and since many relational and non-relational databases use PHP, it supports fast connections to databases.

PHP has excellent support, meaning that anyone building servers, applications, or websites can find quick troubleshooting solutions. Part of managing a PHP application is customizing it to fit your needs. As mentioned, admins can control PHP settings by creating a custom php.ini file. So, what is a php.ini file, and where are they located? Let's take a look in the next sections.

What is a php.ini file?

Any web server needs instructions to work how they’re designed, and they require these instructions in the form of configuration files. A php.ini file contains the server’s PHP settings. Your PHP settings send outputs to your website or application so they function in a specific way.

Examples of PHP functions can be setting file size limits or behaviors concerning error messages. Using a custom php.ini file, you can set your PHP-related rules to suit your or your customer’s needs.

Where can you find php.ini files?

Your php.ini files will have different locations depending on your server, your machine’s operating system, and the PHP version you’re using. When your system uses PHP, it will search for the file in several places. Your php.ini file could be in:

  • The installed PHP or web server’s directory.
  • The Server Application Programming Interface (SAPI).
  • The working directory. You can search this by using a getcwd() command.
  • The PHP Runtime Configuration (PHPRC) environment.

A php.ini file universally governs the configuration of all your server directories. Yet, in cases where unique settings for a specific directory are desired, a .user.ini file is used. This file governs the PHP settings of its corresponding directory, influencing only that location. However, if PHP is a versatile scripting language preferred by many users, why do you have to customize the files at all? Let's explore the rationale in the next sections.

Why do you need to use a custom php.ini file to control PHP?

Many established companies use PHP to build their servers and create unique experiences for their customers. Facebook and WordPress are just a couple that come to mind. There are many reasons users may want to use a custom php.ini file to control their PHP settings.

Take a WordPress website as an example to explain the concept; WordPress is built using PHP. If you have used WordPress, you know that the websites built with WordPress have customization features and plugins. Whether we’re talking about themes or plugins, WordPress has thousands of customization options.

For those features to work, they require edits to the php.ini files. When creating custom php.ini files, web developers use directives to manage certain behaviors.

What is a PHP directive?

You’ve learned what php.ini files are and their intended purpose, but how does customizing them specifically attach certain behaviors to them? Typically, server functions are programmed into php.ini files using PHP directives. A PHP directive is a set of instructions or scripts for the rules that govern the custom php.ini file functions.

Using different PHP directives, a web developer can add or change the way their web server or site behaves. While there is a much longer list of available directives, developers use common directives in virtual structures they design.

Common PHP directives for web servers

Each directive applies a unique function to a web server; it all depends on what features you want to use to shape your customer’s online experience. Here are several common PHP directives:

  • display_errors — this directive will display PHP error messages to the user using the on or off values. It’s typically used when developing your site.
  • upload_max_filesize — using this directive will determine the max file size allowed by PHP to be uploaded on your website. Users can edit this value.
  • session.cookie_lifetime — does your computer remember a site after you visit it? This memory may have to do with your cookie durations based on PHP settings. The default for this value is zero, meaning when visitors close their browser after visiting your site, their session is erased.

No two websites and applications function the same and that’s the beauty of the online experience. When admins want to customize PHP, they create php.ini files in a variety of ways.

How can you create a php.ini file?

Since php.ini files use text to provide scripting instructions, many users will use text editors to create their custom php.ini files. This example method described isn’t always the case, but many text editors like Notepad or TextEdit work well when used for this method. Creating one is straightforward and requires that you set each directive on a separate line as you make it. Once you’re done with your edits, you can save the file as .php.ini and upload it.

How can you configure PHP to control settings using cPanel?

There’s no doubt that creating a php.ini file in a text editor is a personal preference, but that doesn’t mean there isn’t a better way. Web developers can use the file manager found in cPanel to make their changes conveniently in the web server without using third-party tools to upload them.

If you’re using Apache, then you’ll want to make changes in the .htaccess file, but for simplicity’s sake, edit the php.ini file in cPanel’s MultiPHP INI Editor. Using the cPanel editor doesn’t take long and may reduce the chance of errors. Here are the steps involved:

  1. Access your cPanel and find the Software section. Then select the MultiPHP INI Editor to start editing PHP after ramping up on how to use the MultiPHP INI Editor in WHM and cPanel.
  2. Next, go to the directory where you want to control the PHP settings and select it. You may be using a dropdown menu to make your selections.
  3. Now, as if you were using a regular text editor, modify the PHP directives to apply the functions you need.
  4. Once you’re finished, save your custom file, and the changes should take effect.

Some developers check their work by making a PHPinfo_file in the directory where they made the changes. On many occasions, developers take this a step further and apply the changes they made to one directory to the entire site. How and what you do to control the PHP settings is up to you.

Wrapping up

PHP is a common and versatile scripting language that remains a cornerstone of web development. Knowing how to manipulate PHP settings and understanding the language isn’t a requirement for using your applications. However, understanding how to customize php.ini files can be helpful if you want to improve your site experience using themes and plugins.

No matter your reasoning, understanding how the PHP scripting language works could provide some unforeseen benefits to your business down the road. When considering hosting solutions, having reliable, affordable, and customizable experiences should be the industry standard. If you’re searching for access to dedicated server infrastructures and fast cloud-based hosting options, then Liquid Web has you covered.

For over 25 years, Liquid Web has made a name for themselves by offering simple but powerful hosting solutions for small businesses and larger enterprises. The team is trained to understand your business goals and to create a solution that gets you there faster. When you need a hosting solution for your next project, you can contact us for advice, or take advantage of our custom server migrations.

Latest Articles

How to install AWS CLI on Linux (AlmaLinux)

Read Article

Subdomain takeover — protect your website against it!

Read Article

Controlling PHP settings with a custom php.ini file

Read Article

Linux dos2unix command syntax — removing hidden Windows characters from files

Read Article

Change cPanel password from WebHost Manager (WHM)

Read Article