Plesk phpMyAdmin Export File Problem Fix for Large Databases

on Friday, 22 January 2010. Posted in Plesk

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

How-to show all ethernet devices installed on your system

on Monday, 19 January 2009. Posted in Linux

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.

How-to view the current usage of your partitions

on Monday, 19 January 2009. Posted in Linux

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

How-to copy a file

on Monday, 19 January 2009. Posted in Linux

Very simple usage of the "cp" command:

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

Description of the tar and find command options

on Monday, 19 January 2009. Posted in Plesk

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 work with tar and gzipped files

on Monday, 19 January 2009. Posted in Linux

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

How-to Tell Which Version of PHP, Perl, and MySQL you are running

on Monday, 19 January 2009. Posted in Linux

mysql -V

php -v

perl -v

Important Plesk File Locations

on Monday, 19 January 2009. Posted in Plesk

# 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

Correct httpdocs permissions

on Monday, 19 January 2009. Posted in Plesk

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.

How-to Tell Which Version of Redhat you are running

on Monday, 19 January 2009. Posted in Linux

You can type in the following at the command line to get the version of Redhat you are running:

cat /etc/redhat-release

Unfortunately, this method doesn't tell you whether you are running a 32-bit or 64-bit version of the operating system. In order to find out this information you could use the following command:

uname -a

Reconfiguring httpd.include via vhost.conf

on Monday, 19 January 2009. Posted in Plesk

Compared to a cPanel environment, where you are almost exclusively required to use a .htaccess file, in Plesk you are able to reconfigure Apache and add to the configuration file on the fly.

In every domain and sub domain created in Plesk there is a folder named "conf" that contains a file named "httpd.include" which contains the automatically generated Apache configuration created by Plesk. Since you don't want to edit an automatically generated file, Plesk includes a way to add-on to the httpd.include via the "vhost.conf" file. In the same "conf" folder, create a new file named "vhost.conf". I typically do this by typing in the following into the command line:

vi vhost.conf

I then add my Apache configurations to the vhost.conf file and then save them by typing in:

:w

Now you'll need to tell Plesk to reload it's Apache configuration by typing in the following (replace example.com with your domain name):

/usr/local/psa/admin/sbin/websrvmng -u --vhost-name=example.com

Plesk Help Resources

on Monday, 19 January 2009. Posted in Plesk

In my wanderings for Plesk assistance I have found the following resources helpful:

And of course, Parallels support has been pretty helpful in most situations too!

Script to Sync a Pre-production and Production Database in Plesk

on Monday, 19 January 2009. Posted in Plesk

This script was created over the course of a few days early on when I first began working. The way things had been setup, we had an instance of our CMS application using a pre-production database that periodically needed to be synced to our production database. Prior to my arrival this procedure had been completed manually every few hours.

Before this I had never written any sort of shell script so I had a fun time looking up the commands and figuring out how to write the script and get things working.

DBSYNC Shell Script for Plesk Servers

#!/bin/sh
# Plesk MySQL database synchronization script
# DBSYNC -- uses /usr/bin/mysqldump and /usr/bin/mysql to
# create a SQL dump file of the pre-production database
# and then uses this dump file to update the production
# database. SQL dump file is then compressed using gzip
# and is stored in /home/.bkup/dbbackups.
# Last Updated 01/19/2009 by Omar Ramos
# 1. Modified echos to use tee command to output to the screen
# and logfile at the same time.
# 2. Modified script to use /tmp so that the database import
# would successfully complete even if the backup partition
# is filled up.
# 3. Generalized script so that it could be used by others
# looking to implement similar functionality on their
# Plesk servers.

EXPORT_DB="your_pre_production_database_name"
IMPORT_DB="your_production_database_name"
# Gets the date in YYYY-MM-DD format
DATE=`/bin/date +%Y%m%d`
# Shortcut to get the current process ID
PID=$$
# Change to your backup directory location
EXPORT_DIR="/your/backup/directory"
# Change the mydb portion to something relevant for your situation
TMP_FILE_NAME="/tmp/$DATE-mydb-$PID.sql"
EXPORT_FILE_NAME="$EXPORT_DIR/$DATE-mydb-$PID.sql"
# Change to your log directory location
LOGFILE=/your/log/directory/DBSYNC.log

# The portions below that use the cat command pull in the Plesk admin
# password dynamically so that it can be used for the script.

#DB Dump Export File
/usr/bin/mysqldump --user=admin --password=`/bin/cat /etc/psa/.psa.shadow` $EXPORT_DB > $TMP_FILE_NAME
echo "Dumping database to $TMP_FILE_NAME from $EXPORT_DB ..." | tee -a $LOGFILE

#DB Dump File Import Database Location
/usr/bin/mysql --user=admin --password=`/bin/cat /etc/psa/.psa.shadow` -D $IMPORT_DB < $TMP_FILE_NAME
echo "Importing $TMP_FILE_NAME to $IMPORT_DB ..." | tee -a $LOGFILE

#gzip DB Dump File and Store in /your/backup/directory
mv $TMP_FILE_NAME $EXPORT_FILE_NAME
echo "Moving $TMP_FILE_NAME to $EXPORT_FILE_NAME ..." | tee -a $LOGFILE
gzip $EXPORT_FILE_NAME
echo "Gzipping $EXPORT_FILE_NAME ..." | tee -a $LOGFILE

#Piped to DBSYNC.log located in /your/log/directory when run
echo "DBSYNC Backup and Sync Performed on `date`" | tee -a $LOGFILE

