Advertisement
Guest User

Initalize Opcache File Cache

a guest
Feb 27th, 2018
334
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.12 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. # NOTE
  4. # Opcache's file cache settings in /etc/php.d/opcache.ini:
  5. # opcache.file_cache=/dev/shm/opcache
  6. # opcache.file_cache_only=1
  7.  
  8. # Stop php-fpm
  9. ps aux | grep -q "[p]hp-fpm"
  10. if [ "$?" -eq "0" ]; then
  11. /usr/bin/systemctl stop php-fpm
  12. fi
  13.  
  14. # Remove existing cache dir
  15. if [ -d "/dev/shm/opcache" ]; then
  16. /bin/rm -rf /dev/shm/opcache
  17. fi
  18.  
  19. # Create a new writable cache dir
  20. mkdir /dev/shm/opcache
  21. chmod 1777 /dev/shm/opcache
  22.  
  23. # Start php-fpm
  24. /usr/bin/systemctl start php-fpm
  25.  
  26. # Visit a php script to trigger file caching & creation of the hashed dir
  27. /usr/bin/curl -s 'https://domain1.com/any-script.php' > /dev/null 2>&1
  28.  
  29. # Get the name of the hashed dir
  30. hashed_dir=$(ls -1 /dev/shm/opcache)
  31.  
  32. # Make the hashed dir writable by all users
  33. if [[ -n "$hashed_dir" && -d "/dev/shm/opcache/$hashed_dir" ]]; then
  34. chmod 1777 /dev/shm/opcache/$hashed_dir
  35. chown root:root /dev/shm/opcache/$hashed_dir
  36. fi
  37.  
  38. # Make the home subdir writable by all users
  39. if [ -d "/dev/shm/opcache/$hashed_dir/home" ]; then
  40. chmod 1777 /dev/shm/opcache/$hashed_dir/home
  41. chown root:root /dev/shm/opcache/$hashed_dir/home
  42. fi
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement