RSS

php file downloading instead of executing on Ubuntu ( linux )

Few days ago i faced a weird issue while installing lamp stack. After installation i made a symlink (shortcut) of www to public_html folder in the home directory but whenever i tried to run a php file, the browser used to download it rather than running it. I searched for the issue and come up with different but complex solutions. Though i didn’t follow the solutions but they reached me to the solution and a very simple one. All you need to do is to go to the file mentioned below.

sudo gedit /etc/apache2/mods-enabled/php5.conf

Most probably you will find the text written below. Concentrate on the text written in bold. You will find the solution for yourself.

<IfModule mod_php5.c>
 <FilesMatch "\.ph(p3?|tml)$">
 SetHandler application/x-httpd-php
 </FilesMatch>
 <FilesMatch "\.phps$">
 SetHandler application/x-httpd-php-source
 </FilesMatch>
  # To re-enable php in user directories comment the following lines
  # (from <IfModule ...> to </IfModule>.) Do NOT set it to On as it
  # prevents .htaccess files from disabling it.
 <IfModule mod_userdir.c>
 <Directory /home/*/public_html>
 php_admin_value engine Off
 </Directory>
</IfModule>
 </IfModule>

So it should be like

<IfModule mod_php5.c>
<FilesMatch "\.ph(p3?|tml)$">
SetHandler application/x-httpd-php
</FilesMatch>
<FilesMatch "\.phps$">
SetHandler application/x-httpd-php-source
</FilesMatch>
# To re-enable php in user directories comment the following lines
# (from <IfModule ...> to </IfModule>.) Do NOT set it to On as it
# prevents .htaccess files from disabling it.
# <IfModule mod_userdir.c>
# <Directory /home/*/public_html>
# php_admin_value engine Off
# </Directory>
#</IfModule>
</IfModule>

Restart the computer by the following command and Voila!

sudo /etc/init.d/apache2 restart
 
2 Comments

Posted by on November 1, 2011 in Apache, PHP, Ubuntu, Web

 

Tags: , , , , , , , , , ,

Web pages with no extension

If you want that your pages dont have any extension, for example http://yoursite.com/home.html shows up as http://yoursite.com/home.html, you need to do the following steps.

  • Check if there is any “.htaccess” file on your website home folder. In some cases the website home folder might be public_html. Remember dot (.) before htaccess.
  • This is a hidden file and for this file to be visible you need to configure the folder to show hidden files.
  • If not present, create a “.htaccess” file in your website home folder.
  • Add the following lines in the file. Remember this is for rewriting php files only. You need to change the extension according to your requirements.
RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ $1.php [L,QSA]
 
Leave a comment

Posted by on October 13, 2011 in Apache, PHP, Web

 

Tags: , , , , , , ,

How to SEO – Top 10 Search Engine Optimization Tips of 2011

