Knowledge Base

PHP script basics

This article provides essential information about running PHP scripts on A2 Hosting servers.

What permissions do I need to set for my PHP script files?

To avoid potential problems, you should set your PHP script file permissions to 755 (read, write, and execute permissions for the user, and read and execute permissions for the group and world).

Do I need to add a header (shebang) at the top of my PHP script files?

No. You do not need to add a #!/usr/bin/php header (shebang) to your PHP script files.

Can I use short tags in my PHP script files?

Yes, we have installed support for short tags with PHP. This means that you can write:

<? echo "Hello world"; ?>

Instead of:

<?php echo "Hello world"; ?>

What is the path to the PHP executable?

The absolute path to the PHP executable on A2 Hosting's servers is /usr/bin/php. The /usr/bin directory is in the default path, so generally you do not need to include the full path when you run PHP scripts from the command line. Just type the following command, replacing filename with the name of your script file:

php filename

However, if you want to run an alternate PHP version from the command line, you must specify the full path to the executable. To see the PHP versions that are available on your account, type the following command:

ls /opt/php

Each PHP version has its own directory in the /opt/php directory, and the PHP executable is located in the version's bin directory. For example, if you want to run a file named test.php from the command line using PHP version 5.5, type the following command:

/opt/php/php-5.5.0/bin/php test.php

What version of PHP is installed on my account?

Currently, you can use PHP version 5.3, 5.4, 5.5, 5.6 or 7.0.

  • To determine the command-line PHP version currently installed on your account, type the following command at the command prompt:
    php -v
  • To determine the PHP version that the Apache web server uses to process web pages on your site, log in to cPanel, and in the Software/Services section of the home screen, click PHP Version. You can also change the PHP version that Apache uses for web site files on this page.
On a semi-managed VPS or Flex Dedicated Server, you can install any version of PHP that you want.

What file extensions can I use for my PHP script files?

The default file extension for PHP script files is .php. However, you can define additional PHP script file extensions in an .htaccess file. For example, the following line demonstrates how to define the file extension .phtml for PHP script files:

AddHandler application/x-httpd-php5 .phtml

For more information about how to use .htaccess files, please see this article.

Do you run PHP in safe mode?

No, we do not run PHP on our shared servers with safe_mode enabled, because it can cause issues for scripts. Additionally, safe mode is deprecated in PHP 5.3.0, and completely removed in PHP 5.4.0.

More Information

For more information about PHP, please visit http://www.php.net.