How to Enable CageFS for OpenLiteSpeed¶
Before starting, please verify that CloudLinux and CageFS are properly installed and initiated:
[root@test ~]# cat /etc/redhat-release
CloudLinux release 7.6 (Vladimir Lyakhov)
[root@test ~]# /usr/sbin/cagefsctl --display-user-mode
Mode: Disable All
Configure WebAdmin¶
Log into the WebAdmin Console. Navigate to Server Configuration > General > Server Process. Set CloudLinux to CageFS
, save, and restart OpenLiteSpeed.
Add User¶
Add the user into CageFS with this command, making sure to replace example
with your PHP userid:
[root@test ~]# /usr/sbin/cagefsctl --enable example
Updating users ...
And that's it!
Verify¶
For demonstration purposes, create a test.txt
outside of the user home folder.
[root@test ~]# echo "CageFS test" > /test.txt
[root@test ~]# cat /test.txt
CageFS test
Create a PHP file to read it:
cat > /home/example.com/public_html/test.php << 'EOF'
<?php
$myfile = fopen("/test.txt", "r") or die("Unable to open file!");
echo fread($myfile,filesize("test.txt"));
fclose($myfile);
?>
EOF
[root@test ~]# curl -XGET http://example.com/test.php
CageFS test
Enable CageFS options in the WebAdmin Console and restart OpenLiteSpeed.
Try again to open the file.
[root@test ~]# curl -XGET http://example.com/test.php
Unable to open file!