четверг, 18 июля 2013 г.

Install LifeRay 6.1 on Ubuntu and CentOS

Today i will install LifeRay 6.1 GA2 on Ubuntu 13.04 with 1Gb memory.

1. Installing.
At first create new user for Liferay:

sudo adduser --home /home/liferay liferay
Install Java:

sudo apt-get install default-jre
For me it was installed into /usr/lib/jvm/java-7-openjdk-amd64
On CentOS path was:/usr/lib/jvm/java-1.7.0-openjdk-1.7.0.25.x86_64
Get a LifeRay:

http://sourceforge.net/projects/lportal/files/Liferay%20Portal/6.1.1%20GA2/liferay-portal-tomcat-6.1.1-ce-ga2-20120731132656558.zip
unzip liferay-portal-tomcat-6.1.1-ce-ga2-20120731132656558.zip -d /home/liferay
Change user to liferay and go to Liferay folder. There i have a problem becouse when i try to start Tomcat it was not work. So all operations i do as administrator.

2. Tomcat configuration.
How we need to set JAVA_HOME variable. And we do it in bash. Go to file /etc/bash.bashrc and add:

JAVA_HOME=/usr/lib/jvm/java-7-openjdk-amd64
export JAVA_HOME
PATH=$PATH:$JAVA_HOME/bin
export PATH
For CentOS JAVA_HOME=/usr/lib/jvm/java-1.7.0-openjdk-1.7.0.25.x86_64/jre
Next you need give a permissions to Tomcat log file. Only heavy artillery helps me:

chmod 777 /home/liferay/liferay-portal-6.1.1-ce-ga2/tomcat-7.0.27/logs/catalina.out
Okey, now you can start LifeRay

sh /home/liferay/liferay-portal-6.1.1-ce-ga2/tomcat-7.0.27/bin/startup.sh
In console you'll get list of variables. And when in catalina.log appears line
INFO: Server startup in 24802 ms
server is start.

3. Add Liferay in autoload
At first create script /etc/init.d/liferay6

#!/bin/bash
# LifeRay Startup Service script v1.0 by Faraz Haider 6 May 2012
# acts as startup service script for LifeRay Portal.
# USAGE: start|stop|status|logs
#
case "$1" in
start)
echo "Starting LifeRay Web Portal."
export JAVA_HOME=/usr/lib/jvm/java-7-openjdk-amd64
export JRE_HOME=/usr/lib/jvm/java-7-openjdk-amd64/jre
/home/liferay/liferay-portal-6.1.1-ce-ga2/tomcat-7.0.27/bin/startup.sh
;;
stop)
echo "Stopping LifeRay Web Portal."
export JAVA_HOME=/usr/lib/jvm/java-7-openjdk-amd64
export JRE_HOME=/usr/lib/jvm/java-7-openjdk-amd64/jre
/home/liferay/liferay-portal-6.1.1-ce-ga2/tomcat-7.0.27/bin/shutdown.sh
;;
logs)
echo "See the logs of the LifeRay Web Portal."
tail -f /home/liferay/liferay-portal-6.1.1-ce-ga2/tomcat-7.0.27/logs/catalina.out
;;
status)
# Check to see if the process is running
ps aux|grep -i liferay
;;
 
*)
echo “LifeRay Web Portal Service”
echo $”Usage: $0 {start|stop|status|logs}”
exit 1
esac
exit 0
For CentOS:

#!/bin/bash
# chkconfig: 2345 90 10
# description: Liferay Service
# LifeRay Startup Service script v1.0 by Faraz Haider 6 May 2012
# acts as startup service script for LifeRay Portal.
# USAGE: start|stop|status|logs
#
case "$1" in
start)
echo "Starting LifeRay Web Portal."
export JAVA_HOME=/usr/lib/jvm/java-1.7.0-openjdk-1.7.0.25.x86_64/jre
#export JRE_HOME=/usr/lib/jvm/java-7-openjdk-amd64/jre
/home/liferay/liferay-portal-6.1.1-ce-ga2/tomcat-7.0.27/bin/startup.sh
;;
stop)
echo "Stopping LifeRay Web Portal."
export JAVA_HOME=/usr/lib/jvm/java-1.7.0-openjdk-1.7.0.25.x86_64/jre
#export JRE_HOME=/usr/lib/jvm/java-7-openjdk-amd64/jre
/home/liferay/liferay-portal-6.1.1-ce-ga2/tomcat-7.0.27/bin/shutdown.sh
;;
logs)
echo "See the logs of the LifeRay Web Portal."
tail -f /home/liferay/liferay-portal-6.1.1-ce-ga2/tomcat-7.0.27/logs/catalina.out
;;
status)
# Check to see if the process is running
ps aux|grep -i liferay
;;
 
*)
echo “LifeRay Web Portal Service”
echo $”Usage: $0 {start|stop|status|logs}”
exit 1
esac
exit 0
First two comments real important.
Make file executable:

chmod 755 /etc/init.d/liferay6
update-rc.d tomcat7 defaults
For CentOS:
chmod 755 /etc/init.d/liferay6
chkconfig liferay6 on

