I have installed Apache2 on my Raspberry Pi, and installed the php5 module. The webserver works as expected.

First i have coded a small php script to parse the dhcpcd config file (/etc/dhcpcd.conf). I open the file only as readable, and this works properly.

Now I want to change the IP. Therefore, I need to open the file as writeable. But I get an error, that I have insufficient rights to write to this file.

I am new to Apache; where can I set the rights to write to /etc/dhcpcd.conf? And what rights need to be set?

2 Answers 2


This will happen because /etc/dhcpcd.conf is owned by root. On my Raspbian Jessie system, this is what the permissions look like:

-rw-rw-r-- 1 root netdev 1247 Oct 17 00:22 /etc/dhcpcd.conf

We can see from this that user root owns the file, and group netdev owns the file, and that the file has Read and Write permissions for only root and netdev.

So, if we want to make it writable by PHP, running under Apache, we primarily have two options:

  1. Add the Apache2 user, www-data (on Raspbian), to the netdev group:

    sudo usermod -a -G netdev www-data

    You will then need to restart Apache:

    sudo systemctl restart apache2
  2. Just make the file writable by everyone:

    sudo chmod a+rw /etc/dhcpcd.conf

Either of these options will do the trick. But option one is probably the "more proper" way to do it according to Linux security best practices. That said, depending on your application, either way should work fine.


You need to set the path of the dhcpcd.conf in your PHP configuration, and include it in your open_basedir. Then you should be able to write to them.

Also you need the correct permissions for your web user.

  • This isn't an open_basedir problem; he can read the file just fine. This is a Linux file permissions issue.
    – Will
    Commented Feb 15, 2016 at 22:48
  • @Will: If his PHP configured correctly and secured, the open_basedir is not set, then he should not able to open this file, even the user/group permissions are correct
    – Broatcast
    Commented Feb 17, 2016 at 3:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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