October 21, 2008
Second instance of apache on another port
These steps are done on Fedora 9. Other versions of Fedora (or other flavours of Linux) may still work but paths may be different.
On this example, we'll be running the new apache instance with user ian on port 8080.
First step is to duplicate the necessary files:
[root@linux ian]# cp -fR /etc/httpd /etc/httpd-ian
[root@linux ian]# cp /usr/sbin/httpd /usr/sbin/httpd-ian
[root@linux ian]# cp /usr/sbin/apachectl /usr/sbin/apachectl-ian
Create a new directory which the new instance of apache will be serving.
[root@linux ian]# mkdir /home/ian/www
Edit the files using any text editor. I'll be using vim in this example.
[root@linux ian]# vim /etc/httpd/conf/httpd.conf
Replace PidFile from run/httpd.pid to run.httpd-ian.pid
Replace Listen Port from 80 to 8080
Replace all occurences of /var/www/html to /home/ian/www
Replace User from apache to ian
Replace Group from apache to ian
[root@linux ian]# vim /usr/sbin/apachectl-ian
Replace HTTPD from '/usr/sbin/httpd' to '/usr/sbin/httpd-ian -f /etc/httpd-ian/conf/httpd.conf'
Replace STATUSURL from 'http://localhost:80/server-status' to ="http://localhost:8080/server-status"
We are now ready to start a new apache instance.
[root@linux ian]# /usr/sbin/apachectl-ian start
August 12, 2008
Shell script one-line find and replace
One line find and replace
find . -name '*.txt' -print0 |xargs -0 perl -pi -e 's/find/replace/g'
*.txt - files to find
find - pattern to find
replace - replace found pattern
July 21, 2008
Restoring large MySQL backup files
Have you ever tried importing large MySQL backup files via PHPMyAdmin? If yes, you would probably have experienced timeout errors, and PHPMyAdmin will tell you to reload the page... but the same thing happens again.
Solution is use the mysql command line to restore your backup files.
Here's the command:
mysql --user=myuser mydatabase < mybackupfile.sql
You would be surprised at how fast your backup file is restored!