Here is the top ten points around which my seo strategy revolves.

  1. Content
    As cliché as it sounds this is the number one for any search marketing strategy, it is impossibly important to ensure that you have content worth viewing. Without this one simply step to ensure that there is a reason for someone to be on your site, everything else is useless. There are a lot of great sites to find inspiration for writing great content that works.
  1. Incoming Links
    A link is a link is a link, but without the simplest form you aren’t going to do well in search engines. The more links you have the more often you are going to be crawled. It is also important to make sure that you have the proper anchor text for your incoming links. The easiest way to gain quality links from other sites is to link to sites to let them know your site is there and hope for a reciprocal link. It is also important to make sure that you have content that is worth linking to on your site.
  1. Web site title
    Making sure that you have the right web site titles for your pages is extremely important. The keywords you place in your title are important in order to ensure that your topic is understood by Google. One of the primary factors for ranking is if the title is on-topic with the search results. Not only is it important for robots to index and understand the topic of the page either. It is important for click-through rates in the search results. Pay attention to what you click on when you are searching in Google, I know that I don’t always click the first results. Using great titles and topics on your site will bring you more traffic than a number one listing. Most of the time it is within the first page, but I skim through the titles to see which looks to be more on-topic for my search query.
  1. Heading tags
    When you are laying out your site’s content you have to be sure that you are creating the content flow in such a way that the heading tags are based on prominence. The most prominent of course being the h1 tag, which says “this is what this block of copy is about.” Making sure you understand heading tag structure is very important. You only want to have one (or two) h1 tags per a page. It is important to not just throw anything into an h1 tag and hope you rank for it.
  1. Internal Linking
    Making sure that your internal linking helps robots (and visitors!) to find the content on your site is huge. Using relevant copy throughout your site will tell the robots (and visitors!) more effectively what to expect on the corresponding page. You do want to make sure that on pages you don’t want to rank in Google that you add a nofollow tag to ensure that the ranking flow of your site corresponds with your site’s topic and interests. No one is going to be searching Google to find out what your terms of service or privacy policy are.
  1. Keyword Density
    Ensuring that you have the right keyword density for your page and sites topic is paramount. You don’t want to go overboard and use the keyword every 5th word but making sure it “comes up” often is going to help you rank better in search engines. The unspoken rule is no more then 5% of the total copy per a page. Anymore then this and it can start to look a little spammy. Granted, you aren’t shooting for 5% every time. It is really all about context and relevance— just make sure it is good, quality copy.
  1. Sitemaps
    It is always a good idea to give search engines a helping hand to find the content that is on your site. Making sure that you create and maintain a sitemap for all of the pages on your site will help the search robots to find all of the pages in your site and index them. Google, Yahoo, MSN and Ask all support sitemaps and most of them offer a great way to ensure that it is finding your sitemap. Most of the time you can simply name it sitemap.xml and the search robot will find the file effectively.
  1. Meta Tags
    Everyone will tell you that meta tags don’t matter, they do. The biggest thing they matter for is click-through though. There will be a lot of times when Google will use your meta description as the copy that gets pulled with your search listing. This can help to attract the visitor to visit your web site if it is related to their search query. Definitely a much overlooked (as of late) ranking factor. Getting indexed by search engines and ranking well is just the first step. The next, and biggest, step is getting that visitor that searched for your keywords to want to click on your search listing.
  1. URL Structure
    Ensuring that your URL structure compliments the content that is on the corresponding page is pretty important. There are various methods to make this work, such as modrewrite on apache.
  1. Domain
    It can help to have keywords you are interested in ranking for within your domain, but only as much as the title, heading and content matters. One very important factor that is coming to light is that domain age is important. The older the site or domain, the better it is not spam and can do well in search results. The domain age definitely isn’t a make or break factor but it does help quite a bit.
 
Leave a comment

Posted by on October 8, 2011 in SEO

 

Tags: , , , , , , ,

How to Install OpenERP v6 on Ubuntu server 10.10

Manual installation of the openerp-server and the openerp-web server (OpenERP v6.x.x) on the same
server machine, with a fresh installed Ubuntu 10.10 LTS server (64 bit).

The result of this installation is an automatic boot-up of the OpenERP servers (application and web-server).

1:The Ubuntu user must have root rights.

Installation of dependencies and postgresql .

# sudo addgroup openerp
 # sudo adduser --ingroup openerp openerp
 # password = test1234
# sudo apt-get install postgresql (installs postgresql 8.4)
 # sudo su – postgres
 # createuser --createdb --no-createrole --pwprompt openerp
 # password test1234
Shall the new role be a superuser? (y/n) n
 exit

Now install the python and different essential for python

#sudo apt-get install python-psycopg2 python-reportlab python-imaging python-egenix-mxdatetime python-tz python-pychart python-pydot python-lxml python-vobject python-yaml python-profiler python-setuptools python-mako graphviz python-dev build-essential
#sudo easy_install PyYaml

Installation of Openerp-server
create a directory with the name of openerp in /home/

