Using PHP 5
Overview
This User Guide is designed to help you install PHP 5 on your Server, and to do some minor configuration. This User Guide is not intended to be a tutorial on how to use PHP. You will need to consult the official PHP documentation or any of the 100+ available books about PHP if you need to come up to speed on how to actually use the language. |
Installing PHP
Installing PHP using the command line
Installing PHP Extensions
Viewing installed PHP extensions
Installing additional PHP Extensions
PHP Configuration
Common PHP configuration changes
Changing PHP configuration using the command line
PHP Accelerators, Loaders, and Frameworks
Installing PHP
PHP can be installed from the command line of your Server.
Installing PHP using the command line
PHP can be installed from the command line of your Server. You will need to log in to the Server using SSH and work as the root user. Install PHP with the yum install -y php
command.
[root@eapps-example ~]# yum install -y php
Installing PHP Extensions
One of the strengths of PHP is the number of different extensions or modules available that can increase and expand its functionality. The PHP 5 application comes with a large number of extensions pre-installed, and you are also able to install additional extensions using the command line using PEAR and PECL.
Viewing installed PHP extensions
By default there are several PHP extensions installed. You can view the currently installed PHP extensions from the command line.
Viewing the installed PHP extensions using the command line
You can also view the installed PHP extensions from the command line of the Server, with the php -m command.
[root@eapps-example ~]# php -m
[PHP Modules]
bz2
calendar
Core
ctype
curl
date
ereg
exif
fileinfo
filter
ftp
gettext
gmp
hash
iconv
libxml
openssl
pcntl
pcre
Phar
readline
Reflection
session
shmop
SimpleXML
sockets
SPL
standard
tokenizer
xml
zip
zlib
[Zend Modules]
[root@example ~]#
Installing additional PHP Extensions
If you need a PHP extension that is not currently installed, you can install it yourself. This can be done from the command line.
Installing from the command line
You can install PHP extensions from the command line using either pear or pecl.
Your Virtual Server has both pear and pecl installed, which means that you can install any modules from the https://php.net site.
-
Pear packages are located here - https://pear.php.net/packages.php
-
PECL packages are located here - https://pecl.php.net/packages.php
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 one of 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.
After adding the extension files to the php.d directory, you will need to restart the Apache web server so that the extensions will be loaded into PHP.
-
For CentOS 6, use the
service httpd restart
command:[root@eapps-example ~]# service httpd restart
-
For CentOS 7, use the
systemctl restart httpd
command:[root@eapps-example ~]# systemctl restart httpd
PHP Configuration
For the majority of users, PHP as installed should require no additional configuration. However, there are some common PHP configuration changes that are made for application requirements or performance. These changes can be made from the command line.
Common PHP configuration changes
Some PHP configuration changes can affect the security of your Virtual Server. Before making any changes to the default PHP configuration, make sure you understand any potential security risks. Also be aware that changing PHP settings may cause your application to no longer function and may cause issues with your Virtual Server. Make sure you understand the possible impact of any changes you make to the default PHP configuration. |
-
Executing time - this is the maximum amount of time that PHP will wait for a script to finish. If the script does not finish is this time, PHP will kill the script.
-
Memory limit - this is the maximum amount of memory (RAM) that will be allocated to a script. If the script uses more than this amount of memory, it will be killed.
-
Request maximum size - this is the memory limit for a POST request
-
File minimum size - this is the maximum size of a file that a script can request. This is the parameter that controls the size of a file that applications like phpMyAdmin or phpPgAdmin can upload.
-
register_globals - unless you know exactly what register_globals does, and understand the security risks involves with turning it on, please leave it off.
-
display_errors - this will display any errors from the script to the browser. This is useful for debugging applications, but is a security risk if left on for production applications.
-
log_errors - this logs all PHP script errors to the error_log for the web site.
-
E-mail - if e-mails are sent from a PHP script, this is the address the e-mails are from. This must be an actual e-mail address on the Virtual Server, because the SMTP server will authenticate using that e-mail address. If this e-mail address is not valid, then any type of PHP mail script will fail.
Changing PHP configuration using the command line
You can also make configuration changes to PHP by editing the /etc/php.ini file directly, which is the file being edited by the Control Panel. The same options are available. Make sure that after you make any changes to the php.ini file to restart the Apache web server.
PHP Accelerators, Loaders, and Frameworks
There are several applications that will allow you improve the speed of your PHP code, allow you to run PHP code that is encoded by ionCube, and allow you to take advantage of the Zend framework.
You can install ionCube Loader, and Zend Guard Loader.
In order to have ionCube Loader and Zend Guard Loader installed together, they have to be installed in this order in the /etc/php.ddirectory:
ioncube-loader.ini
zend-guard-loader.ini
By default, they will install in this exact order, unless you change the names of the configuration files in the /etc/php.d directory.
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 Guard Loader
Zend Guard Loader 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 Optimizer is not compatible with PHP 5.3. If you are upgrading from PHP 5.2 with Zend Optimizer, you will need to upgrade PHP to the new version, and then install the Zend Guard Loader application from ISPmanager. Zend Guard Loader will replace Zend Optimizer. If you do not install Zend Guard Loader, your Zend Optimizer specific code will not work. |