How to automatically start Apache on Solaris 9 reboot/boot

July 6th, 2009

Here’s how you can have Apache automatically start on system reboot/boot on Solaris 9.

  1. become root user
  2. cd /etc/init.d
  3. ls -al to see if there is a file named “apache.”
  4. If not, create a file named “apache” with the following:
  5. #!/sbin/sh
    #
    # Copyright 2004 Sun Microsystems, Inc. All rights reserved.
    # Use subject to license terms.
    #
    #ident “@(#)apache.sh 1.3 04/07/18 SMI”

    APACHE_HOME=/usr/local/apache2
    CONF_FILE=/usr/local/apache2/conf/httpd.conf
    PIDFILE=/var/run/httpd.pid
    TOMCAT_CF=/var/apache/tomcat/conf/server.xml

    if [ ! -f ${CONF_FILE} ]; then
    exit 0
    fi

    # see if we need to start/stop tomcat also

    CF=`egrep ‘^[ \t]*include[ \t]*/etc/apache/tomcat.conf’ $CONF_FILE`
    if [ -n "$CF" -a -f $TOMCAT_CF ]; then
    TOMCAT=yes
    TC_USER=`egrep ‘^[ \t]*User[ \t]‘ $CONF_FILE | nawk ‘{print $2}’`
    else
    TOMCAT=no
    fi

    case “$1″ in
    start)
    /bin/rm -f ${PIDFILE}
    cmdtext=”starting”
    if [ "x$TOMCAT" != xno ]; then
    (CATALINA_HOME=${APACHE_HOME}/tomcat; export CATALINA_HOME; \
    CATALINA_BASE=/var/apache/tomcat; export CATALINA_BASE; \
    JAVA_HOME=/usr/java; export JAVA_HOME; \
    /bin/su $TC_USER -c \
    “$CATALINA_HOME/bin/startup.sh”) \
    >/dev/null 2>&1
    fi
    ;;
    restart)
    cmdtext=”restarting”
    ;;
    stop)
    cmdtext=”stopping”
    if [ "x$TOMCAT" != xno ]; then
    (CATALINA_HOME=${APACHE_HOME}/tomcat; export CATALINA_HOME; \
    CATALINA_BASE=/var/apache/tomcat; export CATALINA_BASE; \
    JAVA_HOME=/usr/java; export JAVA_HOME; \
    /bin/su $TC_USER -c \
    “$CATALINA_HOME/bin/shutdown.sh”) \
    >/dev/null 2>&1
    fi
    ;;
    *)
    echo “Usage: $0 {start|stop|restart}”
    exit 1
    ;;
    esac

    echo “httpd $cmdtext.”

    /bin/sh -c “${APACHE_HOME}/bin/apachectl $1″ >/dev/null 2>&1
    status=$?

    if [ $status != 0 ]; then
    echo “exit status $status”
    exit 1
    fi
    exit 0

  6. Make sure the APACHE_HOME and CONF_FILE have the correct paths.
  7. chmod 744 /etc/init.d/apache
  8. Test your script to make sure it works:
    ./apache start
  9. cd /etc/rc3.d
  10. See if the “S50apache” symbolic link exists in that directory. If not then create the symbolic link (make sure you are not going to overwrite anything)
    ln -s /etc/init.d/apache S50apache
  11. Reboot the system by typing:
    /usr/sbin/reboot

apache, linux/unix, migration, php, ssh, web server

Start Sun One Web Server 7 on boot (Solaris 9)

June 10th, 2009

