Skip to content
Loading the editor only when it is ready

YAML to PHP INI Converter

Convert any YAML configuration into PHP INI format (php.ini-style). Top-level mappings become [sections], nested keys become key = "value" pairs — ready for PHP configuration use.

Use Cases

  • PHP Configuration — Generate php.ini-style config from YAML specifications
  • App Settings — Convert structured YAML configs into flat INI files
  • Legacy Systems — Produce INI format for older PHP applications
  • Deployment Scripts — Generate PHP INI configs from YAML templates

Example

Input (YAML):

database:
  host: localhost
  port: 3306
  name: myapp
app:
  debug: true
  log_level: error
  timeout: 30
session:
  lifetime: 3600
  gc_probability: 1

Output (PHP INI):

[database]
host = "localhost"
port = "3306"
name = "myapp"
 
[app]
debug = "true"
log_level = "error"
timeout = "30"
 
[session]
lifetime = "3600"
gc_probability = "1"

Understanding the PHP INI Format

The PHP INI format is the standard configuration syntax used by PHP's runtime engine (php.ini). It uses a straightforward structure:

  • Sections — Denoted by [brackets] to group related settings
  • Key-value pairs — Written as key = value within sections
  • Comments — Lines starting with ; are comments
  • All values are strings — Even numeric and boolean values are treated as strings

The PHP INI format is also used beyond php.ini itself — many PHP applications (phpMyAdmin, WordPress, Laravel Forge scripts) adopt INI-style configuration for simplicity.

YAML Nested to INI Section Conversion

YAML's hierarchical structure maps to PHP INI's flat section format through a simple conversion rule:

YAML Structure PHP INI Equivalent
Top-level keys [section] headers
Nested keys under top-level key = "value" pairs within section
Deep nesting (>1 level) Flattened with dot notation
Lists/arrays Not supported — converted to comma-separated strings
Booleans Quoted as strings ("true" / "false")
Numbers Quoted as strings

Use Case: php.ini Generation

PHP applications often need custom php.ini settings. Writing INI by hand is error-prone; starting from YAML makes configuration more maintainable:

PHP:
  display_errors: Off
  error_reporting: E_ALL & ~E_DEPRECATED & ~E_STRICT
  max_execution_time: 60
  memory_limit: 256M
  upload_max_filesize: 64M
  post_max_size: 64M
  max_input_vars: 3000
  date_timezone: UTC
 
OpCache:
  opcache_enable: 1
  opcache_memory_consumption: 128
  opcache_max_accelerated_files: 10000
  opcache_revalidate_freq: 2
 
XDebug:
  xdebug_mode: debug
  xdebug_start_with_request: yes
  xdebug_client_host: 127.0.0.1
  xdebug_client_port: 9003

Output (PHP INI):

[PHP]
display_errors = "Off"
error_reporting = "E_ALL & ~E_DEPRECATED & ~E_STRICT"
max_execution_time = "60"
memory_limit = "256M"
upload_max_filesize = "64M"
post_max_size = "64M"
max_input_vars = "3000"
date_timezone = "UTC"
 
[OpCache]
opcache_enable = "1"
opcache_memory_consumption = "128"
opcache_max_accelerated_files = "10000"
opcache_revalidate_freq = "2"
 
[XDebug]
xdebug_mode = "debug"
xdebug_start_with_request = "yes"
xdebug_client_host = "127.0.0.1"
xdebug_client_port = "9003"

Use Case: Application Deployment Configs

Deployment pipelines often need to generate PHP INI configuration from structured templates. This converter bridges the gap between YAML-based deployment tools and PHP applications:

database:
  host: ${DB_HOST}
  port: ${DB_PORT}
  username: ${DB_USER}
  password: ${DB_PASS}
  charset: utf8mb4
 
mail:
  smtp_host: ${SMTP_HOST}
  smtp_port: 587
  smtp_auth: true
  smtp_secure: tls
 
cache:
  driver: redis
  host: ${REDIS_HOST}
  port: 6379
  prefix: myapp_
  ttl: 3600

Output (PHP INI):

[database]
host = "${DB_HOST}"
port = "${DB_PORT}"
username = "${DB_USER}"
password = "${DB_PASS}"
charset = "utf8mb4"
 
[mail]
smtp_host = "${SMTP_HOST}"
smtp_port = "587"
smtp_auth = "true"
smtp_secure = "tls"
 
[cache]
driver = "redis"
host = "${REDIS_HOST}"
port = "6379"
prefix = "myapp_"
ttl = "3600"

Advanced Example: Full Application Config

server:
  host: 0.0.0.0
  port: 8080
  workers: 4
  timeout: 30
 
logging:
  level: debug
  format: json
  output: stdout
  sentry:
    dsn: https://example@sentry.io/1
    traces_sample_rate: 1.0
 
features:
  new_dashboard: true
  dark_mode: false
  beta_api: true
 
queue:
  connection: redis
  default: default
  connections:
    redis:
      driver: redis
      connection: default
      queue: default
      retry_after: 90

Output (PHP INI):

[server]
host = "0.0.0.0"
port = "8080"
workers = "4"
timeout = "30"
 
[logging]
level = "debug"
format = "json"
output = "stdout"
 
[features]
new_dashboard = "true"
dark_mode = "false"
beta_api = "true"
 
[queue]
connection = "redis"
default = "default"

Note that deeply nested keys (e.g. logging.sentry.dsn) produce only the top-level section. The converter extracts the first level of nesting for INI sections; deeper nesting is flattened.

How the Conversion Works

  1. Parse YAML — The YAML document is parsed into an in-memory object
  2. Extract top-level keys — Each top-level key becomes an INI section header
  3. Flatten nested values — Values under each top-level key become key = "value" pairs
  4. Quote values — All values are wrapped in double quotes for PHP INI compatibility
  5. Format sections — Sections are separated by blank lines for readability

Best Practices

  • Use YAML mappings — Only YAML mapping types at the top level produce valid INI sections
  • Avoid YAML lists — INI does not support arrays; lists are converted to comma-separated strings
  • Keep one level of nesting — Deeply nested YAML is flattened; prefer shallow structures for predictable INI output
  • Use double quotes — The converter quotes all values automatically for PHP INI compatibility
  • Validate output — Ensure the generated INI works with your PHP application before deployment

Related Tools

  • YAML to PHP INI — You are here
  • INI to YAML — Reverse conversion from INI to structured YAML
  • PHP Array to YAML — Convert PHP return arrays to YAML
  • YAML to ENV — Convert YAML to environment variable format
  • YAML Validator — Validate YAML input before conversion

FAQs

Q: How are nested YAML keys converted to PHP INI format? A: Top-level YAML keys become INI sections denoted by [brackets]. Nested keys under each top-level key become key = "value" pairs within that section. Deeply nested keys are flattened with dot notation.

Q: Is my YAML data sent to a server? A: No. All processing happens 100% in your browser. Your data never leaves your computer.

Q: Can I use environment variable placeholders? A: Yes. Values containing ${VAR} patterns are preserved as-is in the output, making it easy to use with env var substitution tools.

Q: How are boolean values handled? A: Booleans are converted to quoted strings ("true" / "false") for PHP INI compatibility.

Q: What about YAML lists/arrays? A: YAML lists at the top level are not supported (INI requires sections). Nested lists are converted to comma-separated string values.

Q: Can the converter handle YAML with comments? A: Yes. YAML comments are preserved in the output as INI-style ; comments where possible.

Related Tools

Try these complementary developer tools:

Popular Developer Tools

Most-used tools on LangStop