PS: only start,stop and status works
Reboot and be happy.

Change Tomcat port

Default port is 8080 but in not prety good becouse link www.example.com:8080 looks like a hell.
So go to home/liferay/liferay-portal-6.1.1-ce-ga2/tomcat-7.0.27/conf/server.xml. Find part:

 
And change port 8080 to what you want. I use 80 port for my site address www.example.com.

понедельник, 15 июля 2013 г.

Install php+FastCGI+nginx on Ubuntu.

Im continue create my super-amazing-web-GIS-application. I have a weak hardware so i have choice between 2 server side languages php and node.js. With php i can work now and there but for using node.js i have to read tons of books and miles of forums. So i have php i choose you!


1. Installing.

In previous part we already install nginx and fastCGI. So now we need only php. I will make php+fastCGI not php+php-rgm just becouse im already have fastcgi. If someone will write in comments why i have to use php-rgm i will glad.


Install php:


apt-get install php5 nginx php5-cgi

I was not install mySQL becouse i will use PostgreSQL+PostGIS for spatial data.


2. FastCGI configuration.

Create file /usr/bin/php-fastcgi and put into:


#! /bin/sh
PHP_FCGI_CHILDREN=3
PHP_FCGI_MAX_REQUESTS=1000
exec /usr/bin/php5-cgi

Create file /etc/init.d/init-fastcgi and put into:


#!/bin/bash
PHP_SCRIPT="/usr/bin/spawn-fcgi -a 127.0.0.1 -p 9000 -u www-data -g www-data -f /usr/bin/php-fastcgi"
RETVAL=0
case "$1" in
start)
$PHP_SCRIPT
RETVAL=$?
;;
stop)
killall -9 php5-cgi
RETVAL=$?
;;
restart)
killall -9 php5-cgi
$PHP_SCRIPT
RETVAL=$?
;;
*)
echo "Usage: sudo /etc/init.d/init-fastcgi {start|stop|restart}"
exit 1
;;
esac
exit $RETVAL

Make files executable:


chmod 755 /usr/bin/php-fastcgi
chmod 755 /etc/init.d/init-fastcgi 
3. nginx configuration.

You can create new file /etc/nginx/sites-enabled/your-file-name for server configuration:


server {
 listen 80;
 listen [::]:80 default_server ipv6only=on;

 root /srv/www/localhost/public_html;
 access_log /srv/www/localhost/logs/access.log;
 error_log /srv/www/localhost/logs/error.log;
 #index index.html index.htm;

 # Make site accessible from http://localhost/
 server_name localhost;

 location / {
  # First attempt to serve request as file, then
  # as directory, then fall back to displaying a 404.
  try_files $uri $uri/ /index.html;
  # Uncomment to enable naxsi on this location
  # include /etc/nginx/naxsi.rules
 }

 location /doc/ {
  alias /usr/share/doc/;
  autoindex on;
  allow 127.0.0.1;
  allow ::1;
  deny all;
 }
 location ~\.php$ {
  root /srv/www/localhost/public_html;
  include /etc/nginx/fastcgi_params;
  fastcgi_pass 127.0.0.1:9000;
  fastcgi_index index.php;
  fastcgi_param QUERY_STRING $query_string;
  fastcgi_param SCRIPT_FILENAME /srv/www/localhost/public_html$fastcgi_script_name;
 }

}

But i use default file so i just add:


 location ~\.php$ {
  root /srv/www/localhost/public_html;
  include /etc/nginx/fastcgi_params;
  fastcgi_pass 127.0.0.1:9000;
  fastcgi_index index.php;
  fastcgi_param QUERY_STRING $query_string;
  fastcgi_param SCRIPT_FILENAME /srv/www/localhost/public_html$fastcgi_script_name;
 }

into /etc/nginx/sites-enabled/default.


4. Site directory.

Its all with configurations. Now you can start FastCGI script:


Now we need to create directory for our site and log directory:


/srv/www/localhost/public_html
/srv/www/localhost/logs

In public_html keeped all site content.


5. Results.

Its all with configurations. Now you can start FastCGI script:


sudo /etc/init.d/init-fastcgi start

And start nginx:


/etc/init.d/nginx start

Create file test.php in our site directory with:



Go to the localhost/test.php and if you do all right you'll see standart phpinfo() output:


Its mean that php+nginx work fine.


In my case i get a 404 error becouse nginx tried to find test.php in standart nginx directory /var/www. Restart of nginx and fastcgi not help me, i was forced to reboot machine. But after all work fine.
Another problem was with permissions. So dont forget set to site directory:


 
sudo chmod -R 755 /srv/www/localhost/public_html
6. Enable PostgreSQL.

Its all nice but i will need PostgreSQL support in php. Now we need to install PostgreSQL module.


 
sudo apt-get install php5-pgsql

Restart fastCGI


 
sudo /etc/init.d/init-fastcgi restart

And go to localhost/test.php again to make sure that PostgreSQL enabled. You gonna see that part:


Its mean all works fine.