There was a problem loading the comments.

User Guide - PHP

Support Portal  »  Knowledgebase  »  Viewing Article

  Print

Applicable Plans - All General VPS Plans, All Plesk Plans

User Guide - PHP User Guide

PHP: Hypertext Preprocessor is a widely used, general-purpose scripting language that was originally designed for web development to produce dynamic web pages. - from http://en.wikipedia.org/wiki/PHP

PHP is a widely-used general-purpose scripting language that is especially suited for Web development and can be embedded into HTML - from http://php.net

Overview

This User Guide is designed to help you install and do some minor configuration to PHP on your VPS. This User Guide is not a tutorial on how to use PHP, or how to configure your application or sites to use PHP.

If you need assistance beyond what is included in this User Guide, you will need to consult the official PHP documentation or the documentation that came with your application for more information.

Installing PHP
PHP available versions

PHP Installed Features

PHP Installed Modules
PHP Info Web Page

PHP Configuration


PHP Accelerators and Loaders and Frameworks


Links to other information



Installing PHP

To install PHP, log in to the PBA Control Panel, and click on the System tab. If necessary, click on Select Another System (Subscription) link on the left and choose the correct Virtuozzo container.

If you are not sure if PHP is already installed, go to Applications and click on All Applications. If your VPS is running either Fedora or CentOS 4, PHP will be listed this way:
Apache module mod_php5 (the number may be a 4 or a 5)

If your VPS is running CentOS 5, PHP will be listed this way:
PHP-5

To see what operating system (OS) you have, click on the Subscriptions icon from the My Account tab of your PBA Control Panel. Click on the name of the subscription you want to see, and the OS for the subscription will be displayed near the top of the page.

If PHP is not installed, go to Applications, and click on the Add Application link. Find PHP in the list, and click the box next to it. Then scroll down and click the Next button.

This takes you back to the All Applications screen. Wait for about five minutes, and then click on the Refresh link at the upper right, just under the word Parallels. The application should now show as installed.

 If it still shows as Scheduled, wait another five minutes, and click Refresh again. If it still shows as Scheduled, or in Error state, please contact eApps Technical Support.

PHP available versions

The latest version of PHP is only available on plans running CentOS 5 or newer.

To see what operating system (OS) you have, click on the Subscriptions icon from the My Account tab of your PBA Control Panel. Click on the name of the subscription you want to see, and the OS for the subscription will be displayed near the top of the page.

To see the latest version of PHP currently available, go to the Application Index - http://www.eapps.com/applications/application-hosting-index.php - and look for the Programming Languages and Frameworks section. The latest version of PHP available will be listed there.
  • For plans running Fedora Core, the latest version of PHP available is 5.0.4.
  • For plans running CentOS 4, the latest version of PHP available is 5.2.0.
If you are running a Fedora or CentOS 4 plan, and need a newer version of PHP than what is available to you, then you will need to upgrade to a CentOS 5 plan. For information on migrating to a CentOS 5 plan, please contact eApps Technical Support.

If you have PHP installed and wish to see if there is an upgrade for your current version, then follow the steps in the User Guide - Upgrading Applications in the PBA Control Panel - http://support.eapps.com/hsp/upgrades


PHP Installed Features

Note Not all of these modules are available on the Fedora Core or CentOS 4 plans. This list is only correct for CentOS 5 or newer plans. If you are on a Fedora or CentOS 4 plan, use the php -m command from the command line to see the available modules.

PHP Installed Modules

This is a list of the PHP modules currently available. This information is found by using the command php-m from the VPS command line.

bcmath
bz2
calendar
ctype
curl
date
dba
dbase
dom
exif
filter
ftp
gd
gettext
gmp
hash
iconv
imap
json
ldap
libxml
mbstring
mcrypt
mhash
mssql
mysql
mysqli
ncurses
odbc
openssl
pcntl
pcre
PDO

pdo_pgsql
pdo_dblib

pdo_mysql
PDO_ODBC
pdo_sqlite
pgsql
posix
pspell
readline
recode
Reflection
session
shmop
SimpleXML
snmp
soap
sockets
SPL
standard
sysvmsg
sysvsem
sysvshm
tidy
tokenizer
wddx
xml
xmlreader
xmlrpc
xmlwriter
xsl
zip
zlib

