Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- # NOTE
- # Opcache's file cache settings in /etc/php.d/opcache.ini:
- # opcache.file_cache=/dev/shm/opcache
- # opcache.file_cache_only=1
- # Stop php-fpm
- ps aux | grep -q "[p]hp-fpm"
- if [ "$?" -eq "0" ]; then
- /usr/bin/systemctl stop php-fpm
- fi
- # Remove existing cache dir
- if [ -d "/dev/shm/opcache" ]; then
- /bin/rm -rf /dev/shm/opcache
- fi
- # Create a new writable cache dir
- mkdir /dev/shm/opcache
- chmod 1777 /dev/shm/opcache
- # Start php-fpm
- /usr/bin/systemctl start php-fpm
- # Visit a php script to trigger file caching & creation of the hashed dir
- /usr/bin/curl -s 'https://domain1.com/any-script.php' > /dev/null 2>&1
- # Get the name of the hashed dir
- hashed_dir=$(ls -1 /dev/shm/opcache)
- # Make the hashed dir writable by all users
- if [[ -n "$hashed_dir" && -d "/dev/shm/opcache/$hashed_dir" ]]; then
- chmod 1777 /dev/shm/opcache/$hashed_dir
- chown root:root /dev/shm/opcache/$hashed_dir
- fi
- # Make the home subdir writable by all users
- if [ -d "/dev/shm/opcache/$hashed_dir/home" ]; then
- chmod 1777 /dev/shm/opcache/$hashed_dir/home
- chown root:root /dev/shm/opcache/$hashed_dir/home
- fi
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement