Flash Sale:75% Off Hosting + Free DomainEnds in13h47m14sView Plans
Hostvento logoHostvento

How to Change PHP Settings from the Command Line

This guide shows you how to view and change PHP settings using the command line on your server. It needs SSH access. On a VPS or dedicated server you also have root.

Domains and DNS2 min read7 steps

What are PHP settings?

PHP is a language that runs many websites. Its settings control things like how much memory a script can use, or how big an upload can be. They live in a file called php.ini. The command line is a text window where you type commands instead of clicking.

Step 1: Connect

  1. Open a terminal. On Windows 10 or later, you can use PowerShell.
  2. Connect with SSH. SSH is a safe way to control a server from far away.
ssh username@your-server-address

Use the details from your welcome email.

Step 2: See the current settings

php -i | grep memory_limit

This shows the current memory limit. Change memory_limit to any other setting name.

php --ini

This shows which php.ini files PHP reads.

The command line PHP may use a different file than your website does. Check the web value with a page that runs phpinfo(). Delete that page afterwards.

Step 3: Change a setting

Warning: A wrong value or a typing mistake can break your site. Back up the file first.
  1. Copy the file as a backup.
cp php.ini php.ini.bak

This keeps a safe copy.

  1. Open the file in a text editor.
nano php.ini

This opens the file in nano, an easy editor.

  1. Find the line to change, for example the following.
memory_limit = 256M
upload_max_filesize = 64M
post_max_size = 64M
max_execution_time = 300

Edit the numbers to what you need. Lines starting with a semicolon are comments and are ignored.

  1. Press Ctrl and O to save. Press Enter. Then press Ctrl and X to leave.
  2. Restart the web service so the change takes effect. On a VPS with root, the command is often this.
systemctl restart php-fpm

This restarts PHP. The service name differs by system, for example apache2 or php8.2-fpm.

Change a setting for one run only

php -d memory_limit=512M script.php

This runs one script with a bigger memory limit. Nothing is saved.

On shared hosting

You may not be able to edit the main file. Look in your control panel for a PHP settings tool, or ask support in a ticket.

Quick recap

  • PHP settings live in php.ini.
  • Use php --ini and php -i to look.
  • Back up, edit, save and restart the service.
  • Use php -d for a one-time change.