If you are on a Fedora or CentOS 4 plan and the modules you need are not available to you, your best option is to upgrade to a CentOS 5 plan.

If you do not wish to do that, you may be able to install the modules you want manually, but that requires removing the eApps installed PHP, and compiling your own PHP from scratch.

Be aware that doing this will take you outside the eApps support guidelines, and any assistance from that point forward will be billable at our standard rate of $90/hr.

PHP Info Web Page

You can also see what features and modules are available in PHP by using a PHP Info web page. To do this, you will need to either create a file on the VPS from the command line, or upload a file from your local computer.

The file must go in the DocumentRoot for one of your sites (it does not matter which site - the PHP settings are global). To see the DocumentRoot for a site, go to the Control Panel, Site tab for that site, Website Settings. The DocumentRoot is listed in the General section.

The file must be called info.php, and the contents are as follows:

#!/usr/bin/php
<?php
phpinfo();
?>

The file must be plain text - you cannot create this file in a word processor like Word or Open Office, you must use a plain text editor like vim or Notepad or TextEdit.

Once the file is in place, you can access it by going to your site and appending info.php to the URL: http://eapps-example.com/info.php

This page will show all the installed modules, as well as copious information about their options and other information about the PHP installation.

Once you've found the information you need, eApps recommends either removing this file or renaming it so that you are not giving away too much technical information to those who might have malicious intent.


PHP Configuration

For the majority of users, PHP as installed should require no additional configuration. However, it is possible to change some PHP settings, as well as install additional modules using Pear and Pecl.

Making changes to php.ini

The main configuration file for PHP is called php.ini, and is located in the /etc directory. Before editing this file, make a backup first just in case you need to roll back your changes. It is also a good idea to copy the line you are editing, comment it out, and then edit the new line. That way you can see what the original value for that setting was.

Tech tip The php.ini file has over a thousand lines and hundreds of settings. eApps technically offers no support for any edits you make to php.ini, but can assist with a few specific functions.

If you need to make major edits to php.ini, you will need to reference the official PHP documentation and the PHP community for support. A listing of all the values in php.ini can be found here: http://php.net/manual/en/ini.core.php

The php.ini file can be edited either from the command line, or from the File Manager in the Control Panel. After you have made the edits to the file, you will need to restart the Apache web server for the changes to take effect.

Control Panel

To edit php.ini from the Control Panel, click on the System tab. If necessary, click on the Select Another System (Subscription) link on the left, and choose the correct Virtuozzo container.

Click on File Manager, and navigate to the etc directory. Depending on the size of your screen, you may have to scroll several pages to find the php.ini file (not the php.d directory).

Click the box next to php.ini, and then scroll up and click on Copy. The File Manager is somewhat limited in what it allows for copying a file, so you will have to make your copy outside of the current directory.

For the Destination path, click Select, and pick the home directory. Leave the default of Do not move if the destination file or directory exists already checked. The other two options should be unchecked.

Click OK to copy the php.ini file to the home directory.

Once the file copy has been made, navigate back to the php.ini file. Click the check box next to the file again, and then click on Edit at the top of the screen.

This opens the php.ini file for editing. To copy a line, just highlight the line, and use the Copy and Paste functions in the browser. Then comment out the original line using a semi-colon (;) and make your edits to the new line.

Leave the Select line ends type at the default of Unix (LF).

Once you have made your edits, click OK to save your changes, or Cancel to cancel editing.

You will need to restart the Apache web server before any changes you have made will take effect. To do this, click back on the System tab, and then on Web Server. Click Restart to restart the web server.

If you get an error when restarting the web server, then copy your newly edited php.ini file to another location ( not home), and Copy your original php.ini file back into place, and restart the web server. If you are still having problems starting the web server, please contact eApps Support for assistance.


Command line

To edit php.ini from the command line, you will need to be able to log in to the VPS using SSH, and work as the root user. For more information on connecting to the VPS via SSH, see the SSH User Guide - http://support.eapps.com/hsp/ssh . You will also need to know standard Linux commands, and be able to edit files using the vim or vi editor.

[root@eapps-example ~]# cd /etc/
[root@eapps-example etc]# cp php.ini{,.orig}
[root@eapps-example etc]# ll php.ini*
-rw-r--r-- 1 root root 45912 Feb 27 12:52 php.ini
-rw-r--r-- 1 root root 45912 Apr 22 11:54 php.ini.orig
[root@eapps-example etc]#

