Cara edit php.ini di ubuntu

edit the my.ini in the mysql/bin directory and change the max_allowed_packet = 1M to e.g. max_allowed_packet = 100M.

Gunnar

Useful (4)

 


Windows XP and Server 2003 Instructions

These instructions presume that you have downloaded the latest PHP 5.3.x Windows zip package and extracted it to C:\PHP. If you have installed PHP to another location then change all references to “C:\PHP” to the location you installed PHP too.

lightbulb.png Download and install any text editor that can save the file in a UTF-8 format, Crimson Editor is one such, NotePad++ is another, use that instead of either Wordpad or Notepad! The issue is that WordPad or Notepad will include hidden characters that may not be compatible with the requirements of PHP.
Open C:\PHP
Right Click the php.ini file in this folder and choose “Open with…” selecting your editor of choice.
Press Ctrl + F and type “post_max_size” (click Find…”, where needed)
Change the value to the number of Mb you want your site to accept as uploads
Press Ctrl + F and type “upload_max_filesize” (click Find…”, where needed)
Change the value to the number of Mb you want your site to accept as uploads
Press Ctrl + F and type “max_execution_time” (click Find…”, where needed)
Change the value to 600
Press Ctrl and S or the save button.
Exit your editor.
Restart your webserver to reload PHP with the edited changes.
For IIS
Open the Start Menu on your server and select “Run”
Type “iisreset /RESTART”
For Apache 2 and Windows XP
Go to Start > All Programs > Apache > Restart
For Apache 2 and Windows Server
The following command will work as long as you have installed Apache 2 as a service on your Windows Server
Open your Start Menu on your server and select “Run”
Type “httpd -k restart”
Your new file size limit should now appear in Administration > Security > Site Policies > Maximum uploaded file size

NOTE: These instructions also cover the Xampp Windows installer. Just replace C:\PHP with C:\Moodle\server\php and to restart your Moodle with a normal stop-start.

File konfigurasi php sering membingungkan, dimana lokasinya. Dikarenakan ada beberapa versi PHP yang digunakan pada Ubuntu misalnya. Untuk itu kami membuat tulisan ini supaya kami tidak mudah melupakan :).

CentOS

Pada CentOS biasanya hanya terdapat satu versi php, untuk melihat lokasi file php.ini di CentOS, dapat dilakukan dengan perintah php sendiri.

php -i | grep "Loaded Configuration File"

Ubuntu

Pada Ubuntu, mungkin terdapat beberapa file php.ini yang ada. Supaya tidak salah konfigurasi, dapat dilakukan dengan beberapa cara untuk melihatphp.ini yang aktif.

1 – Menggunakan phpinfo

Cara ini menggunakan file php sendiri yang bisa di akses pada web browser. Masuk ke web root, kemudian buat sebuah file php, misal :info.php. Kemudian masukan kode berikut ini :

<?php phpinfo(); ?>

Kemudian simpan dan buka alamat alamat http://alamat_website/info.php

Akan terlihat detil tentang informasi PHP yang digunakan, termasuk didalamnya lokasi PHP.ini.

2 – Menggunakan perintah php

Sama dengan sistem operasi Linux CentOS, dapat menggunakan perintah :

php -i | grep "Loaded Configuration File"

Menggunakan perintah locate

Cara ketiga ini kita menggunakan tool tambahan dari sistem operasi linux. Perintah ini tidak tersedia secara default di Linux Ubuntu maupun di CentOS. Kita dapat memasang tool ini dengan perintah di ubuntu apt-get install mlocate, jika di CentOS yum install mlocate.

PHP is one of the most important languages on the Internet. Many content management systems like WordPress, TYPO3 or Joomla are based on PHP. With the release of PHP 8, various new features were introduced. Also some old features were reworked, meaning that errors may occur if the code is not up to date. You can find all the important information about the new features of PHP 8 here.

PHP settings are controlled by a file named ‘php.ini’. The configuration file is read when Apache web server starts. To change the default PHP settings, you should edit the ‘php.ini’ file and restart your web server.

Out-of-the-box, PHP settings work pretty well but customizing the configuration file allows you to select what can work best for you depending on your hardware architecture and software design.

In this guide, we are going to show you how to edit the basic PHP settings on your Apache web server running on Ubuntu 18.04 VPS.

Prerequisites

  • A VPS Plan (visit HostAdvice’s VPS reviews for the best VPS providers)
  • A non-root user with sudo privileges
  • Apache web server
  • PHP

Step 1: Determine the Location of your php.ini File

