Table of Contents
How to Enable PHP Short Tags on Your Hosting Account
If you have ever encountered errors when running older PHP scripts or working with legacy web applications, there is a good chance that PHP short tags could be the culprit. Understanding how PHP short tags work, why they are sometimes disabled by default, and how to enable them on your hosting account is an essential skill for any web developer or website owner. In this guide, we will walk you through everything you need to know about PHP short tags hosting, including practical steps to get them working on the most common hosting environments.
What Are PHP Short Tags?
PHP short tags are an alternative, abbreviated syntax for opening PHP code blocks. Instead of writing the standard opening tag <?php, short tags allow you to simply write <? to begin a block of PHP code. Similarly, the short echo tag <?= can be used in place of <?php echo.
Here is a quick comparison of the two syntaxes:
Standard PHP tag: <?php echo "Hello, World!"; ?>
Short tag equivalent: <?= "Hello, World!"; ?>
Short tags were commonly used in older PHP applications and frameworks, and many legacy codebases still rely on them. However, they have been a point of contention in the PHP community because they can cause conflicts with XML declarations, which also begin with <?.
Why Are PHP Short Tags Disabled by Default?
Many hosting providers disable PHP short tags by default for a number of important reasons. Firstly, short tags can interfere with XML processing instructions, which start with the same <? characters. This can lead to unexpected output or broken pages when XML and PHP are used together.
Secondly, the PHP development team has historically discouraged the use of short tags to promote cleaner, more portable code. For a period, there was even discussion about removing short tags from future PHP versions entirely, although they remain available in current releases.
Despite these concerns, there are still many legitimate reasons why you might need to enable PHP short tags on your hosting account, particularly if you are working with older scripts, third-party plugins, or inherited codebases that rely on this syntax.
How to Check If PHP Short Tags Are Enabled
Before making any changes, it is worth checking whether PHP short tags are already enabled on your server. The easiest way to do this is by creating a simple PHP info file.
Using phpinfo() to Check Your Settings
Create a new file called phpinfo.php and add the following code:
<?php phpinfo(); ?>
Upload this file to your web server and visit it in your browser. Search the page for short_open_tag. If the value shows On, short tags are already enabled. If it shows Off, you will need to enable them using one of the methods described below. Remember to delete this file after checking, as it can expose sensitive server information.
Methods to Enable PHP Short Tags on Your Hosting Account
There are several ways to enable PHP short tags depending on your hosting environment and the level of access you have. Below, we cover the most common approaches.
Method 1: Editing the php.ini File
The most straightforward way to enable PHP short tags is by editing the php.ini configuration file. This is the main configuration file for PHP and controls a wide range of settings.
To enable short tags, locate the following line in your php.ini file:
short_open_tag = Off
Change it to:
short_open_tag = On
Save the file and restart your web server if you have the ability to do so. On shared hosting, changes to php.ini typically take effect immediately or after a short delay. If you cannot find an existing php.ini file, you may need to create one in the root directory of your hosting account or within the specific directory where your PHP files are located.
Method 2: Using a Custom php.ini on Shared Hosting
If you are on shared hosting and do not have access to the server’s main php.ini file, you can often create a custom php.ini file in your website’s root directory or within a specific folder. Simply create a file named php.ini and add the following line:
short_open_tag = On
Upload this file to the appropriate directory. Note that this method does not work on all shared hosting providers, so you may need to check with your host to confirm whether custom php.ini files are supported.
Method 3: Enabling PHP Short Tags via .htaccess
For Apache-based hosting environments, you can enable PHP short tags using the .htaccess file. Add the following line to your existing .htaccess file or create a new one in your website’s root directory:
php_value short_open_tag On
This method is particularly useful for shared hosting environments where you do not have direct access to the php.ini file. However, it is worth noting that this approach only works if your hosting provider allows PHP directives to be set via .htaccess. Some hosts disable this for security reasons.
Method 4: Using cPanel to Modify PHP Settings
Many hosting accounts come with cPanel, which provides a graphical interface for managing your server settings. If your host offers cPanel, you can often adjust PHP settings directly from the control panel without needing to edit configuration files manually.
To do this, log in to your cPanel account and look for the PHP Configuration, MultiPHP INI Editor, or Select PHP Version option. Within these tools, you should be able to find the short_open_tag directive and toggle it on. Once saved, the changes will apply to your hosting account immediately.
Method 5: Contacting Your Hosting Provider
If none of the above methods work for your particular hosting environment, the simplest solution is to contact your hosting provider’s support team directly. Most reputable hosting companies will be able to enable PHP short tags on your account upon request, either globally or for a specific directory. When getting in touch, clearly explain that you need the short_open_tag directive set to On and provide the reason for your request.
PHP Short Tags on VPS and Dedicated Servers
If you are managing a VPS (Virtual Private Server) or a dedicated server, you will have full root access and can edit the main php.ini file directly. After making the change and saving the file, restart your web server using the appropriate command for your setup, such as sudo service apache2 restart for Apache or sudo service nginx restart for Nginx with PHP-FPM. This will apply the changes across the entire server.
Important Considerations When Using PHP Short Tags
Before enabling PHP short tags on your hosting account, there are a few important points to bear in mind. Whilst short tags can solve compatibility issues with legacy code, they are not recommended for new development projects. Modern PHP best practices favour the use of full <?php tags to ensure maximum portability and compatibility across different server environments.
If you are planning to distribute your code or work in a team environment, relying on short tags can create problems when your code is deployed on servers where they are disabled. It is generally better to update legacy code to use standard PHP tags wherever possible.
For more useful guides on managing your hosting environment and web applications, visit the DA Manager blog, where you will find a wealth of practical tutorials and hosting tips.
Conclusion
Enabling PHP short tags on your hosting account is a straightforward process once you know which method suits your server environment. Whether you opt to edit your php.ini file, use .htaccess, adjust settings through cPanel, or contact your hosting provider, there is a solution available for virtually every type of hosting setup. Understanding PHP short tags hosting is particularly valuable when working with older codebases or troubleshooting compatibility issues. Just remember to use short tags responsibly and consider migrating to standard PHP syntax for any new projects you undertake.














