Cloud Service >> Knowledgebase >> Domains & DNS >> Setting Your PHP Settings in Command Line
submit query

Cut Hosting Costs! Submit Query Today!

Setting Your PHP Settings in Command Line

To set your PHP settings via the command line, you can use the php.ini file, environment variables, or command-line options when executing a PHP script.

1. Using the php.ini File

You can edit the php.ini file to set your PHP configurations globally:

Locate your php.ini file:
PHP hosting

This command will show the path to the loaded configuration file.

2. Open the php.ini file in a text editor:
PHP hosting

 

3. Modify the settings as needed. For example, to change the memory_limit:

PHP hosting

4. Save the file and exit the editor.

5. Restart your web server or PHP service to apply the changes:
PHP hosting

2. Using Command-Line Options

You can override php.ini settings directly from the command line when running a PHP script using the -d option:

PHP hosting

 

3. Using Environment Variables

You can set PHP settings via environment variables for the current session:

PHP hosting

 

Or directly for a specific setting:

PHP hosting

This method is useful for temporary changes that don't require editing the php.ini file.

4. Using .user.ini (for Web Servers)

If you're configuring PHP for a web application, you can use a .user.ini file in the root directory of your application:

1. Create or edit the .user.ini file in your web root directory:
PHP hosting

2. The settings in .user.ini will be applied for the current directory and all its subdirectories.

Summary

php.ini file: Global settings.

Command-line options (-d): Temporary, script-specific settings.

Environment variables: Temporary, session-specific settings.

.user.ini: Directory-specific settings for web servers.

Pick the approach that fits you be­st. Consider if you need the­ alterations to affect eve­rything, be short-term, or apply just to a certain script or folde­r.

Cut Hosting Costs! Submit Query Today!

Grow With Us

Let’s talk about the future, and make it happen!