Installing PHP (Personal Home Page) on Linux Cloud Servers

2019-12-19 By Aaron 9879 Views linux php development
43 reviews

PHP is the most popular open-source general-purpose scripting language in this World. The main use of PHP is creating forums, picture galleries, check details from a form, etc.


The main advantage of PHP is that it can easily be run on various platforms. See the instructions for installing PHP, changing PHP settings and enabling PHP extension on CentOS, Debian, Ubuntu & Fedora below.


Install PHP on Linux Cloud Servers


CentOS 6/7/8 & Fedora


  1. Install and enable EPEL and Remi repository in the server.

    # yum install http://rpms.remirepo.net/enterprise/remi-release-7.rpm
    

    Centosupgrade1

  2. Install yum utils in the server.

    # yum install yum-utils
    

    Centosupgrade2

  3. Enable Remi repository to install PHP version.

    # yum-config-manager --enable remi-php72
    

    Centosupgrade3

    Centosupgrade4

  4. Install PHP7.2 on the server.

    # yum install php php-mcrypt php-cli php-gd php-curl php-mysql php-ldap php-zip php-fileinfo
    

    Centosupgrade5

    Centosupgrade6

  5. Check the installed version of PHP on your system.

    # php -v
    

    Centosupgrade7


Ubuntu & Debian


  1. Add the Ondrej PHP repository to the server.

    # sudo add-apt-repository ppa:ondrej/php
    

    Centosupgrade8

    Centosupgrade9

  2. Install PHP 7.2 on the server.

    # sudo apt-get install -y php7.2
    

    Centosupgrade10

    Centosupgrade11

  3. Check the installed version of PHP on your system.

    # php -v
    

    Centosupgrade12


Change PHP Settings on Linux Cloud Servers

There may arise situations when the existing PHP settings configurations do not meet the requirements of the website/application hosted in the server. In such cases, it is a requisite to modify and update the PHP settings to better suit your applications. This guide can be used to change the PHP settings in your Linux server irrespective of the OS distribution.

The existing PHP configuration settings and PHP values can be viewed using a file written with the phpinfo function. The file can be placed under the website files or under the default document directory of the web service installed in the server.


CentOS / Ubuntu / Debian / Fedora


  1. Change into the directory under which the phpinfo file is to be created. For example, the default directory for web pages in Apache is /var/www/html.

    # cd /var/www/html
    

    Centosupgrade13

  2. Create the file with the phpinfo function using any editor of your choice.

    # vi /var/www/html/info.php
    

    Centosupgrade14

    Open the file using any editor, type in the below snippet in the file and then save and quit the file.

    Centosupgrade15

  3. The file, info.php can now be browsed using any browser using the website name under which the file is created or using the server IP address if the file is created in the default document directory and the existing PHP version and its settings can be viewed.

    http://websitename/info.php (replace `websitename` with the name of the website)  
    (or)
    http://123.123.123.123/info.php (replace `123.123.123.123` with the server IP address)
    

    A general example of the phpinfo page is as shown below:

    Centosupgrade16

    The file displayed to the right side of Loaded Configuration File is the PHP configuration file in which the PHP settings need to be changed.

  4. Open the PHP configuration file using any editor of your choice and make necessary changes to the PHP settings as per your requirement.

    For example, if you require to increase the maximum size of files that you need to upload through your PHP application, the variables that need to be adjusted are post_max_size and upload_max_filesize.

    The existing values of both these variables can be found using the below commands.

    # grep post_max_size /etc/php.ini
    
    # grep upload_max_filesize /etc/php.ini
    

    Centosupgrade17

    Modify these values according to your requirement in the PHP configuration file, save and exit the file.

    Some other common PHP values that often require adjustment are the PHP memory limit and PHP execution time, denoted by the variables and max_execution_time respectively.

  5. Once the values are adjusted, the web service needs to be restarted for the changes to become effective.

    # systemctl restart httpd
    

    Check and confirm that the values of the variables have been adjusted as required.

    # grep post_max_size /etc/php.ini
    
    # grep upload_max_filesize /etc/php.ini
    

    Centosupgrade18


Enable PHP extension on Linux Cloud Servers

The core functionality of PHP is PHP modules/ extensions. It helps to enable specific functions to be used in the PHP code.


CentOS / Ubuntu / Debian / Fedora


  1. To check the list of Compiled PHP Modules.

    # php -m
    

    Centosupgrade19

  2. To know more about any specific module which is already installed on the server. Please use the following command.

    # yum info <module-name>
    
    E.g.: # yum info php-pdo
    

    Centosupgrade20

  3. To install any new PHP module in the server, may use the following command.

    # yum install <module-name>
    
    E.g.: # yum install php-pdo
    

    Centosupgrade21

  4. Install multiple modules at once.

    # yum install module-name1 module-name2 module-name3
    
    E.g.: # yum install php-cli php-fpm php php-punic
    
  5. View Current PHP Modules.

    # yum list installed *php*
    

    Centosupgrade22


Related Tutorials

What do you think about this article?

Rate this article
LayerStack Promotion
Need assistance?

Try this guide to receive free bundled services at signup on a new free account.

Sign Up

Your Feedback Is Important

We hope you’ll give the new products and updates a try. If you have an idea for improving our products or want to vote on other user ideas so they get prioritized, please submit your feedback on our Community platform. And if you have any questions, please feel free to ask in the Community or contact our Technical Support team.