Edit the file, making sure to copy the lines you are changing first, and commenting out the original line using a semi-colon (;). Make your changes to the new line.
Once you have made your edits, save and exit the file. Then restart the web server so that the changes will take effect.

[root@eapps-example etc]# service httpd restart
Stopping httpd:                                            [  OK  ]
Starting httpd:                                            [  OK  ]
[root@eapps-example etc]#

If the web server gives an error on restart, move your original php.ini file back into place, and try to restart the web server again. If this works, double check your edits to php.ini to make sure they are correct. If you are still having issues, contact eApps Support for assistance.

Common Changes to php.ini

While no change to php.ini is specifically supported, there are a few changes that eApps recommends to help improve the performance of your sites, or to assist in troubleshooting.

Display Errors

By default, all PHP errors are sent to the error_log for the site, which is located one directory above the site DocumentRoot (if the DocumentRoot is /home/webadmin/eapps-example.com/html, the error_log is located at /home/webadmin/eapps-example.com/error_log )

Read the warnings about changing this value carefully, and do not enable this for a production site. Only use this for testing.

; Print out errors (as a part of the output).  For production web sites,
; you're strongly encouraged to turn this feature off, and use error logging
; instead (see below).Keeping display_errors enabled on a production website
; may reveal security information to end users, such as file paths on your
; Web server, your database schema or other information.
;
; possible values for display_errors:
;
; Off          - Do not display any errors
; stderr       - Display errors to STDERR (affects only CGI/CLI binaries!)  
; On or stdout - Display errors to STDOUT (default)

; To output errors to STDERR with CGI/CLI: display_errors = "stderr"
;
; Default
;
display_errors = Off

Memory Limit

The Memory Limit is the amount of memory a PHP script can use. If the script tries to use more memory than the Memory Limit allows, the script will usually fail.

Be careful about increasing this value. If you increase this value too high, and do not have enough free memory on your VPS, you will experience problems with the VPS such as slow performance or even application crashes.

memory_limit = 32M   ; Maximum amount of memory a script may consume (16MB)

Maximum Upload Size

The default maximum upload size for a file is 2 MB. To increase that value, increase the maximum file size allowed for upload. Be careful of changing this value too high. If you allow very large files to be uploaded from a PHP based application, the amount of system resources needed for that may cause performance issues with your VPS.

; Maximum allowed size for uploaded files.
upload_max_filesize = 2M

Short Open Tags

In older versions of PHP, the short open tag, where PHP scripts were allowed to start with <? instead of the correct <?php, were allowed, but discouraged.

In PHP 5, short open tags are not allowed by default. If you have PHP code that worked on an older VPS or version of PHP but is now showing a blank page with PHP 5, short_open_tag might be the issue.


Read the warnings about short open tags before making this change.

; Allow the <? tag.  Otherwise, only <?php and <script> tags are recognized.
; NOTE: Using short tags should be avoided when developing applications or
; libraries that are meant for redistribution, or deployment on PHP
; servers which are not under your control, because short tags may not
; be supported on the target server. For portable, redistributable code,
; be sure not to use short tags.
short_open_tag = Off

Installing Additional PHP Modules with Pear and Pecl

If you have a CentOS 5 VPS, your PHP has both pear and pecl installed, so you can install any modules from the http://php.net web site. On a VPS with CentOS 4 installed, pecl might not be available, depending on the version of PHP installed. On Fedora plans, only pear will be installed.

Note eApps offers no support for any PHP modules you install yourself. If you need assistance with a self-installed module, please contact the developer for that module. Any assistance from eApps for a self-installed module will be billable at our standard rate of $90/hour.


To get the correct name for a Pear module, go the Pear packages page, and then click on the module itself. Then, click on the Download tab. The Easy Install section will have the correct command to install the module.

To get the correct name for a PECL module, go to the PECL packages page, click on the module name, and then look for the version you wish to install.

To install a Pear or PECL module, use the following commands:

[root@eapps-example ~]# pear install module-name

[root@eapps-example ~]# pecl install module-name


Once the module is installed, it will need to be loaded into PHP so that it is available for use. To load the module into PHP, you will need to create a file in the /etc/php.d directory called module_name.ini that will contain the line:

extension=module_name.so

Do not use extension version numbers, just use the extension name.

