Tuesday, May 7, 2013

Find currently logged users on a linux system

With the who command you can list the current logged users on a linux system:

# who

user     tty7         2013-05-07 09:18 (:0)
roy     pts/0        2013-05-07 14:47 (:0.0)
tony     pts/1        2013-05-07 14:49 (:0.0)
ana     pts/2        2013-05-07 15:18 (:0.0)

If the list is too long, and you want to search for a specific user, you can use grep:

# who | grep ana

ana     pts/2        2013-05-07 15:18 (:0.0)

Thursday, April 18, 2013

Linux: check available space on each filesystem

To check used/available space on each filesystem, use the following command:

df -h

example output:

Filesystem            Size  Used Avail Use% Mounted on
/dev/sda1             285G   16G  256G   6% /
none                  1.9G  288K  1.9G   1% /dev
none                  1.9G  3.6M  1.9G   1% /dev/shm
none                  1.9G  100K  1.9G   1% /var/run
none                  1.9G     0  1.9G   0% /var/lock


-h param stands for human-readable and if you don't specify it, sizes will be printed in bytes

Ubuntu: Add new domain / subdomain in apache

Navigate to /etc/apache2/sites-available. Create a file with your new domain name and add the following:

#file: mydomain.com
<VirtualHost *:80>
        ServerName mydomain.com
        DocumentRoot /root/directory/of/site
</VirtualHost>

Enable the configuration for the new domain with the following command:

a2ensite mydomain.com

 Restart Apache

service apache2 restart

Wednesday, April 17, 2013

change date.timezone in php

Open php.ini file and search for date.timezone directive. It should look something like this:

[Date]
; Defines the default timezone used by the date functions
; http://php.net/date.timezone
date.timezone = 'America/New_York'

or you can use the ini_set() function. Just add at top of your script:

ini_set('date.timezone', 'America/New_York'); 

Here is a list of time zones: http://php.net/manual/en/timezones.php

create and delete symbolic links in linux

Create a symlink

ln -s /path/to/file/or/dir /path/to/symbolic/link

Delete a symlink

 unlink /path/to/symbolic/link

Example:

Create a symlink for file.gz which is placed in /home dir

ln -s /home/file.gz /home/user/file.gz

Delete the symlink for file.gz

unlink /home/user/file.gz

or simply delete the symbolic link with the rm command

rm /home/user/file.gz

Tuesday, April 16, 2013

PHP increase file upload size

 You can increase file upload size by setting upload_max_filesize to a higher value. Find the upload_max_filesize directive in php.ini and change the default value:
; Maximum allowed size for uploaded files.
; http://php.net/upload-max-filesize
upload_max_filesize = 8M

Restart apache so the new configuration can take effect:
/etc/init.d/apache2 restart

PHP Disable File Upload

Open php.ini file and find the file_uploads directive. It should look something like this:
; Whether to allow HTTP file uploads.
; http://php.net/file-uploads
file_uploads = On

To disable file uploads in php set the directive to Off:
file_uploads = Off

Restart apache with the following command
service apache2 restart

Note: In Ubuntu php.ini file can be found udner: /etc/php5/apache2