Posts Tagged ‘mysql’

PHP/MySQL mass update script

hostgator wordpress hosting I didn’t want to grind out a whole bunch of clicks in PHPMyAdmin to update the domain name on a wordpress install so I created this mass update script. Searches multiple database, tables, columns for specified search string and replaces the search string with a replacement string.

subversion and warehouse

I had first heard about the Warehouse subversion browser a couple of months back. At the time it was still closed source and cost $30 per server license. Recently though, it went open source and is now freely available. For those of you with about 1-2 hours of time and know how to setup and run subversion on a Linux/Unix box (with WebDAV) it really isn’t that hard to get up and running.

I installed this on one of my home Debian Etch (4) servers and it took me about 30 minutes once I understood the entire process.

  1. Install some necessary dependencies for building (I prolly left out a few) – make, rake, unzip, zip, tar, gzip, bzip2, libc6, gcc, cpp, g++
  2. Install Ruby
    • download the latest tarball (source code in tar.gz) here – http://www.ruby-lang.org/en/downloads/wget ftp://ftp.ruby-lang.org/pub/ruby/1.8/ruby-1.8.7-p72.tar.gz
    • run – tar xzvf ruby*.tar.gz – to open up the archive
    • cd into the directory – cd ruby*
    • configure, make and then install –> 1) ./configure 2) make 3) make install (as root)
  3. Install Swig
    • download one of the latest tarballs – wget http://internap.dl.sourceforge.net/sourceforge/swig/swig-1.3.31.tar.gz
    • unarchive the archive – tar xzvf swig-1.3.31.tar.gz
    • get into the directory – cd swig-1.3.31
    • configure, make, then install –> 1) ./configure 2) make 3) make install (as root)
  4. Install Subversion and the Swig-Ruby bindings
    • download one of the latest subversion archives – wget http://subversion.tigris.org/downloads/subversion-1.5.5.tar.gz
    • unarchive that sucker – tar xzvf subversion*.tar.gz
    • get into the directory that was just created – cd subversion*
    • configure for installation (and if you are missing anything be sure to install it!) – ./configure –enable-shared –enable-static –enable-debug –with-ssl –with-swig
    • make and install –> 1) make 2) make install
    • now install the swig-ruby bindings –> 1) make swig-rb 2) make install-swig-rb
  5. Install various dependencies for later: apache2 with WebDAV support, ruby gems, MySQL server/client, PHPMyAdmin might be handy as well
  6. Download the Warehouse source code – http://github.com/entp/warehouse/tree/master
  7. Untar into where you want Warehouse to start from: tar xvzf, mv, and whatnot.
  8. Setup a 3 MySQL databases (warehouse_test, warehouse_production, warehouse_dev) that can be accessed by 1 user for testing, production and development.
  9. Now run the warehouse bootstrapping program and setup procedures. (No registration key needed now that it is open source, so leave that field blank.) – http://www.warehouseapp.com/installing/installing-and-registering-warehouse
  10. In the Warehouse settings, be sure to setup warehouse so that it updates your WebDAV permissions and passwords.
    • Shell command to run when permissions are updated. This will auto-generate the necessary permission file for WebDAV: rake warehouse:build_config CONFIG=[warehouse directory]/config/access.conf
    • Shell command to run when someone’s password is updated. This will auto-generate the necessary password file for WebDAV: rake warehouse:build_htpasswd CONFIG=[warehouse directory]/config/htpasswd.conf

debian 4 web server setup

First post in awhile! I just had to get that out there. Well it has been an intense couple of weeks with college life really starting to kick in (the tests and lectures) and my work being the way it has. But I am back serving up cookbook recipies. Today’s is about setting up a debian based web server (for those of you with a vps or dedicated box). It is assumed that you are able to send mail directly from this box. Enjoy.

1) Install debian from floppies, full cd, or cd net install. Pretty self explanitory. I suggest doing it from floppies or cd net install, because we want to save as much disk space as possible for data.

2) Log in as root and run:

  • apt-get update
  • apt-get upgrade

If the system prompts you to reboot a process or the system, do as it says. Once you reboot all the core daemons and programs should be the latest (stable) versions.

3) Install the ssh server [apt-get install ssh] for remote command line access, so you don’t have to be hunched over a server rack.

4) If you wish to have email functionality follow the instructions in this article on howtoforge.org.

5) various dependencies and apps (php, mysql, pcre for nginx): apt-get install php5-cli php5-cgi build-essential mysql-server mysql-client openssl libssl-dev libpcre3 libpcre3-dev bzip2 gzip
better lock down the mysql root user: mysqladmin -u root password NEWPASSWORD

6) For individual virtual host files under nginx:
mkdir /etc/nginx
mkdir /etc/nginx/sites-enabled

[Sample Virtual Host File] • [More on Virtual Hosts]

7) if ($operating_system == “ubuntu*”) {
grab the nginx .deb archive (check the other releases out on technokracy.net):
[i386] wget http://vraidsys.com/article-includes/nginx_shiz/nginx_0613grrr-1_i386.deb
OR
[amd64] wget http://vraidsys.com/article-includes/nginx_shiz/nginx_0613grrr-1_amd64.deb
unpack and setup nginx: dpkg -i nginx_*
}else if($operating_system == “debian*”){
command to grab nginx: apt-get install nginx
}

8) Setup lighttpd for spwan-fcgi
grab the archive and make it. but DO NOT make install!
wget http://www.lighttpd.net/download/lighttpd-1.4.20.tar.bz2
tar -xvjf lighttpd-*
cd lighttpd*
./configure --without-bzip2
make

Now copy what we need for spawn-fcgi: cp src/spawn-fcgi /usr/bin/spawn-fcgi
Open the config file: vi /usr/bin/php-fastcgi
And add: /usr/bin/spawn-fcgi -a 127.0.0.1 -p 9000 -C 5 -u www-data -f /usr/bin/php5-cgi
-C controls how many fcgi instances of PHP5 are spawned, so you can put however many are appropriate for you in there. I only needed 5.

Open the startup file: vi /etc/init.d/init-fastcgi
Add the following:
#!/bin/bash
PHP_SCRIPT=/usr/bin/php-fastcgi
RETVAL=0
case "$1" in
start)
$PHP_SCRIPT
RETVAL=$?
;;
stop)
killall -9 php
RETVAL=$?
;;
restart)
killall -9 php
$PHP_SCRIPT
RETVAL=$?
;;
*)
echo "Usage: php-fastcgi {start|stop|restart}"
exit 1
;;
esac
exit $RETVAL

Now change some perms to make the files executable:
chmod 755 /etc/init.d/init-fastcgi
chmod 755 /usr/bin/php-fastcgi

Start your fcgi processes: /etc/init.d/init-fastcgi start
And add the script to startup: update-rc.d init-fastcgi defaults
Restart nginx and see if it works: /etc/init.d/nginx restart

#8 was based on: http://www.johnyerhot.com/2008/02/12/how-to-nginx-fcgi-php-mysql-ruby-on-rails-rewrite-vhosts/

[More on fcgi setups on the nginx wiki]

9) Install vsftpd
apt-get install vsftpd
Now open up the configuration file: vi /etc/vsftpd.conf
I am creating a single/few user system here, so whenever I add a new user, that user will have ftp permissions. Which would mean that I would edit the config file so that: local_enable=yes and chroot_local_user=YES.
Restart vsftpd: /etc/init.d/vsftpd restart

10) A great resource page on adding, editing, and deleting users can be found at http://www.ahinc.com/linux101/users.htm.

Return top