During the Sun One Web Server install, there is an option to have the web server start on system boot or reboot. In the case that you did not select this option, but would like the web server to start on boot, here’s how you do it.

  1. su -
  2. cd /etc/init.d
  3. create a file named SunWebServer7, and add the following:
    #!/sbin/sh

    #start SunOneWebServer 7 on system restart and boot

    case “$1″ in
    start)
    /var/opt/SUNWwbsvr7/https-SERVERNAME.com/bin/startserv
    ;;
    stop)
    /var/opt/SUNWwbsvr7/https-SERVERNAME.com/bin/stopserv
    ;;
    restart)
    /var/opt/SUNWwbsvr7/https-SERVERNAME.com/bin/restartserv
    ;;
    *)
    echo $”usage: $0 {start|stop|restart}”
    exit 1
    esac

  4. replace SERVERNAME with the name of your server
  5. make sure SunWebServer7 has the same ownership and permissions as the other files in the /etc/init.d directory
  6. create symbolic links to this script in the /etc/rc*.d/ directories. For example:

    ln -s /etc/init.d/SunWebServer7 /etc/rc0.d/K99SunWebServer

linux/unix, web server , ,

SSH Authorized Keys setup – login with no password

March 6th, 2009

SSH Authorized keys allow you to login to a Linux server with no password. This is particularly helpful if you are running an automated script, like a cron job.

For this example, let’s say you want to login in to server B from server A with no password.

a@A:~> ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/home/a/.ssh/id_rsa):
Created directory ‘/home/a/.ssh’.
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /home/a/.ssh/id_rsa.
Your public key has been saved in /home/a/.ssh/id_rsa.pub.
The key fingerprint is:
3e:4f:05:79:3a:9f:96:7c:3b:ad:e9:58:37:bc:37:e4 a@A

Now use ssh to create a directory ~/.ssh as user a on B. (The directory may already exist, which is fine):

a@A:~> ssh a@B mkdir -p .ssh
a@B’s password:

Finally append a’s new public key to a@B:.ssh/authorized_keys and enter a’s password one last time:

a@A:~> cat .ssh/id_rsa.pub | ssh a@B ‘cat >> .ssh/authorized_keys’
a@B’s password:

From now on you can log into B as a from A as a without password:

a@A:~> ssh a@B

If you would like to login to other remote server C, do not generate a new id_rsa.pub file. Just do the following:

a@A:~> cat .ssh/id_rsa.pub | ssh a@C ‘cat >> .ssh/authorized_keys’
a@C’s password:

linux/unix, ssh

AMFPHP error – PHP Fatal error: date(), system’s timezone settings

March 6th, 2009

If you get the following error in AMFPHP (I got it using the AMFPHP browser):

[Fri Jan 30 12:49:56 2009] [error] [client 192.168.1.x] PHP Fatal error:
Uncaught exception ‘VerboseException’ with message ‘date(): It is not safe
to rely on the system’s timezone settings. Please use the date.timezone setting,
the TZ environment variable or the date_default_timezone_set() function.
In case you used any of those methods and you are still getting this warning,
you most likely misspelled the timezone identifier. We had to select ‘UTC’
because your platform doesn’t provide functionality for the guessing algorithm’
in /path/amfphp/core/amf/app/Gateway.php:213\nStack trace:\n#0 [internal function]: amfErrorHandler(2, ‘date(): It is n…’, ‘/path…’, 213, Array)\n#1 /path/amfphp/core/amf/app/Gateway.php(213): date(‘D, j M Y ‘)\n#2 /path/amfphp/gateway.php(154): Gateway->service()\n#3 {main}\n thrown in /path/amfphp/core/amf/app/Gateway.php on line 213, referer: http://yourdomain.com/somefile

Then you need to edit the following variable in your php.ini file:

date.timezone =”US/Eastern”

amfphp, php

mysql database replication

March 6th, 2009

This MySQL replication example is specific to Red Hat Enterprise Server 5, so you may need to modify these directions on other flavors of Linux/UNIX.

For basic MySQL replication, there will be a master server and a slave server. In this example, we will use IP addresses for each of these servers. Let’s say:

Master server: 192.16.1.1

Slave server: 192.168.1.2

Step 1: set up user accounts

It’s best to create a new mysql user that will be solely responsible for the replication process. We’ll call this user “repl.”

First login to the master server, and then get to the mysql command line:

# mysql -u username -p

Enter your password when prompted.

At the mysql prompt:

