Fix mkdir permission
Replace rm -rf with php equivalent