How to add entry to /etc/fstab file using php

236 Views Asked by At

Is there any way for add entry to /etc/fstab using php? I have done lvcreate and mount each volume into mountfolder using php.

The last step is to edit the mount options in the /etc/fstab file so that the new mount persists after reboot. No documents found for this step using php code.

1

There are 1 best solutions below

0
On

I found the solution for this. Yes, we can use ssh vi code editor using phpseclib. Refer my previous post to connect ssh using phpseclib.

Then my code to write vi /etc/fstab as follows:

    $ssh->setTimeout(2);
    $ssh->read();
    //enter vi editor
    $ssh->write("sudo vi /etc/fstab\n");
    $ssh->read();
    //Insert line in vi editor
    $ssh->write("i");
    //enter in new word on that empty line
    $ssh->write("/dev/mapper/uservolumegroup-foldername  /var/www/html/efsmount/foldername   xfs     defaults,nofail   0   0\n");
    //hit escape button
    $ssh->write("\x1B");
    //saves and closes the vi editor
    $ssh->write(":wq!\n");