From time to time, you will need to manage the critical php.ini file. The file location may vary a bit depending on the PHP version running on your server.

The configuration file is located on:

/etc/php/php_version/apache2/php.ini

For instance, if you are running PHP 7.0, the file will be located on:

/etc/php/7.0/apache2/php.ini

The same case applies to PHP 7.2. You can find the configuration file at:

/etc/php/7.2/apache2/php.ini

Step 2: Opening the PHP configuration file for editing

Once you determine the location of your file, the next step is editing it using a nano editor. Use the command below to open the file:

$ sudo nano php_ini_file

For instance:

$ sudo nano /etc/php/7.2/apache2/php.ini

Step 3: Making changes on the php.ini file

As mentioned at the beginning of the article, the default PHP settings may work for the majority of websites or web applications. However, your environment may demand some values to be tweaked a bit to ensure that your website is running smoothly.

In most cases, you will be editing the below PHP settings:

PHP max_execution_time

This sets the maximum execution time in seconds that a PHP script is allowed to run before it is terminated. Sometimes, you might have demanding scripts that should run for a few minutes and you need to change this value. The default value is 30 seconds but you can set it to a larger value

Default value:

max_execution_time =30

Change to any value e.g. 1800

max_execution_time =1800

PHP upload_max_filesize

The default value for this directive is 2M (two Megabytes). This value controls the maximum size of files that you upload using PHP scripts. Sometimes, it is necessary to change this value if you anticipate uploading big files.

For instance, if you are uploading a large database via phpMyAdmin, you will need to change this value.

Default value:

upload_max_filesize=2M

Change to a large value e.g. 16M

upload_max_filesize=16M

PHP post_max_size

This value limits the amount of data allowed on post data. It usually affects PHP scripts that use a lot of web forms. The value also controls files uploaded via a PHP script, hence, it should always be larger than ‘upload_max_filesize’. The default value for ‘post_max_size’ is 8M.

Default value:

post_max_size =8M

Customize it depending on your needs e.g.

/etc/php/7.0/apache2/php.ini
0

PHP memory_limit

The default value for PHP 7.2 ‘memory_limit’ is 128M. Sometimes, poorly written PHP scripts may consume a lot of server’s memory and affect other applications running on your VPS. To avoid this, PHP ‘ memory_limit’ controls the amount of memory allocated to a script.

Default value

/etc/php/7.0/apache2/php.ini
1

Custom value example

/etc/php/7.0/apache2/php.ini
2

You can also use -1 if you want to allocate an unlimited amount of memory to your PHP script depending on the available RAM on your VPS

/etc/php/7.0/apache2/php.ini
3

PHP Error Reporting Settings

You can control the behavior of error reporting in PHP using the below directives:

display_errors:>  Set this value to ‘On’ or ‘Off’ depending on whether you want PHP to display errors when scripts are run. In PHP 7.2 the default value is ‘Off’

/etc/php/7.0/apache2/php.ini
4

You can turn error reporting on by changing the value to ‘On’:

/etc/php/7.0/apache2/php.ini
5

log_errors: This value tells whether errors from a script should be saved on the server’s log file. Instead of displaying errors to regular users in a production environment, you should log them. The default value in PHP 7.2 is ‘On’

/etc/php/7.0/apache2/php.ini
6

You can switch error logging off by changing the value to:

/etc/php/7.0/apache2/php.ini
7

error_reporting:  This directive dictates the error reporting level. For PHP versions greater than 5.3, the default value is ‘E_ALL & ~E_DEPRECATED & ~E_STRICT’

/etc/php/7.0/apache2/php.ini
8

You may change the value depending on the errors that you want to be reported. For instance, to include notices, use the value below

/etc/php/7.0/apache2/php.ini
9

PHP Date/Time settings

You can also change the default timezone used by PHP scripts.

Find the line:

/etc/php/7.2/apache2/php.ini
0

Uncomment it by removing the semicolon and then enter your preferred time zone. You can check the list of support time zones on the official PHP website (http://php.net/manual/en/timezones.php)

For instance, if you want to change the time zone to New York City, use the value below:

/etc/php/7.2/apache2/php.ini
1

Once you finish editing the php.ini file, press CTRL + X, Y and hit Enter to save the changes. You should also restart Apache for the settings to be reloaded using the command below:

/etc/php/7.2/apache2/php.ini
2

Conclusion

In this guide, we have discussed how to locate and edit PHP settings on your Ubuntu 18.04 server. We have also taken you through the basic settings that you should tweak to optimize the performance of your website or web applications. We believe that the changes you make on your PHP configuration file will help you to have a smoother environment for running your websites.