mysql> GRANT REPLICATION SLAVE, REPLICATION CLIENT ON *.* TO ‘repl’@’192.168.1.2′ IDENTIFIED BY ‘password’;

Be sure to replace ‘password’ with whatever you want. Note that we are granting these privileges to the ‘repl’ user on the SLAVE server (see the IP). We’ll repeat this on the slave server being sure to change the ip address:

Now login to the slave server, and then get to the mysql command line:

# mysql -u username -p

Enter your password when prompted.

At the mysql prompt:

mysql> GRANT REPLICATION SLAVE, REPLICATION CLIENT ON *.* TO ‘repl’@’192.168.1.1′ IDENTIFIED BY ‘password’;

Be sure to replace ‘password’ with whatever you want. Note that we are granting these privileges to the ‘repl’ user on the MASTER server (see the IP).

Step 2: edit the mysql /etc/my.cnf file on the master server

On the MASTER server, edit the /etc/my.cnf file in the editor of you choice. Below is the an example my.cnf file. Your file may look different. Add only the bolded lines to your file. The other lines of your file should not have to be changed. These two lines will give your server and id and tell in to start binary logging.

[mysqld]
server_id=1
log-bin=/var/lib/mysql/logs/superfly-bin.log

datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
user=mysql
# Default to using old password format for compatibility with mysql 3.x
# clients (those using the mysqlclient10 compatibility package).
old_passwords=1

[mysqld_safe]
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid

–END FILE–

From the command line, restart mysql:

# service mysqld restart

Step 3: getting a snapshot of the current state of the database(s)

The next step involves temporarily preventing any data changes to any MySQL databases on your system, so be sure to warn any users. Start up the mysql command line client:

# mysql -u username -p

Enter your password when prompted, and then enter the following commands:

mysql> FLUSH TABLES WITH READ LOCK;

mysql> SHOW MASTER STATUS; (BE SURE TO NOTE THE ‘File’ and ‘Position’ VALUES–let’s say they have these values; ‘master-bin.00001′ and ’98′ respectively)

Back at the system command line:

# mysqldump –all-databases –master-data > dbdump.db

This will give you a snapshot of the current state of you databases. In a coming step, you will load this data in the slave server.

Back at the mysql prompt:

mysql> UNLOCK TABLES;

Now your users can make changes to your database(s). Copy (scp) the “dbdump.db” file to your SLAVE server.

Step 4: edit the mysql /etc/my.cnf file on the slave server

Now onto the SLAVE server, edit the /etc/my.cnf file in the editor of you choice. Below is the an example my.cnf file. Your file may look different. Add only the bolded lines to your file. The other lines of your file should not have to be changed.

[mysqld]
server_id=2
log-bin=/var/lib/mysql/logs/dolemite-bin.log
log-bin-index=/var/lib/mysql/logs/dolemite-bin.index
log-error=/var/lib/mysql/logs/dolemite-error.log
relay-log=/var/lib/mysql/logs/dolemite-relay.log
relay-log-info=/var/lib/mysql/logs/dolemite-relay.info
relay-log-index=/var/lib/mysql/logs/dolemite-relay.index
log-slave-updates
log-warnings

# Slave details
report-host=192.168.1.2

# Master details
master-host=192.168.1.1
master-user=repl
master-password=password
(set this to whatever you set on the master server)
master-port=3306

datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
user=mysql
# Default to using old password format for compatibility with mysql 3.x
# clients (those using the mysqlclient10 compatibility package).
old_passwords=1

[mysqld_safe]
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid

– END FILE –

Step 5: Starting with a clean database, import your dump file:

# mysql -u username -p < dbdump.db

Enter your password when prompted.

Step 6: initialize slave with values from SHOW MASTER STATUS from master:

mysql> change master to MASTER_LOG_FILE=’master-bin.00001′,MASTER_LOG_POS=98;
mysql> start slave;

The databases should now be replicating…

ERRORS?

If you get the following error:

mysql> start slave;
ERROR 1200 (HY000): The server is not configured as slave; fix in config file or with CHANGE MASTER TO