Use one file for each extension. Also, some modules have their own list of variables, and those should be in the extension file, not in php.ini. Read the documentation for each module to see if you need to configure any variables for your modules.

Default Pear and PECL Modules

There are several Pear modules installed with PHP. To see them, use the pear list command. There are no Pecl modules installed by default. Use the pecl list command to see any that you install manually.

[root@eapps-example ~]# pear list
INSTALLED PACKAGES, CHANNEL PEAR.PHP.NET:
=========================================
PACKAGE          VERSION STATE
Archive_Tar      1.3.3   stable
Console_Getopt   1.2.3   stable
PEAR             1.8.0   stable
Structures_Graph 1.0.2   stable
XML_RPC          1.5.1   stable
XML_Util         1.2.1   stable
[root@eapps-example ~]#


After adding the extension files to the php.d directory, you will need to restart the web server so that the extensions will be loaded into PHP.

[root@eapps-example php.d]# service httpd restart
Stopping httpd:                                            [  OK  ]
Starting httpd:                                            [  OK  ]
[root@eapps-example php.d]#

Using PHP Sqlite2

For backwards compatibility reasons on CentOS 5 we have added support for the old sqlite version 2 with PHP.

To install PHP Sqlite2, you will need to have yum installed on your VPS (yum is available for CentOS 5 only). For more information on installing and using Yum, see the User Guide - yum http://support.eapps.com/hsp/yum.

To install php sqlite2, use this command:

yum install php-sqlite2

The PHP Sqlite2 extension is useful if you encounter an error that looks like this:

'PHP Fatal error: Class 'SQLiteDatabase' not found in... '

PHP Accelerators, Loaders and Frameworks

There are several applications available that can improve the speed of your PHP code, allow you to run PHP code that is encoded by ionCube, and allows you to take advantage of the Zend framework.

Note None of these applications are available on Fedora Core plans. Only Zend Optimizer is available on CentOS 4 plans. You need to be on a CentOS 5 plan to have all these applications available to you. You will also need to be on a Standard Plus or greater plan. The Plesk and cPanel reseller plans also have some of these applications available.

To see what operating system (OS) you have, click on the Subscriptions icon from the My Account tab of your Control Panel. Then click on the name of the subscription you want to see. The OS for the subscription will be displayed near the top of the page. If you are not on a CentOS 5 plan, but would like information on updating your plan, please contact eApps Technical Support for more information.

These applications are installed from the Add Application link on the System tab of the PBA Control Panel.

eAccelerator

eAccelerator is a free and open source PHP accelerator, optimizer and dynamic content cache. It increases the performance of PHP scripts by caching their compiled state to almost completely eliminate the overhead of dynamic compilation. It also optimizes scripts to speed up their execution. eAccelerator typically reduces the VPS load and can increase the speed of your PHP code by up to 10%.

ionCube Loader

The ionCube Loader application allows you to execute ionCube encoded files. ionCube develops software products for PHP, including an encoder that protects and encrypts software written in PHP.

This is not the ionCube PHP Encoder. That product is only available from ionCube and requires a paid license.

Zend Framework

You can use the Zend Framework to build your PHP applications. The Zend Framework is only available in the General VPS plans (not Plesk or cPanel).  By default, it will be installed in /usr/share/php/Zend/, and does not require the full path, only the Zend/file.php path.

For assistance in using the Zend Framework, you will need to read the official Zend documentation - http://framework.zend.com/

Zend Optimizer

Zend Optimizer is required to run Zend Guard encoded PHP scripts. This is usually the case when you have purchased a commercial application that is written in PHP and encoded with Zend Guard.

Zend Server

eApps offers the Zend Server. Please see the User Guide - Zend Server http://support.eapps.com/hsp/zend for more information.


In order to have eAccelerator, ionCube Loader and Zend Optimizer installed together, they have to be installed in this order in the /etc/php.d directory:

eAccelerator
ionCube Loader
Zend Optimizer

By default, they will install in this exact order, unless you change the names of the configuration files in the /etc/php.d directory.


Links to other information

PHP official website - http://php.net/
PHP documentation - http://www.php.net/docs.php
PHP support website - http://www.php.net/support.php


Share via
Did you find this article useful?  

Related Articles


On-Premise Help Desk Software by SupportPal

Categories

© Cloudscale365