In this tutorial, we are going to explain what contains the “php.ini” configuration file and what is used for. The PHP ini configuration file is a special file for PHP applications used to control PHP settings what users can or can not do with the website.
When PHP is installed the server is configured to use the default PHP settings, but sometimes we need to change the behavior of the PHP at runtime and this is when this configuration file comes to in use.
We are going to use Ubuntu 20.04 as OS while we are explaining and installing the PHP along with its extensions. Let’s get started!
Table of Contents
Prerequisites
- Fresh install of Ubuntu 20.04
- User privileges: root or non-root user with sudo privileges
Update the System
Update the system to its latest version with the following command:
apt-get update -y && apt-get upgrade -y
Install PHP8.0
First, we need to install some prerequisites and add the Ondrej repository. We are going to use the ondrej/apache2 option:
sudo apt install lsb-release ca-certificates apt-transport-https software-properties-common -y sudo add-apt-repository ppa:ondrej/php
We are going to install the latest version PHP8.0 along with its extensions. Execute the following command and allow some time for the PHP to be installed completely.
sudo apt install php8.0 -y && sudo apt install php8.0- -y
Check if the PHP8.0 installation is successful:
php -v
You should receive the following command:
root@vps:~# php -v PHP 8.0.12 (cli) (built: Oct 22 2021 12:34:48) ( NTS ) Copyright (c) The PHP Group Zend Engine v4.0.12, Copyright (c) Zend Technologies with Zend OPcache v8.0.12, Copyright (c), by Zend Technologies
To check the installed extensions, execute the command below:
php -m
You should see the following output:
root@vps:~# php -m [PHP Modules] calendar Core ctype date exif FFI fileinfo filter ftp gettext hash iconv json libxml openssl pcntl pcre PDO Phar posix readline Reflection session shmop sockets sodium SPL standard sysvmsg sysvsem sysvshm tokenizer Zend OPcache zlib [Zend Modules] Zend OPcache
PHP values in the php.ini configuration file
In this section, we will explain a little bit more about the PHP values in the php.ini configuration file and their usage. We will start with the most important and most usable PHP values that are changeable every day in the Hosting world for the client’s needs.
1. upload_max_filesize
With this value, we define the maximum size of the files that we can upload.
2. max_execution_time
With this value, we set the limit in seconds for time-limiting scripts in production servers.
3. post_max_size
With this value, we set the maximum allowed size of POST data accepted by PHP.
4. memory_limit
With this value, we set the maximum amount of memory the script can consume.
5. max_input_time
With this value, we set the maximum amount of time the script needs to parse input data, whether POST or GET.
6. file_uploads
This setting is for setting the FLAG to ON or OFF if the file uploads in PHP are included in the code or not.
7. enable_safe_mode
This setting is by default to ON whenever PHP is compiled.
8. upload_tmp_dir
This setting is for defining the temporary directory for storing files.
9. display_errors = off
This setting is for not allowing the PHP to show the errors while PHP is running on a specific host.
10. max_file_uploads
This setting is for defining the maximum number of files allowed to be uploaded simultaneously.
11. mysql.default_host
This setting is for defining the MySQL connection if no other server host is mentioned.
12. mysql.default_user
This setting is for defining the MySQL user if no other username is mentioned.
PHP values in browser
We will explain now, how you can access the configured PHP values in more detail by accessing them in your browser
First, create the “phpinfo.php” file in the document root of your website
cd /var/www/html/ sudo nano phpinfo.php
Once the file is opened paste the following lines of code:
<?php phpinfo(); ?>
Save the file, close it and access it in your browser
http://YOUR_DOMAIN/phpinfo.php
You should see the screen like the picture below:
You can see that by accessing this URL, you can get the information about the PHP version, system information core PHP values and etc. Everything that is changed in the php.ini file, on your server by refreshing this URL will be updated.
The location of your php.ini file is located at “/etc/php/8.0/apache2/php.ini” and you can easily check this in the “Loaded Configuration File” section also in this window. Please note the location of the php.ini file is different if you are using the control panel and the values are recommended to be changed from the control panel GUI instead of the command line.
Congratulations! You learned a lot of new things about php.ini, phpinfo, and PHP values.
Of course, you don’t have to manage your PHP version and update the php.ini values for your website. If you use one of our VPS Hosting plans, in which case you can simply ask our expert Linux admins to install and manage the PHP for your websites. They are available 24×7 and will take care of your request immediately.
If you liked this post about the PHP values in the php.ini configuration file, please share it with your friends on the social networks using the buttons on the left or simply leave a reply below. Thanks.