Before you start installing PHP7, ensure that your Linux server has PHP5 or a higher version installed. If not, you will need to install PHP5 or a later version first. Additionally, make sure necessary dependencies like GCC are installed on your system.
First, we need to add a Personal Package Archive (PPA) named ondrej/php to get the latest PHP7 version.
sudo add-apt-repository ppa:ondrej/php
Next, run the following command to update the package list:
sudo apt-get update
Then, use this command to install PHP7:
sudo apt-get install php7.0
After installation, use this command to check if PHP7 is correctly installed:
php -v
If everything is correct, you should see the PHP7 version information.
By default, PHP7 uses the system's php.ini configuration file. You can find the location of this file with the following command:
php --ini
Once you've located the php.ini file, you can edit it to adjust various settings like upload file size and maximum request size. Below is a common configuration example:
; Maximum allowed size for uploaded files. ; http://php.net/upload-max-filesize upload_max_filesize = 2M ; Maximum size of POST data that PHP will accept. ; Its value may be 0 to disable the limit. It is ignored if POST data reading ; is disabled through enable_post_data_reading. ; http://php.net/post-max-size post_max_size = 8M
PHP7 does not include all commonly used extensions by default. If you need any additional extensions, you can install them as needed.
Use the following command to list the currently installed PHP modules:
php -m
For example, if you need the MySQL extension, use this command:
sudo apt-get install php7.0-mysql
If you need the GD extension, you can use this command:
sudo apt-get install php7.0-gd
This article covered how to install PHP7 on a Linux system, configure PHP7 settings, and install additional PHP extensions. It's important to ensure your server is running the latest PHP7 version, as older versions may have security risks or functional limitations.