1: # cd /home/openerp
 # sudo wget http://www.openerp.com/download/stable/source/openerp-server-6.0.1.tar.gz
 # sudo tar zxvf openerp-server-6.0.1.tar.gz
 # cd /home/openerp/openerp-server-6.0.1
# sudo python setup.py install
# su openerp
cd /home/openerp/openerp-server-6.0.1
openerp-server -s (This starts up the server and also creates a configuration file ".openerp_serverrc" in the  directory /home/openerp)
Control C (to shut down the openerp-server)
exit

2:Installation of the Openerp-server daemon
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

sudo vim /etc/init.d/openerp-server (create a new file)

paste all this lines below there in  the file,

#! /bin/sh
### BEGIN INIT INFO
# Provides: openerp-server
# Required-Start: $syslog
# Required-Stop: $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: OpenERP Server - the server
# Description: OpenERP is a complete ERP and CRM software
### END INIT INFO
PATH=/sbin:/usr/sbin:/bin:/usr/bin:/usr/local/bin
DESC=openerp-server
NAME=openerp-server
DAEMON=/usr/local/bin/openerp-server
# Specify the user name (Default: openerp).
USER="openerp"
# Specifty an alternate config file (Default: ~/.openerp_serverrc)
CONFIGFILE="/home/openerp/.openerp_serverrc"
# pidfile
PIDFILE=/var/run/$NAME.pid
# Additional options that are passed to the Daemon
DAEMON_OPTS="-c $CONFIGFILE"
# Exit if the package is not installed
[ -x "$DAEMON" ] || exit 0
[ -f $CONFIGFILE ] || exit 0
checkpid() {
[ -f $PIDFILE ] || return 1
pid=`cat $PIDFILE`
[ -d /proc/$pid ] && return 0
return 1
}
# function that starts the daemon/service
#
if [ -f /lib/lsb/init-functions ] || [ -f /etc/gentoo-release ] ; then
do_start() {
start-stop-daemon --start --quiet --pidfile $PIDFILE \
--chuid $USER --background --make-pidfile \
--exec $DAEMON -- $DAEMON_OPTS
RETVAL=$?
sleep 5 # wait for few seconds
return $RETVAL
}
#
# Function that stops the daemon/service
do_stop() {
start-stop-daemon --stop --quiet --pidfile $PIDFILE --oknodo
RETVAL=$?
sleep 2 # wait for few seconds
rm -f $PIDFILE # remove pidfile
return $RETVAL
}
do_restart() {
start-stop-daemon --stop --quiet --pidfile $PIDFILE --oknodo
sleep 2 # wait for few seconds
rm -f $PIDFILE # remove pidfile
start-stop-daemon --start --quiet --pidfile $PIDFILE \
--chuid $USER --background --make-pidfile \
--exec $DAEMON -- $DAEMON_OPTS
RETVAL=$?
sleep 5 # wait for few seconds
return $RETVAL
}
else
do_start() {
$DAEMON $DAEMON_OPTS > /dev/null 2>&1 &
22/33
RETVAL=$?
sleep 5 # wait for few seconds
echo $! > $PIDFILE # create pidfile
return $RETVAL
}
do_stop() {
pid=`cat $PIDFILE`
kill -15 $pid
RETVAL=$?
sleep 2 # wait for few seconds
rm -f $PIDFILE # remove pidfile
return $RETVAL
}
do_restart() {
if [ -f $PIDFILE ]; then
do_stop
fi
do_start
return $?
}
fi
start_daemon() {
if [ -f $PIDFILE ]; then
echo "pidfile already exists: $PIDFILE"
exit 1
fi
echo -n "Starting $DESC: "
do_start
checkpid
if [ $? -eq 1 ]; then
rm -f $PIDFILE
echo "failed."
exit 1
fi
echo "done."
}
stop_daemon() {
checkpid
if [ $? -eq 1 ]; then
exit 0
fi
echo -n "Stopping $DESC: "
do_stop
if [ $? -eq 1 ]; then
echo "failed."
exit 1
fi
echo "done."
}
restart_daemon() {
echo -n "Reloading $DESC: "
do_restart
checkpid
if [ $? -eq 1 ]; then
rm -f $PIDFILE
echo "failed."
exit 1
fi
echo "done."
}
status_daemon() {
23/33
echo -n "Checking $DESC: "
checkpid
if [ $? -eq 1 ]; then
echo "stopped."
else
echo "running."
fi
}
case "$1" in
start) start_daemon ;;
stop) stop_daemon ;;
restart|force-reload) restart_daemon ;;
status) status_daemon ;;
*)
N=/etc/init.d/$NAME
echo "Usage: $N {start|stop|restart|force-reload|status}" >&2
exit 1
;;
esac
exit 0
# vim: sts=4 st=4 et