Then do this:

mysql> reset slave;
Query OK, 0 rows affected (0.06 sec)

mysql> reset master;
Query OK, 0 rows affected (0.04 sec)

mysql> start slave;
Query OK, 0 rows affected (0.03 sec)

That should fix your error.

NOTE:

If you want to check the status of your slave server, from the mysql prompt on the slave server:

mysql> SHOW SLAVE STATUS;

mysql , , , ,

How to migrate WordPress to another server

March 6th, 2009

Here’s the basic steps to migrate WordPress to another server. Most steps are high level.

1. tar up existing site and extract files on new server
2. create db on new server, then move data
3. setup db user
4. database changes:

UPDATE wp_options SET option_value = replace(option_value, ‘http://old.domain.com’, ‘http://new.domain.com’) WHERE option_name = ‘home’;
UPDATE wp_options SET option_value = replace(option_value, ‘http://old.domain.com’, ‘http://new.domain.com’) WHERE option_name = ‘siteurl’;
UPDATE wp_posts SET guid = replace(guid, ‘http://new.domain.com’,”);
UPDATE wp_posts SET post_content = replace(post_content, ‘http://new.domain.com’, ”);

5. using the Dashboard, go to Settings –> Miscellaneous Settings and update upload dir

linux/unix, migration ,

Get web server info from Linux command line

March 6th, 2009

Ever want to know what platform a website is running on? If there isn’t the obvious “.apsx” or other file extension, give this a try from command line (using deeblake.com as example):

type this and hit ENTER:

# telnet www.deeblake.com 80

you get this:
Trying 208.113.238.218…
Connected to www.deeblake.com (208.113.238.218).
Escape character is ‘^]’.

then type this and then hit ENTER twice:

GET / HTTP/1.1

you’ll get something like this:


HTTP/1.1 400 Bad Request
Date: Fri, 06 Mar 2009 19:43:49 GMT
Server: Apache/2.0.63 (Unix) PHP/4.4.7 mod_ssl/2.0.63 OpenSSL/0.9.7e mod_fastcgi/2.4.2 DAV/2 SVN/1.4.2
Content-Length: 226
Connection: close
Content-Type: text/html; charset=iso-8859-1

<!DOCTYPE HTML PUBLIC “-//IETF//DTD HTML 2.0//EN”>
<html><head>
<title>400 Bad Request</title>
</head><body>
<h1>Bad Request</h1>
<p>Your browser sent a request that this server could not understand.<br />
</p>
</body></html>
Connection closed by foreign host.

Notice the “Server” line that has all of the platform specs.

http, linux/unix, web server , ,

Install Pear Spreadsheet_Excel_Writer package on Red Hat ES5

February 18th, 2009

As of this posting, the Pear Spreadsheet_Excel_Writer package is available only in a beta release. Running the following command gives errors:

pear install http://download.pear.php.net/package/Spreadsheet_Excel_Writer-0.9.1.tgz

Since this package is in a beta release. Try running this command instead:

pear install -f ––alldeps http://download.pear.php.net/package/Spreadsheet_Excel_Writer-0.9.1.tgz

The “-f” forces the install. The “––alldeps” flag is included to that package dependencies are also downloaded and installed.

linux/unix, php , ,

how to shutdown a Solaris server

February 5th, 2009

Here’s how to shutdown a Solaris server:

  1. login as root
  2. at the command line, type “sync”
  3. type “sync” a second time
  4. now type /etc/telinit 0   (NOTE: 0 = shutdown, s = single user mode, 6 = reboot)
  5. you will eventually get to an ‘ok’ prompt

From here you can actually unplug the server. If you would like to start the server up again, just type “boot” at the “ok” prompt.

linux/unix , ,

find command in linux

February 5th, 2009

Here’s a simple and effective use of the linux “find” command. Let’s say you want to find out what directory mysql was installed in. As root, cd to /. Then type this command:

find . -name mysql -print

This will print out the full path to all occurences of “mysql” in the filesystem.

linux/unix, mysql