How to Enable PHP Short Open Tags on Ubuntu/Apache

This guide explains how to activate PHP short open tags by editing the php.ini file on an Ubuntu server with Apache, shows the syntax differences between full and short tags, and provides the necessary commands to reload Apache after the change.

php Courses
php Courses
php Courses
How to Enable PHP Short Open Tags on Ubuntu/Apache

This article introduces the development environment used for the tutorial: Ubuntu 18.04 LTS server, MariaDB 10.1.34, PHP 7.3, and a macOS High Sierra workstation.

Enabling PHP short open tags can make scripts cleaner, especially when many files are involved. The traditional opening tag <?php can be replaced with the short form <?, and echo statements like <?php echo $data; ?> become <?=$data;?>.

To enable this feature, locate the php.ini used by Apache (e.g., /etc/php/7.X/apache2/php.ini) and set the directive short_open_tag = On. After saving the file, reload Apache with service apache2 reload so the change takes effect.

Note: When running PHP scripts via crontab, the file must still start with the full <?php tag; otherwise the script will not execute.

Example code snippets:

<?php
// do ...
?>

Short‑tag version:

<?
// do ...
?>

Echo example: <?php echo $data; ?> Short‑tag echo: <?=$data;?> Command to edit the configuration: $ nano /etc/php/7.X/apache2/php.ini Command to reload Apache:

$ service apache2 reload
PHPUbuntuphp-inishort_open_tag
php Courses
Written by

php Courses

php中文网's platform for the latest courses and technical articles, helping PHP learners advance quickly.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.