now do the following steps one by one

1: #sudo chmod +x /etc/init.d/openerp-server
2: #sudo mkdir /var/log/openerp
3: #sudo touch /var/log/openerp/openerp-server.log
4: #sudo chown -R openerp:openerp /var/log/openerp/
5: #sudo update-rc.d openerp-server defaults
6: #su openerp
7: $ cd /home/openerp
8: $vim .openerp_serverrc

do the following changes in the file .openerp_serverrc

Change:
[options]
without_demo = False
smtp_port = 25
db_password = False
xmlrpcs_interface =
syslog = False
logrotate = True
xmlrpcs_port = 8071
test_report_directory = False
list_db = True
xmlrpc_interface =
timezone = False
cache_timeout = 100000
smtp_password = False
secure_pkey_file = server.pkey
xmlrpc_port = 8069
log_level = info
test_disable = False
admin_passwd = admin
assert_exit_level = error
smtp_server = localhost
static_http_url_prefix = None
test_commit = False
xmlrpcs = True
demo = {}
login_message = False
import_partial =
pidfile = None
db_maxconn = 64 #test1234
stop_after_init = False
test_file = False
reportgz = False
xmlrpc = True
netrpc_port = 8070
db_port = False # add port 5432
db_name = False
debug_mode = False
netrpc = True
secure_cert_file = server.cert
logfile = none
#/var/log/openerp/openerp-server.log
csv_internal_sep = ,
pg_path = None
static_http_enable = False
translate_modules = ['all']
smtp_ssl = False
root_path = /usr/local/lib/python2.6/dist-packages/openerp-server
netrpc_interface =
smtp_user = False
db_user = "openerp"
db_host = False #add localhost
email_from = False
addons_path = /usr/local/lib/python2.6/dist-packages/openerp-server/addons
static_http_document_root = None

save and exit
now do the following steps

1: #sudo chmod 777 /usr/local/lib/python2.6/dist-packages/openerp-server/addons
2: #sudo /etc/init.d/openerp-server start
3: #sudo /etc/init.d/openerp-server status (it must say: running)

now install the openerp-web to access the openerpserver through web.
Installing Openerp-web

1: # cd /home/openerp
2: # sudo wget http://www.openerp.com/download/stable/source/openerp-web-6.0.1.tar.gz
sudo tar zxvf openerp-web-6.0.1.tar.gz
3: # cd /home/openerp/openerp-web-6.0.1
4: # sudo vim setup.py and change the value of line 9 from >= to == and exit from there.
5: # sudo python setup.py install (this installation takes a while)
./openerp-web.py (start server for testing)

You must see something like this:

[29/Jan/2011:19:37:37] ENGINE Bus STARTING
[29/Jan/2011:19:37:37] ENGINE Started monitor thread '_TimeoutMonitor'.
[29/Jan/2011:19:37:37] ENGINE Started monitor thread 'Autoreloader'.
[29/Jan/2011:19:37:37] ENGINE Serving on 0.0.0.0:8080
[29/Jan/2011:19:37:37] ENGINE Bus STARTED

Control C (to shut down the openerp-web server).

Installation of the Openerp-web daemon