Oracle OCI8 PHP Installation

on Monday, 19 January 2009. Posted in Plesk, Oracle

This is a reprint of a post I made on the Atomic Rocket Turtle Forums on September 15, 2008:

OK, I've accomplished my main goal for the day :-).

I've gotten the OCI8 PHP Module installed along with the Oracle Instant Client Library so now I can make calls to our Oracle database within PHP.

Awesome!

So this is what I needed to do.

Step 1: Download Oracle Instant Client Basic AND SDK Packages

To download Oracle Instant Client first go to:

http://www.oracle.com/technology/software/tech/oci/instantclient/index.html

And go to the download page for the version of Linux you are running (I'm running on x86_64, but you may be using x86) by clicking on the appropriate link (I clicked on "Instant Client for Linux x86-64").

The download page has two requirements: first you must accept the Oracle Terms, and second you're going to need an Oracle.com account (which is free, but you just need to register first). If you don't have an Oracle.com account yet, no worries as you'll be asked about it once you try and download a file.

You'll see a couple of different version for the Oracle Instant Client: Version 11.1.0.6.0, 10.2.0.4, etc.). Now I'm not 100% certain, but I am pretty sure that the 11.1.0.6.0 version dropped support for Oracle 9i (since I remember trying it out on my Windows PC with PHP and it couldn't connect to our database) so I decided to use 10.2.0.4 instead.

I downloaded both the Basic and the SDK Instant Client Packages in RPM format (since we have a Redhat server).

I do not know if you can use a wget to download the files or not, but what I did was download them both to my local Windows PC, and then SFTP them over to my home directory on the Plesk server.

Step 2: Install the Oracle Instant Client Basic and SDK Packages

With an RPM, the installation was fairly simple, and I am pretty sure installing from the zip file would be almost as easy (if somebody knows the procedure for the zip file it'd be nice of you to add a comment).

To install the Basic and SDK packages from SSH just go into your home directory (or wherever you placed the files) and then type in: rpm -ivh oracle-instantclient-basic-10.2.0.4-1.x86_64.rpm rpm -ivh oracle-instantclient-devel-10.2.0.4-1.x86_64.rpm

That will create a few different folders, but specifically the Oracle Instant Client files will be installed here: /usr/lib/oracle/10.2.0.4/client64/lib

You've now installed the Oracle Instant Client Basic Package and the SDK which you'll need to install the PHP OCI8 module.

Step 3: Download the OCI8 Extension from PECL

With PECL you can go about this a couple of different ways, but I just went to the OCI8 Extension Page:

http://pecl.php.net/package/oci8

And then downloaded the latest version of the extension to my local PC.

Then I created a folder named "oci8" on my Desktop and used 7-zip to extract the contents of the tgz file into the oci8 folder.

So in the oci8 folder on your Desktop you should have the following: A package.xml file A oci8-1.3.4 folder with some files inside.

Step 4: Build the PHP OCI8 Module

Now copy the oci8 folder to your home directory using a SFTP program like WinSCP.

I then followed this person's instructions, which I'll be going over here (I just wanted to provide some of the source for my success):
http://www.php.net/manual/en/oci8.setup.php#83323

Using SSH go into the oci8 folder that you just SFTP'd into your home directory and run the following command: pecl build

I'm trying to remember exactly what happened right now from memory, but I am pretty sure at this point that you will be prompted for the location of ORACLE_HOME. It really doesn't matter what you enter at this point though because it really doesn't take your input as it should so just press enter and let it take it's course.

After that's done run the following command: cd oci8-1.3.4

and then type in: ./configure --with-oci8=instantclient,/usr/lib/oracle/10.2.0.4/client64/lib and push enter.

 

You'll see quite a bit of output but you shouldn't run into any errors (I initially ran into an SDK issue because I hadn't download the Oracle Instant Client SDK Package).

Once that has completed type in the following: make

Which I suppose creates the oci8.so file.

And you've successfully built the oci8 PHP module :-).

Step 5: Install the OCI8 PHP Module

Now that everything has been built, there should be a new folder named "modules" in the oci8-1.3.4 folder.

cd into the modules directory and if you do an ls to see the folder contents you will see the oci8.so module. What you want to do now is copy it into the location where your other PHP modules are stored.

In my case this location is: /usr/lib64/php/modules/

So to do the copy from within the modules folder type in: cp oci8.so /usr/lib64/php/modules

Next, you have to add an .ini entry to your php.d folder so that php will try and load this extension when it starts up.

Go to your php.d folder by typing in: cd /etc/php.d

Then you are going to want to create a new oci8.ini file which you can do by typing in: vi oci8.ini

First press "i" on your keyboard to change the vi text editor to insert mode so that you can start typing and then type in: ; Oracle Instant Client Shared Object extension=oci8.so

Now press ":" (colon) and then "w" to write your changes to disk and then press ":" and then "q" to quit vi and go back to the command line. If you do an ls at this point you should see the new oci8.ini there.

You've successfully installed the OCI8 PHP Module into PHP, just one more step!

Step 6: Restart Apache to Load New Changes

To restart Apache all you need to do is type in: /etc/init.d/httpd restart

Everything should be working and the OCI functions should be available to your PHP scripts now. If you'd like to test further, you can create a phpinfo file (and then use Ctrl+F to do a search for oci8 in the output) and also try using the OCI functions by making a connection to your database and running a query.