Tips and How-tos

I know there are a lot of places where you can probably find the code below, but instead of having to look it up again the next time I have to use it, I thought it'd be handy to just add it here as a how-to item.

The code uses the primary admin account which comes default with Plesk, and uses a snippet to pull in the password automatically, then the database name is specified along with a filename for the exported database.

On newer Plesk versions it seems the phpMyAdmin importing is a lot more robust (larger file sizes and execution times) you can then take the exported file and import it using phpMyAdmin into a new Plesk server (if you're migrating from an older Plesk version as I was).

/usr/bin/mysqldump --user=admin --password=`/bin/cat /etc/psa/.psa.shadow` mydatabasename > myexportfile.sql

Well, I was a little surprised today when I learned that Joomla 2.5 does not allow for users to change their own usernames (I'm sure there's a valid reason for it, but at the same time I have a valid need to allow it). 

Since I've allowed my support system to automatically create accounts it does so in a way that adds a lot of random numbers to the end of the username it creates for a user. Now if I were in my user's shoes and I saw that, I'd most likely want to go in and edit my username right away to something I could actually remember (even though I've already added the option of users to be able to use their emails instead using Michael Richey's useful authentication plugin).

So, here's what you do if you want to enable your users to be able to change their username in Joomla 2.5:

  1. First, open up components/com_users/models/forms/profile.xml go to line 28 and change where it says:
    readonly="true"
    So that it says:
    readonly="false"
  2. Second, open up components/com_users/models/profile.php go to line 230 and comment out this line:
    unset($data['username']); 
    By adding two forward slashes to the beginning of that line:
    //unset($data['username']); 

Here are a few screenshots demonstrating the corrected files:

01 allow username changes in joomla
Step 1 - Change username readonly attribute to false

02 allow username changes in joomla
Step 2 - Comment out line which disables username changes

I was having some trouble the other day exporting a database that was about 40MB from Plesk's phpMyAdmin area and was getting a page could not be found error (though it appeared to work when only trying to export one table). This gave me the sense that it might be a memory issue for Plesk's PHP installation, and on searching I found a really good Parallels forum thread with exact instructions on what to modify. I found these instructions here: http://forum.parallels.com/showthread.php?t=81020

Open your plesk php.ini (my plesk php.ini located: /usr/local/psa/admin/conf/php.ini) 
Find memory_limit change to example: memory_limit = 256M 
Stop and start psa services: 
/etc/init.d/psa stopall
/etc/init.d/psa start

Adding the "-a" option to the ifconfig command will show all of the ethernet devices installed on the computer:

ifconfig -a

The ifconfig command allows you to a whole lot more to configure your network interfaces, for additional options you can always check the Linux manual from the command line or you can visit the ComputerHope article on the command.

I haven't had to use this one much since most of the time there is a GUI representation of this available, but it does help to find out how much hard drive space you are currently using.

df -k

Very simple usage of the "cp" command:

# copy and preserve modification date of a file:
cp -p filename /copy/to/directory

tar options (and their meanings):

# (extract archive contents)
-x
--extract

# (list archive contents)
-t
--list

# (make new tar archive)
-c
--create

# (specify name of archive file)
-f
--file

# (show the files being worked on as the tar is being performed)
-v
--verbose

find options:

# (for greater than n)
+n
# (for less than n)
-n
# (for exactly n)
n
# (last modified n minutes ago)
-mmin n
# (last modified n*24 hours ago)
-mtime n
# (pattern represents a filename string to look for, may also contain special regular expression characters)
-name pattern
# (replace c with a d, for directory or f, for a regular file)
-type c
# (allows you to execute commands on every file found by the find command, very useful. You can use the special token {} which represents the current filename)
-exec
# (tells the find command how many folder levels to recurse through, use a 1 to only pick up files from the current directory)
-maxdepth n

Examples of using the find command

# returns all files matching the pattern created in the last 14 days
find -name 'var1*' -mtime -14

# returns all files over 14 days old
find -name 'var1*' -mtime +14

# finds all files matching the pattern and then executes the rm -R command on the file
# the final \ is necessary when using the -exec option because it signifies the end of the command you are trying to execute
find -name '_vti_cnf' -type d -exec rm -R {} \;

How to gzip a tar file:

gzip filename.tar

How to decompress a gzip file back to a tar file:

gunzip filename.tar.gz

How to create a .tgz file from a set of folders:

tar -czvf filename.tgz /folder/to/backup

How to decompress a .tgz file:

tar -xzvf archive.tgz

How to extract files from a compressed tarball:

# extract to same directory
tar -xzf archive.tar.gz

# extract to a specific directory
tar -xzf archive.tar.gz -C /location/to/extract/to

How to list files in tar or compressed tar file

tar -tf archive.tar
tar -tzf archive.tar.gz

How to tell which versions of tar and gzip are installed on your machine:

tar --version

gzip -v
# php.ini location
/etc/php.ini

# php.ini include files
/etc/php.d

# ioncube location on 64-bit OS
/usr/lib64/php/ioncube

# httpd.conf location
/etc/httpd/conf/httpd.conf

# httpd.conf include files
/etc/httpd/conf.d

# php.conf location
/etc/httpd/conf.d/php.conf

When Plesk creates an account for you it will always assign the httpdocs folder to the "psaserv" group, and all files within the httpdocs folder to the "psacln" group.

Sometimes you may run into trouble should you accidentally modify these groups (especially when you change the group of the httpdocs folder from psaserv) so should you need to restore these groupings you may run the following commands in succession:

chown -R your_plesk_username:psacln /your/httpdocs/directory
chown your_plesk_username:psaserv /your/httpdocs/directory

What the first command does is make sure that all of the files and folders within your httpdocs folder are correctly within the "psacln" group. The negative side effect of using the "-R" directive is that it also changes the permissions of the httpdocs directory itself, leading to the second command which only changes the httpdocs folder itself to be part of the "psaserv" group, while leaving the files and folders within with the correct grouping.