6: # sudo mkdir /usr/local/bin/openerp
sudo vim /usr/local/bin/openerp/openerp-web
paste:
 #!/bin/sh exit 
7: cd /home/openerp/openerp-web-6.0.1
8: exec /usr/bin/python ./openerp-web.py $@
9: sudo chmod +x /usr/local/bin/openerp/openerp-web
10: sudo vim /etc/init.d/openerp-web (create a new file)Paste:
 #!/bin/sh ### BEGIN INIT INFO # Provides: openerp-web # Required-Start: $syslog # Required-Stop: $syslog # Should-Start: $network # Should-Stop: $network # Default-Start: 2345 # Default-Stop: 016 # Short-Description: OpenERP Web - the Web Client of the OpenERP # Description: OpenERP is a complete ERP and CRM software. ### END INIT INFO PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/bin/openerp DAEMON=/usr/local/bin/openerp/openerp-web NAME=openerp-web DESC=openerp-web # Specify the user name (Default: openerp). USER="openerp" # Specify an alternate config file (Default: /etc/openerp-web.cfg). CONFIGFILE="/etc/openerp-web.cfg" # pidfile PIDFILE=/var/run/$NAME.pid # Additional options that are passed to the Daemon DAEMON_OPTS="-c $CONFIGFILE" # Exit if the package is not installed [ -x "$DAEMON" ] || exit 0 [ -f $CONFIGFILE ] || exit 0 checkpid() { [ -f $PIDFILE ] || return 1 pid=`cat $PIDFILE` [ -d /proc/$pid ] && return 0 return 1 } # function that starts the daemon/service # if [ -f /lib/lsb/init-functions ] || [ -f /etc/gentoo-release ] ; then do_start() { start-stop-daemon --start --quiet --pidfile $PIDFILE \ --chuid $USER --background --make-pidfile \ --exec $DAEMON -- $DAEMON_OPTS RETVAL=$? sleep 5 # wait for few seconds return $RETVAL } # # Function that stops the daemon/service do_stop() { start-stop-daemon --stop --quiet --pidfile $PIDFILE --oknodo RETVAL=$? sleep 2 # wait for few seconds rm -f $PIDFILE # remove pidfile return $RETVAL } do_restart() { start-stop-daemon --stop --quiet --pidfile $PIDFILE --oknodo sleep 2 # wait for few seconds rm -f $PIDFILE # remove pidfile start-stop-daemon --start --quiet --pidfile $PIDFILE \ --chuid $USER --background --make-pidfile \ --exec $DAEMON -- $DAEMON_OPTS RETVAL=$? sleep 5 # wait for few seconds return $RETVAL } else do_start() { $DAEMON $DAEMON_OPTS > /dev/null 2>&1 & RETVAL=$? sleep 5 # wait for few seconds echo $! > $PIDFILE # create pidfile return $RETVAL } do_stop() { pid=`cat $PIDFILE` kill -15 $pid RETVAL=$? sleep 2 # wait for few seconds rm -f $PIDFILE # remove pidfile return $RETVAL } do_restart() { if [ -f $PIDFILE ]; then do_stop fi do_start return $? } fi start_daemon() { if [ -f $PIDFILE ]; then echo "pidfile already exists: $PIDFILE" exit 1 fi echo -n "Starting $DESC: " do_start checkpid if [ $? -eq 1 ]; then rm -f $PIDFILE echo "failed." exit 1 fi echo "done." } stop_daemon() { checkpid if [ $? -eq 1 ]; then exit 0 fi echo -n "Stopping $DESC: " do_stop if [ $? -eq 1 ]; then echo "failed." exit 1 fi echo "done." } restart_daemon() { echo -n "Reloading $DESC: " do_restart checkpid if [ $? -eq 1 ]; then 27/33 rm -f $PIDFILE echo "failed." exit 1 fi echo "done." } status_daemon() { echo -n "Checking $DESC: " checkpid if [ $? -eq 1 ]; then echo "stopped." else echo "running." fi } case "$1" in start) start_daemon ;; stop) stop_daemon ;; restart|force-reload) restart_daemon ;; status) status_daemon ;; *) N=/etc/init.d/$NAME echo "Usage: $N {start|stop|restart|force-reload|status}" >&2 exit 1 ;; esac exit 0 # vim: sts=4 st=4 et 
