Cara menggunakan change apache php path

Im trying to change something in php.ini - but after editing, saving the file and restarting apache no changes is updated.

Table of Contents

  • Not the answer you're looking for? Browse other questions tagged ubuntu ubuntu-14.04 php or ask your own question.
  • Reader Interactions
  • Installing PHP 7.2
  • Configuring Apache to Use PHP 7.2
  • Verifying Apache's PHP Version
  • Adding Modules to PHP 7.2
  • Where is my PHP ini file in Ubuntu?
  • Where can I find PHP ini?
  • Where is my PHP ini Linux?
  • Where is PHP ini in lamp?

I'm on Ubuntu 16.04.3 LTS

  • I have used phpinfo.php to locate the file in use: /etc/php/7.0/fpm/php.ini

  • Changing that file through terminal, updating short_open_tag from Off to On, and saving the file.

  • Typing service apache2 restart to make the changes go live

But no changes is updated. From phpinfo I can still see that short_open_tag is Off.

What am I missing here?

asked Jun 30, 2018 at 20:26

since you mention fpm, you need to restart fpm not apache, on debian based should be close to :

sudo service php7.0-fpm restart

or just

sudo service php-fpm restart

reload can also do it instead or restart.

answered Jun 30, 2018 at 20:47

fab2sfab2s

8081 gold badge8 silver badges14 bronze badges

1

Not the answer you're looking for? Browse other questions tagged ubuntu ubuntu-14.04 php or ask your own question.

Manage custom PHP settings without breaking the apt-get upgrade process.

I am using WordPress on my Ubuntu machine and require some custom configuration of the PHP environment – but changing the php.ini file directly caused some issues for the apt-get upgrade process as it would stop with the following message:

php.ini: A new version (/usr/lib/php/7.2/php.ini-production) of configuration file /etc/php/7.2/fpm/php.ini is available, but the version installed currently has been locally modified. 

What do you want to do about modified configuration file php.ini?

- install the package maintainer's version
- keep the local version currently installed
- show the differences between the versions
- show a side-by-side difference between the versions
- start a new shell to examine the situation

While this was a nuisance, if I picked the wrong option, I lost my changes. So I found a better way.

I could not find any official documentation for this, but it appears to work the same way as Apache mods and there are numerous unofficial references online, such as How To Enable/Disable PHP Modules on Ubuntu 18.04 & 16.04 which describes this process and the phpendmod, phpdismod, and phpquery commands.

Note that this works for Ubuntu 18.04 and for PHP 7.3 as well.

The PHP configuration is in /etc/php/7.2/, within this are four folders: apache2, cli, fpm, mods-available. Rather than change the php.ini file in the apache2 folder, I created a new file (user.ini) in the mods-available folder to contain my custom configuration.

user.ini 

date.timezone = Australia/Melbourne

display_errors = On
display_startup_errors = On
error_reporting = E_ALL
html_errors = On
log_errors = On

This was then enabled using:

sudo phpenmod user 
sudo service php7.2-fpm restart 
sudo service apache2 restart

A quick check of phpinfo() confirmed that the custom configuration was being used.

Happy coding.

The php.ini file is responsible for all the PHP settings in Apache server. So you can modify the PHP settings by modifying the php.ini file

When you want to change PHH configuration in Ubuntu 16.04, please follow the below steps

1) Open terminal in your Ubuntu 16.04
sudo nano /etc/php/7.1/apache2/php.ini
2) Change your PHP configuration whichever you want to change. For example change the upload_max_filesize to 64M, higher values are better.
upload_max_filesize = 64M

3) Now save the text editor and restart the apache to get the changes takes palce.

sudo service apache2 restart


Reader Interactions

Using PHP 7.2 on an Ubuntu dedicated server is highly recommended over previous PHP versions for several reasons, first being security. Active Support for PHP 7.2 goes until November 30th, 2019 and Security Support until Nov. 30, 2020. Older versions like 7.0 and anything 5.6 and below are no longer getting any support and can leave open security holes on a server if they are not replaced. Another main reason to upgrade is the big performance increase over previous versions when PHP 7.2 is installed and is using the OPcache module.  This can greatly decrease the time it takes for your web page to load! If you are developing a site locally or launching it on one of Liquid Web’s Ubuntu VPS or Dedicated Servers, using PHP 7.2 or newer would be the way to go.

Cara menggunakan change apache php path

Pre-flight: Check the Server Environment
  • Correct Permissions: First, make sure you have proper root or sudo permissions to be able to manage the system and applications on the server. If you only have access to a non-root user on the system, then you may have to get more permissions from the server admin.
  • Existing PHP Versions: Check for an existing version of PHP. If you selected the default LAMP stack when first installing the Ubuntu image onto the server, it defaults to PHP 7.0. If you used a different image or did a plain install, then you may not have any version of PHP on the server. To check the PHP version access the terminal and run:
[email protected]:~# php -v
 PHP 7.0.30-0ubuntu0.16.04.1 (cli) ( NTS )

If you see an older PHP version, then you will have to install the new version and switch the version Apache connects to later. If it shows “Command php not found” then there is no PHP version currently installed.

  • Creating a Quick Backup: If you do have an existing PHP version, you may want to make a backup of any configurations before doing the upgrade in case there are issues (like if your site code wasn’t compatible) and you need to downgrade again. You can check on the current configuration directory by running:
[email protected]:~# php --ini
 Configuration File (php.ini) Path: /etc/php/7.0/cli
 Loaded Configuration File:         /etc/php/7.0/cli/php.ini
 Scan for additional .ini files in: /etc/php/7.0/cli/conf.d

This shows the configurations are all in the /etc/php/7.0/ directory. So if you want to make a quick backup, you can run a command like:

[email protected]:~# sudo cp -a /etc/php/7.0/ /etc/php/7.0.backup

Also, you can save a list of existing PHP modules by running:

[email protected]:~# sudo cp -a /etc/php/7.0/ /etc/php/7.0.backup

This can help when comparing the existing modules to the modules in PHP 7.2.

Installing PHP 7.2

The official repository for PHP on Ubuntu is from Ondřej Surý on launchpad. To add it to your system, you need to run the following command:

[email protected]:~# sudo add-apt-repository ppa:ondrej/php

Press enter when it prompts you to. This allows your system to use the repository as a source for new software. The next command grabs the list of available software packages for your system:

[email protected]:~# sudo apt-get update

After that you can proceed with the install:

[email protected]:~# sudo apt-get install php7.2

It should show several different packages that it will install and how much total disk space they will use. When it prompts you, type ‘Y’ and submit it. After a few moments the install should be complete, check the PHP version with:

[email protected]:~# php -v
 PHP 7.2.13-1+ubuntu16.04.1+deb.sury.org+1

It should now show PHP 7.2, but now we need to have Apache configured to use the newer version.

Configuring Apache to Use PHP 7.2

Ubuntu 16.04 uses a few different commands to help manage Apache modules so the way it utilizes a specific PHP version depends on which module is loaded. You can view the list of available modules by running:

[email protected]:~# ls /etc/apache2/mods-available/php*
 /etc/apache2/mods-available/php7.0.conf
 /etc/apache2/mods-available/php7.0.load
 /etc/apache2/mods-available/php7.2.conf
 /etc/apache2/mods-available/php7.2.load

You may have other modules as well, the default LAMP stack install would have 7.0 and the new 7.2 install we just made, but running the next command shows that 7.0 is still active:

[email protected]:~# ls /etc/apache2/mods-enabled/php*
/etc/apache2/mods-enabled/php7.0.conf
/etc/apache2/mods-enabled/php7.0.load

To switch that to the newer 7.2 version, first disable older PHP version:

[email protected]:~# sudo a2dismod php7.0

Then enable PHP 7.2:

[email protected]:~# sudo a2enmod php7.2

Before restarting Apache, check the Apache configuration syntax by running:

[email protected]:~# apachectl -t
Syntax OK

If it says the syntax is OK, then restart Apache:

[email protected]:~# sudo service apache2 restart

Verifying Apache's PHP Version

Now to check your work, run the previous command again to see which module is loaded and it should show the PHP 7.2 version:

[email protected]:~# ls /etc/apache2/mods-enabled/php*
/etc/apache2/mods-enabled/php7.2.conf
/etc/apache2/mods-enabled/php7.2.load

If you do not see the same results as shown in the last few commands, recheck the spelling and syntax of the last few commands and make sure sudo was entered if you are not running as the root user.

Then to test it on your site, we recommend making a phpinfo file you can view on your domain. This shows the PHP version as well as information about current configurations, variables, and all the added modules. Create a new .php file in your site’s home folder or in Apache’s document root (/var/www/html by default) and include this code:

<?php phpinfo(); ?>

Then if you visit the page in the browser it should look something like this:

If you had a site already up and running on the previous PHP version, test it out now and see if there are any issues. If your code isn’t compatible or showing errors, you can try to diagnose further or if you need the site back up right away you can downgrade the PHP version again by running the a2dismod and a2enmodcommands to disable PHP 7.2 and then enable 7.0 or whichever previous version you had on the server then restart Apache again.

Some sites may now show an error saying a module is missing and can’t run, or if you are developing a new site and have a list of modules that are needed, then the next section can help you add new modules.

Adding Modules to PHP 7.2

The switch to PHP 7.2 doesn’t automatically keep all the same modules from previous PHP versions. If you don’t need to compare the list to a previous PHP version then to install any basic modules you do need, first type the comannd below. But don’t press enter, if you press the TAB key twice you should get a list of available modules specific to 7.2::

@test:~# sudo apt-get install php7.2[tab][tab]

Example Output:
php7.2 php7.2-enchant php7.2-mbstring php7.2-snmp
php7.2-bcmath php7.2-fpm php7.2-mysql php7.2-soap
php7.2-bz2 php7.2-gd php7.2-odbc php7.2-sqlite3
php7.2-cgi php7.2-gmp php7.2-opcache php7.2-sybase
php7.2-cli php7.2-imap php7.2-pgsql php7.2-tidy
php7.2-common php7.2-interbase php7.2-phpdbg php7.2-xml
php7.2-curl php7.2-intl php7.2-pspell php7.2-xmlrpc
php7.2-dba php7.2-json php7.2-readline php7.2-xsl
php7.2-dev php7.2-ldap php7.2-recode php7.2-zip

This is not a complete list so you may need to look up how to install other modules you may need. You can type the modules you want, and you can add multiple in the same install command, like:

[email protected]:~# sudo apt-get install php7.2-opcache php7.2-mbstring php-memcached

php -m > /tmp/7.2.modulelist.txt

Then to compare it to the list that was created before, run:

[email protected]:~# diff  /tmp/7.0.modulelist.txt /tmp/7.2.modulelist.txt
15,16d14
< mysqli
< mysqlnd
21d18
< pdo_mysql
28d24
< soap
29a26
> sodium

Or if you want a more visual way to compare the two lists, run:

[email protected]:~# vimdiff  /tmp/7.0.modulelist.txt /tmp/7.2.modulelist.txt

Which will show a page like this in the terminal:

In this example, the various MySQL modules and soap show up on the list of 7.0 modules on the left but are missing from the 7.2 version on the right, and the sodium module is on 7.2 but wasn’t in 7.0.

So for this example, we can install the missing modules with:

[email protected]:~# sudo apt-get install php7.2-mysql php7.2-soap

After that installs, we can save an updated list of modules and can compare it again:

[email protected]:~# php -m > /tmp/7.2.modulelist.updated.txt
diff /tmp/7.0.modulelist.txt /tmp/7.2.modulelist.updated.txt
29a30
> sodium

Only the sodium module is different between the module lists, so it is now ready for development! Hopefully, this guide helped with your upgrade to PHP 7.2! If you had any issues or need further help with your Liquid Web Ubuntu Server, please let our Linux Support Team know!

Where is my PHP ini file in Ubuntu?

The default location for the php. ini file is: Ubuntu 16.04: /etc/php/7.0/apache2.

Where can I find PHP ini?

Your answer.

You can get a full phpinfo() using : php -i..

And, in there, there is the php.ini file used : $ php -i | grep 'Configuration File' Configuration File (php.ini) Path => /etc Loaded Configuration File => /etc/php.ini..

On Windows use find instead: php -i|find/i"configuration file" Hope this is helpfull!!.

Where is my PHP ini Linux?

Apache. On Apache, php. ini is usually located in /etc/php/8.1/apache2/php. ini .

Where is PHP ini in lamp?

ini -Folder (Windows) or in the etc -Folder (within the xampp-Folder). Under Linux, most distributions put lampp under /opt/lampp , so the file can be found under /opt/lampp/etc/php. ini . It can be edited using a normal Text-Editor.