Search Our Database
How to enable the short_open_tag option in PHP
Introduction
The “short_open_tag” option in PHP allows the use of short tags (<? ?>) for PHP scripts, which can be useful for simpler code formatting. However, it is disabled by default in many server configurations to encourage the use of full PHP tags (<?php ?>). This guide explains how to enable the “short_open_tag” option in PHP to allow the use of short tags in your PHP scripts for easier coding and compatibility with older scripts.
Prerequisite
- SSH access to the server with root privileges
- Basic understanding of Linux Command Line and Services
- Basic understanding of PHP configuration
Step-by-step guide
Step 1: SSH into your server
- Access your server via SSH. Then run command below to gain root privilege.
sudo su -
Step 2: Locate and navigate to PHP configuration file
- To find out the PHP configuration file, you may run the command below. And look for Loaded Configuration File, which indicated the path of the PHP configuration file.
php -i | grep ini
- For server that are having control panel, such as DirectAdmin or cPanel, you may show different result. However, you will still look for the path that Loaded Configuration File indicate to.
Important Note: If you are having multiple PHP version and wanted to configure for all. The path will change according to your PHP version.
For example:
– PHP 8.3, the path will look like /usr/local/php83/lib/php.ini
– PHP 7.4, the path will look like /usr/local/php74/lib/php.ini
Step 3: Enable short_open_tag option
- Once you get the path, run the command to enter editor. For example, it will be like vi /etc/php.ini.
vi <path>
- Then press i to enable edit mode.
- Look for short_open_tag = Off and change it to short_open_tag = On.
- Press ESC then :wq to save the configuration.
- Run command below to identify the PHP service name.
systemctl | grep php
- Then restart the PHP service.
systemctl restart <PHP service>
- Verify PHP service status after restart.
systemctl status <PHP service>
Conclusion
By going through this guidance, you will be able to enable the “short_open_tag” option in PHP, allowing your scripts to use short PHP tags for quicker and cleaner code.
For additional assistance or if you encounter any issues, please contact our support team at support@ipserverone.com.