I have over 5 million session files in /var/lib/php5
I would like to delete all files in this folder using rm *, however I'm not sure if there are other files other than the session files in that directory that should not be deleted.
Through SSH it took a few minutes to make the file count and I'm not sure I can navigate through there with all these random filenames.
The setup is ubuntu lucid linx, apache 2 and php5. In the most common of setups are there other folders / files in /var/lib/php5 that I should not delete?
Edit The reason I want to remove the files is because I moved session handling to a database and don't need any of the files anymore.
cd /var/lib/php5
find . -name "sess_*" -print | xargs rm -v
Let PHP's gc perform cleanup by itself. Find php.ini and change session.gc_probability to something bigger, save it and restart Apache (call any php script). It says here http://somethingemporium.com/2007/06/obscure-error-with-php5-on-debian-ubuntu-session-phpini-garbage
In Debian and Ubuntu, /var/lib/php5, where the session data is stored,
has permissions of drwx-wx-wt and should only be cleaned by a cron
script. So, the package maintainers disable automatic session garbage
collection.
Or you could try to put ini_set('session.gc_probability', 100); session_start(); (if your session.gc_divisor is equal to 100) in one of your scripts and call it. The best way is to put in empty php file, because it might perform cleanup for a very long period of time.
ps: I would also try to leave session.gc_probability 1 and set session.gc_divisor to 1. It should call gc at every run, but you need it just for a directory cleanup.
And check your cron /etc/cron.d/php5 - it should run every half an hour to purge session files in the /var/lib/php5/ directory.
pps: found interesting comment
This does not disable it (it is commented out). The default within the
engine is still used - phpinfo() shows the value to be 1. There is a
problem with garbage collection in Debian (and thus Ubuntu) but that's
due to PHP wanting to vacuum garbage that has already been removed by
the cron script. This causes an error that may be displayed on the
unlucky page.
in PHP7, this worked
cd /var/lib/php/sessions/
sudo find . -name "sess_*" -print |sudo xargs rm -v
If you're using CODEIGNITER, then try with following commands.
cd /var/lib/php/sessions/
sudo find . -name "ci_*" -print |sudo xargs rm -v
sudo find . -name "cises*" -print |sudo xargs rm -v
cd /var/lib/php5
sudo find . -name "sess_*" -print |sudo xargs rm -v
This has worked in my case .
On my ubuntu computer, at /var/lib/php5, there is a sess ID file:
sess_a7kjdaojmneuhcgslj
If I tried to remove this file using the command:
sudo rm sess_a7*
I got an error message saying there is no such a file. I had to use the full name as:
sudo rm sess_a7kjdaojmneuhcgslj
It worked. This is my two cents.
Related
I'm troubleshooting a php log file that has expanded way too rapidly and used up a lot of disk space.
What is the best way to clear a log file?
is it a problem to simply delete the log file? And will that log file be recreated as php tries to write to it?
It is entirely safe to just delete the php.log file. It will be auto-created the next time it is needed.
On Linux you can do :
cat /dev/null > /var/logs/php.log
On Mac OS X 10.6 I deleted /var/log/apache2/error_log. Minor panic when it didn't re-appear upon refreshing my page. Just had to restart apache by going through the Sharing settings. Now she's back.
It IS safe to delete the log file by doing the following:
Delete the php.log file altogether.
If on Apache Restart the Server using "service apache2 restart" command
If on NGINX you do not have to restart the server
You can run this simple command from terminal(in WHM) or From SSH terminal.
find -name error_log -type f -exec rm -rf {} \;
This command will find all files with name "error_log" and remove it.
Enjoy.
Hi I currently have a magento 1.9 site which i use session storage as files as i find that using the database is very slow.
I currently have about 16 gig of session files which i want to delete.
If I run:
find . -name 'sess*' -mtime +7 -exec rm -f {} \;
The site grinds to a halt and then kills the database attached.
I then looked at garbage collection I changed:
session.gc_probability = 1
session.gc_divisor = 100
When I did this and restarted apache the site crashed too?
What would be the best way to remove these files?
You can delete the whole folder, from your Magento Root with the following
rm -rf var/session/*
Also, if you have enought RAM, you should consider using Redis to store session. Here is a nice tuto for Magento 1.
first go to the var/session folder of the magento root directory
find . -name "*" -print | xargs rm -rf
This command will delete all the data in the current folder without prompting you.
I know this may seem as a repeated question but so far I have 4 hours digging around unable to find a straight answer to this. I have setup a brand new CentOS 7 and I installed NGINX (https://www.digitalocean.com/community/tutorials/how-to-install-linux-nginx-mysql-php-lemp-stack-on-centos-7) + PHP 5.6 (https://webtatic.com/packages/php56/) and MariaDB.
Following the guides I was able to make the NGINX serve PHP files successfully.
I have a project in Symfony2 which I am trying to get in this server, my problem is when I try to open up http://server/web/app.php. I get the following error:
Fatal error: Uncaught exception 'RuntimeException' with message 'Unable to create the cache directory (/usr/share/nginx/html/app/cache/prod) ' in ................
I read in the documentation (http://symfony.com/doc/current/book/installation.html) that I should work around my permissions so I was able to apply the following:
$ HTTPDUSER=`ps aux | grep -E '[a]pache|[h]ttpd|[_]www|[w]ww-data|[n]ginx' | grep -v root | head -1 | cut -d\ -f1`
$ sudo setfacl -R -m u:"$HTTPDUSER":rwX -m u:`whoami`:rwX app/cache app/logs
$ sudo setfacl -dR -m u:"$HTTPDUSER":rwX -m u:`whoami`:rwX app/cache app/logs
Since I have CentOS 7 from scratch that was the option that I was able to apply. However, I still have the same issue, after this approach these are the other options I've tried:
changed the owner for app/cache and app/logs to nginx:nginx
changed the permissions to 777 to the above folders
verified and re-verified that PHP is running under the nginx user, I had to change this in the www.conf
if I do ls -Al it shows that app/cache and app/logs are owned by nginx
restarted services after each single change
restarted the server completely
cleared the cache and performed warmup and still
Tried the umask option provided by symfony and still.
So after all these options I still get the same issue, to other people out there with this problem it's simply following the Symfony2 guidelines for applying the ACL and puff, done. But this is not the case.
What am I missing?
Ps: I double checked the permissions of the folder..and I am in the server as root.
Update 1
I re-installed CentOS 7 from scratch and followed https://www.digitalocean.com/community/tutorials/how-to-install-linux-nginx-mysql-php-lemp-stack-on-centos-7 and in combination with Symfony's suggestion for the configuration file and still I get the " Uncaught exception 'RuntimeException' with message 'Unable to create the cache directory" error
You might be running into SELinux issues, since CentOS 7 ships with SELinux running by default.
You can test by executing setenforce 0 to see if that solves the problem. If that works, you need to configure SELinux to allow the nginx user to write to the cache directory, and then re-enable SELinux. SELinux does provide some good security, so it would be best to figure out how to configure it properly, as opposed to turning it off completely.
You need to add a local custom rule (policy module), suppose you have your application under the /usr/share/nginx/www directory:
semanage fcontext -a -t httpd_sys_rw_content_t '/usr/share/nginx/www/.+/app/(cache|logs)(/.*)?'
You need to restore the contexts for all the files in that dir:
restorecon -Rv /usr/share/nginx/www/your-app-dir
Change the group of the cache and logs directories and add permissions for the group:
chgrp -R apache /usr/share/nginx/www/your-app-dir/app/{cache,logs}
chmod -R 775 /usr/share/nginx/www/your-app-dir/app/{cache,logs}
first I took you to excuse my English.
I made a website with Symfony which works fine locally. (dev and prod).
But as soon as I put online the dev version works but the prod version displays a blank page.
Lighttpd does not give me error.
PHP does not give me error.
Cache and log are writable.
I do not understand anything.
OK, this is highly undesirable situation as you need to squash bugs one-by-one. It could be as benign as missing php module or some major httpd misconfiguraion.
Some steps that should shed some light on the issue:
Fire up the Terminal (you do have ssh access, right?)
Check logs (both httpd and symfony)
httpd log:
tail -f /var/log/httpd/error_log
... and refresh your page
Symfony
tail -f /path-to-your-symfony-app/app/logs/prod.log
... again, refresh your page
In your comment, you said you encountered HTTP500 error. Is that Apache's or Symfony's HTTP500?
If you do not hape ssh access upload your app_dev.php and run it directly. Be sure to add your IP address to list of allowed (within the file)
Change your permission on cache and log folders in 777.
chmod 777 cache/ log/ -R
php symfony cc
As the documentation says:
Instead of the Welcome Page, you may see a blank page or an error page. This is caused by a directory permission misconfiguration. There are several possible solutions depending on your operating system. All of them are explained in the Setting up Permissions section.
And then you should follow these steps:
rm -rf app/cache/*
rm -rf app/logs/*
HTTPDUSER=' ps aux | grep -E '[a]pache|[h]ttpd|[_]www|[w]ww-data|[n]ginx' | grep -v root | head -1 | cut -d\ -f1'
sudo setfacl -R -m u:"$HTTPDUSER":rwX -m u:'whoami':rwX app/cache app/logs
sudo setfacl -dR -m u:"$HTTPDUSER":rwX -m u:'whoami':rwX app/cache app/logs
I did the deployment as guided in this official docs
In my case the update of symfony before deploying was not BC with an old Bundle, so the clear:cache --env=prod was giving some error. So what I did was to manually delete the prod cache and then clear:cache with the prod environment and it worked: so to resume:
#rm -rf app/cache/prod/* #removes only production cache
rm -rf app/cache/ #removes prod and any other stage cache
php app/console cache:clear --env=prod
I'm troubleshooting a php log file that has expanded way too rapidly and used up a lot of disk space.
What is the best way to clear a log file?
is it a problem to simply delete the log file? And will that log file be recreated as php tries to write to it?
It is entirely safe to just delete the php.log file. It will be auto-created the next time it is needed.
On Linux you can do :
cat /dev/null > /var/logs/php.log
On Mac OS X 10.6 I deleted /var/log/apache2/error_log. Minor panic when it didn't re-appear upon refreshing my page. Just had to restart apache by going through the Sharing settings. Now she's back.
It IS safe to delete the log file by doing the following:
Delete the php.log file altogether.
If on Apache Restart the Server using "service apache2 restart" command
If on NGINX you do not have to restart the server
You can run this simple command from terminal(in WHM) or From SSH terminal.
find -name error_log -type f -exec rm -rf {} \;
This command will find all files with name "error_log" and remove it.
Enjoy.