***********************************************************************************
12: sudo chmod +x /etc/init.d/openerp-web
13: sudo chmod 777 /home/openerp/openerp-web-6.0.1/addons
14: sudo cp /usr/local/lib/python2.6/dist-packages/openerp_web-6.0.1-py2.6.egg/doc/openerp-web.cfg /etc/
15: sudo vim /etc/openerp-web.cfg
copy and past the lines below :
Change:
 log.access_file = "/var/log/openerp-web/access.log" log.error_file = "/var/log/openerp-web/error.log" 
16: sudo mkdir -p /var/log/openerp-web
17: sudo touch /var/log/openerp-web/access.log
18: sudo touch /var/log/openerp-web/error.log
19: sudo chown -R openerp:openerp /var/log/openerp-web/
20: sudo update-rc.d openerp-web defaults
21: sudo /etc/init.d/openerp-web start

Browser interface
Type in your browser:

http://ipaddressserver:8080

You must see a login screen; create a database first .

Post created By Imran Ullah (shahmeer_IT@yahoo.com)

 
10 Comments

Posted by on April 20, 2011 in OpenERP, Ubuntu

 

Tags: , , , , , , , , , ,

setting up free ssl certificate for apache on ubuntu server

In order to setup a free certificate on apache server using Ubuntu 10.04 you need to follow the following steps.

Step 1 : Install ‘apache’ if you dont have any by following the given command i.e.
sudo apt-get install apache2

Step 2 : install ‘ssl3’ by following the command
sudo apt-get install ssl3

Step 3 : install ‘libssl-dev’ by following the command
sudo apt-get install libssl-dev or sudo apt-get install openssl openssl-develu

Step 4 : Enable the SSL module by
sudo a2enmod ssl

Step 5 : Make a directory for ssl
mkdir /etc/apache2/ssl
cd /etc/apache2/ssl
mkdir private
mkdir certs Note:(if the ssl, certs, private folders already exist there no need to create extra)

Step 6 : Create your own privete key
sudo openssl genrsa -out ~/ssl foldername/key name size
e.g. sudo openssl genrsa -out ~/domain.com.ssl/domain.com.key 2048

Step 7 : Create csr
sudo openssl req -new -key ~/domain.com.ssl/domain.com.key - out  ~/domain.com.ssl/ domain.com.csr

Step 8 : Move the keys to /etc/ssl/certs
mv domain.com.crt /etc/ssl/certs/ mv domain.com.key /etc/ss/private/
Note:(if you have the bundle-file key from CA then mv sf_bundle.crt /etc/ssl/certs)

Step 9 : Configure your ssl
cd /etc/apache2/sites-available/
cp default default-ssl
vi default-ssl

do the following changes:

<IfModule>
<VirtualHost _default_:443>
ServerAdmin webmaster@localhost
DocumentRoot "/var/www/sitefolder"
ServerName xyz.com:443
<Directory />
.  . . . no change
</Directory>
#SSL Engine Switch: #Enable/Disable SSL for this virtual host.

SSLEngine on
#SSLCertificateFile directive is needed.

SSLCertificateFile /etc/ssl/certs/domain.com.crt SSLCertificateKeyFile /etc/ssl/private/domain.com.key

#Note:(if you have the CV bundle.cert then uncomment the line and correct the path to sf_bundle.crt)
#Server Certificate Chain:
#SSLCertificateFile
/etc/ssl/certs/sf_bundle.crt
</VirtualHost>
</IfModule>

Step 10 : Check for port 443 on server:
sudo vi /etc/apache2/port.conf
<IfModule mod_ssl.c>  Listen 443  </IfModule>
<IfModule mod_gnutls.c>    Listen 443  </IfModule>

