33

I want to allow short_open_tags in php.ini

I want to access to the php.ini on my vagrant box configured with homestead. I saw the php.ini file in /etc/php5/fpm/php.ini

But ... permission denied Is somebody knows ?

Thanks

miken32
  • 42,008
  • 16
  • 111
  • 154

6 Answers6

51

Here is how you grant read/write access to php.ini, modify it, save changes & reload nginx:

1. Navigate to folder containing php.ini: $ cd /etc/php5/fpm

2. Grant read/write access: $ sudo chmod -R ugo+rw php.ini

3. Open php.ini: $ vim php.ini

4. Enter edit mode: $ i

5. Edit stuff

6. Exit edit mode: Press ESC

7. Save & close php.ini: $ :x!

7.1 OPTIONAL: Exit without saving: $ :q

8. Navigate to home (not sure if this is actually necessary): $ cd ~

9. Reload/Restart nginx: $ sudo nginx -s reload

10.1 Reload/Restart php: $ sudo service php5-fpm restart

10.2 If using PHP 7 then use $ sudo service php7.0-fpm restart (Thanks & Credit to Richard in comments).

11. ???

12. PROFIT! (or is that joke really too old?)

Here is a screenshot:

git bash showing php.ini before & after getting read/write access

Remember if you run $ vagrant provision, it'll reset all configuration files. Just so you know.

EDIT

Super useful to know. You can search in vim by exiting input mode, and type $ /post_max_size or whatever you want to find.

MartinJH
  • 2,590
  • 5
  • 36
  • 49
  • 1
    In php.ini the last value takes precedence so a one-liner should be: sudo su; echo "short_open_tag = On" >> /etc/php5/fpm/php.ini; service restart php5-fpm; exit; – runamok Feb 06 '16 at 05:21
  • 2
    If using PHP 7 then use `sudo service php7.0-fpm restart` – Richard Jul 11 '16 at 12:43
  • 1
    The trick was ``sudo service php7.0-fpm restart``, I was editing the right file but I was restarting nginx instead of php fpm – Cassiano Aug 16 '16 at 13:59
  • 2
    `sudo service php7.1-fpm restart` for php7.1, hopefully the pattern is clear now – MECU May 17 '17 at 16:06
  • `service --status-all` when in doubt. Somewhere in the list is a service starting with `php` – online Thomas Jun 15 '17 at 22:28
  • 1
    Run `readlink -f "$(which php)"` or `php -v` to determine which version of php you are using. Looks like the directory structure has changed a bit too: now, you need to `cd /etc/php/x.x/fpm` where `x.x` is your php version. – Illya Moskvin Jul 14 '17 at 14:52
  • 1
    To see the path where your **php.ini** file is located you can run `php --ini`. This will show which php.ini file is being read – Connor Leech Sep 26 '20 at 20:18
12

Just create ".user.ini" file (.user.ini files) in public/

[PHP]
short_open_tag = On
griba
  • 121
  • 1
  • 2
3

Simply ssh in to the homestead environment:

ssh homestead

Then become the superuser by typing:

sudo su

Then you will be able to edit your php.ini.

Gareth Daine
  • 4,016
  • 5
  • 40
  • 67
3

I have tried to change the mentioned php.ini for over an hour.
I suggest to check first which php.ini is really loaded.
I have checked it with php -i.

In my case it was located in /etc/php/7.2/cli.

zx485
  • 28,498
  • 28
  • 50
  • 59
  • 3
    Adding a grep command to this `php -i | grep php.ini` shows the path more clearly. Don't have to find it in the dump of info. – Ian Sep 20 '18 at 17:44
0

Maybe you should use htaccess to this problem

If you dont have, make file .htaccess (with the dot in root) and write down

<IfModule mod_php5.c>
   php_value short_open_tag 1
 </IfModule>

Good hosting providers does not provide the enter into php.ini

Mego
  • 154
  • 1
  • 3
  • 10
  • doesn't work. I Have added it to the existing htaccess in my laravel projevt folder ! – Thibault Van Campenhoudt Feb 02 '15 at 11:06
  • Are you sure, that your server runs on Linux? htaccess is not functional on windows servers – Mego Feb 03 '15 at 12:11
  • 2
    1. Vagrant homestead uses nginx, the .htaccess file is for cross-compatibility with apache when your app is deployed 2. It's a bad idea to change the php.ini as all other answers suggest, because all that's needed to screw up the changes is a `homestead destroy` 3. A more viable solution could be to conditionally set it at run-time `if (app()->environment() === "local) { ... }`, and set the php.ini correctly on your production servers – oskarth Sep 05 '15 at 13:53
-1

I had the same issue i solved it by opening php.ini file in root user mode otherwise you will not have permission to edit file....