PHP is a powerful, flexible scripting language which is designed for web development, and can be easily embedded into an HTML page. Learn the basics of managing PHP on a Cloud Server running Linux, including how to check your PHP version, how to see which options and modules are configured, and how to edit the php.ini file to change the PHP configurations.
- A Cloud Server with PHP installed and running.
Note: PHP is installed and running on a Standard Linux installation by default. If your server was created with a Minimal installation, you will need to install and configure PHP before you proceed.
Find the PHP Version
php -v command to find your PHP version from the command line:
[user@localhost html]# php -v PHP 5.4.16 (cli) (built: Nov 6 2016 00:29:02) Copyright (c) 1997-2013 The PHP Group Zend Engine v2.4.0, Copyright (c) 1998-2013 Zend Technologies
In the example above, the server is running PHP version 5.4.16.
To upgrade the version of PHP, see:
View the PHP Options and Installed Modules
The PHP command
phpinfo(); will output all of the PHP installation's information, including the version number, all of the configurations, all of the loaded modules, and all of the settings.
To view this information in a browser, create a file
phpinfo.php in your webspace and open it for editing. For example, to create the file in
/var/www/html the command is:
sudo nano /var/www/html/phpinfo.php
Put the following into this file:
<?php phpinfo(); ?>
Save and exit the file, then view the file in a web browser.
Use Ctrl + F to find information on the page.
Note: For security reasons, delete this file after you are finished checking the PHP version.
Edit the php.ini File
The php.ini file is used to make changes to the PHP configurations. Use the following command to edit the php.ini file:
- CentOS 7: sudo nano /etc/php.ini
- Ubuntu 16.04: sudo nano /etc/php/7.0/apache2/php.ini
After you make the required changes, save and exit the file. Then restart Apache for the changes to take effect:
- CentOS 7: sudo systemctl restart httpd
- Ubuntu 14.04: sudo services apache2 restart
Use a Package Management System
If you plan to use PHP extensively, a package management system is a convenient way to manage PHP libraries.
Composer is the most popular package management system. All you need to do is declare which packages your project requires, and Composer will install and update them for you.
For more information on Composer see our article Install and Use PHP Composer on Ubuntu 16.04.
Use a PHP Framework
A PHP framework is a collection of commonly-used website tools. Instead of "reinventing the wheel" every time you need to do a common task (like authenticate users or manage sessions), you can use the framework to install a pre-made component. This allows developers to build entire websites quickly and reliably.
For more information on using a PHP framework, see our article Install and Use the Fat-Free Framework for PHP.