Step 11 : Force fully Redirect the http traffic to https, in case you want the site be only accessible through https

vi /etc/apache2/sites-available/virtual-host-80(xyz.com)
<VirtualHost *:80>

# Admin email, Server Name (domain name) and any aliases
ServerAdmin webmaster@xyz.com
ServerName  xyz.com
Redirect / https://xyz.com  ServerAlias xyz.com
# Index file and Document Root (where the public files are located)
DirectoryIndex index.php
DocumentRoot /var/www/sitefolder
<Directory /var/www/sitefolder/>
Options Indexes FollowSymLinks MultiViews
AllowOverride all
Order allow,deny
allow from all
</Directory>

# Custom log file locations
LogLevel warn
ErrorLog  /var/log/apache2/xyz_error.log
CustomLog /var/log/apache2/xyz_access.log combined
</VirtualHost>

Step 12 : restart you apache2 server
/etc/init.d/apache2 reload

Step 13 : Voila ! you are done now check your site
https://sitename

 
4 Comments

Posted by on April 4, 2011 in Apache, SSL, Ubuntu

 

Tags: , , , , , , , , , , ,

Installing Solr using php on Ubuntu tutorial

Solr logo

Image via Wikipedia

Solr is an apache index base searching server or module which you can use for index base searching . It is mostly preferred due to its scalability and performance. In this tutorial we will cover integration of Solr with php using Ubuntu .

In order to install and configure Solr server on Ubuntu for use with PHP ,  we need to go through the following steps

install java

sudo apt-get install sun-java6-jdk

if multiple JVM installed then change your preffered by

sudo update-alternatives --config java

To install Solr

  • visit Apache.org
  • click Resources > Download
  • select a convenient project mirror
  • navigate within the folders shown to pick a tarball (a .tgz file) of Solr V1.2.
  • Unpack the tarball with the following code.

After extracting the files , using terminal go to the solr folder and then example folder . Something like this

cd /path//apache-solr-1.4.0/example (apache-solr-1.4.0 in my case )

and then run

java -jar start.jar

The application is now available on port 8983.

Start your browser and type http://localhost:8983/solr/admin/ in the address bar . This is the interface for administering Solr.

To stop the Solr server, use Ctrl+C at the command line.

References :
http://www.ibm.com/developerworks/opensource/library/os-php-apachesolr/

 
Leave a comment

Posted by on March 26, 2011 in PHP, Solr

 

Tags: , , , , , , , ,

Counting word occurrences in a table column using PHP script in MySQL

Few days ago we were working on a task where we have to count word occurrences in a skill column of database table and then retreive the top 30 occurring words. I thought it might be worth posting it .


<?php

$con = mysql_connect("hostname","database user", "password");
if (!$con)  {  die('Could not connect: ' .mysql_error());  }

mysql_select_db("test") or die(mysql_error());

$skill=array();

$query ="select column from table";

$result = mysql_select($query);

while($row = mysql_fetch_assoc($result))	 {

$tags=$row[tags];

$temp=explode(',',$tags);

foreach($temp as $tag)

{

if(trim($tag) == ' ')
continue;
$tag = trim(strtolower($tag));
if (array_key_exists($tag,$skills))
{
$skills[$tag]++;
}	 else	 {
$skills[$tag]=1;
}
}
}
arsort($skills);
$top_skills= array_slice($skills,0,30);
echo count($skills);
echo "<center><table border=1><tr>	<th>S.no</th>	<th>Skills</th>	<th>Counts</th></tr>";
$sno=0;
foreach($top_skills as $key=>$entry){
$sno=$sno+1;
echo"<tr>";
echo"<td>".$sno."</td>";
echo"<td>".$key."</td>";
echo"<td>".$entry."</td>";
echo "</tr>";
}

echo "</table>";

?>

 

 
1 Comment

Posted by on February 12, 2011 in Databases, MySQL, PHP

 

Tags: , , , ,