Symfony Headache pt.1

Ok since I had a very frustrating day with symfony, I have decided to make a Symfony Headache series. In these series, I’ll point some problems in Symfony and give my solution.

What made me do this? I have spent a WHOLE DAY trying to solve Forbidden problem accessing one of symfony applications. I can’t explain how furious I was, after I found the explanation to my problem.

I’m using /home/user/public_html folder for web sites, and then map them into virtual hosts. Somehow, I did not know that my flags for other users are unusual, or at least different from flags on my other computer, and did not check them. Apparently, my /home directory, didn’t have right permissions, so Apache could not ‘read’ my web sites.

So, if there is any possibility that you did not check /home permissions, check it! You need to have at least rx flags for other users, on your web directory, for Apache to read it.

😦 bye

Advertisements

Making a simple web service using axis2

Me again! 8)

In last article related to Axis, we talked about installing Axis2 on tomcat server. Today, I’m going to write about making a basic web service, using axis2. Now, I do not have the great knowledge on using web services, but I managed to make them work. For following this mini tutorial, you are going to need Linux, Tomcat6, Java, Axis2. If you do not have that, just follow this tutorial.

First, let us decide what will our service do! Since it is going to be simple tutorial and simple service too, let us make service that will calculate sum of 2 numbers.

Service name: SimpleService
Methods: Add; arguments: a(int),b(int); returns int;

Before we get into coding, lets see what makes web service.
When you hear web service, you have to think about it being on some server. To put it on server is called deployment. So, we are going to deploy our web service, when we make it. What are we deploying? When making java web service, we are making an archive. That archive has extension aar, which is a basic jar extension, but renamed. What it has to contain? Main thing is, of course, our class, with methods. Another very important part is particular file called services.xml. Now, we are not going to get into ways of writing it, but you need to check this tutorial about it. This file has to be placed into META-INF document, so axis can find it and read it.

Folder structure:

SimpleService.aar
+ SimpleService.class
+ META-INF
   + services.xml

I hope you’ll get the idea 8)
Let us see the services.xml file:

<service name="SimpleService"> <parameter name="ServiceClass" locked="false">SimpleService </parameter> <operation name="add"> <messageReceiver class="org.apache.axis2.rpc.receivers.RPCMessageReceiver" /> </operation> </service>

Now, service name has to be the same as the name of the aar archive. In parameter tags, you have to put the whole path to the service class. In more complex projects, you’ll have packages, and you have to put all those dots, something like: folder1.folder2.Classfile. For our concern, it is only one file, so its name fill be enough. For the operation tag, you have to put the name of the method we will make, and this massageReceiver is the basic and default one.
Now, it is time for java coding. Stay calm, it is not going to be hard, just a few rows. Here it is:

public class SimpleService {
	public int add(int a, int b){
		return a+b;
	}
}

It wasn’t hard, was it?

Now all you have to do is to deploy it.
You do not have to write client for it, because you can try it through browser. If you are working on localhosto server, then address should be something like this:

From here, you can see where is the name of method, and which are the arguments.

And at last, but not at least, accessing this link http://localhost:8080/axis2/services/SimpleService?wsdl, you’ll get the WSDL, which is the most important part of communication between client and web services on server, but since this tutorial is for beginners, we shall not talk about it. To be honest, I don’t know to write it, but luckily axis makes it from your arr automatically. YEY for Axis!!! 😉

I hope this will be useful for someone who is facing the web services for the first time, because I was the newb not so long ago, and I know how it is to have sooo many questions, and not adequate literature. Feel free to ask if you have some questions about whis topic, and I’ll try to answer if I can. 8) Bye

Installing axis2 on Ubuntu host

Hey ppl, it is time for one of my super helpful mini tutorials 🙂

Its been a while since last post. I had lot of work and things on my mind. Today I decided to write mini tutorial about installing axis2, as I setup it again on my virtual machine.

Before we start, I’d like to tell you why I’m installing everythin again! 😦 It is because my old virtual machine was broken few days ago.

I had WinXP on it, and I was doing some IDEF0 and DFD diagrams. I needed ERWIN for some ER diagrams and I tried to install it. It started and took some time, and then VBox started going crazy! It shutdown WinXP virtual machine and threw me an error about it. If I just had a clue not to edit Virtual Box.xml file, I’d be very happy man right now. Anyway, I had removed some lines, or something like that and all my virtual machines and their snapshots were inaccessible. I have lost few hours trying to make it work again, but with no success. So, I’m giving you advice, FIRST READ THEN EDIT CONFIG FILES 🙂

Ok, now we will start with installing axis2.

First, you have to install java6, tomcat6 packages with next command:

sudo apt-get install sun-java6-jdk tomcat6-admin tomcat6-docs tomcat6-examples

Now, you can try accessing localhost:8080/ in your browser. If you try to get on admin pages, to deploy some servlet, you’ll get prompt for username and password. Because tomcat6 default install hasn’t those parameters in config file, you’ll have to edit /var/lib/tomcat6/conf/tomcat-users.xml. In it you’ll have to add next lines:

<role rolename=”admin”/>
<role rolename=”manager”/>
<user username=”admin” password=”password” roles=”admin,manager”/>

between tomcat-users tags. Change “password” with your own.

After this, you’ll have to restart tomcat6 with:

sudo /etc/init.d/tomcat6 restart

Then, you have to access manage-webapp link on localhost:8080/ and enter your username and password from tomcat-users.xml file.

Inside, you can do lot of things, but we will do war deploy :D. Since we are installing axis2, you must download WAR archive from this link: http://ws.apache.org/axis2/download/1_5_1/download.cgi

Then you choose path to axis2.war file, and deploy it. To access it, visit localhost:8080/axis2/. I’m pretty sure you’ll get error. It took me som time to figure out what is blocking it. The problem is in tomcat6 script in /etc/init.d directory. You have to switch tomcat security flag from yes to no. Then restart tomcat6, and you’ll have axis2 working.

That is all. Feel free to comment and ask, and I’ll feel equally free to answer them 🙂 BYE!

Installing LAMP, SSH, Webmin, SVN repository on jeOS

Hey ppl, today I’m going to tell you how I did this particular job of setting up a Linux based server dedicated for my project.

I’m going to cut the intro and start with the real deal :).

First, I used VirtualBox for making virtual machine. I’m using VBox 3.1.4. I made a dynamic sized hard disk and set its max capacity for 6 GB, which is just enough for my needs.

Second, I downloaded jeOS from this link, http://cdimage.ubuntu.com/cdimage/jeos/releases/8.04.3/release/jeos-8.04.3-jeos-i386.iso. You can download it just clicking on this link, ooooor you can use wget tool in your command line(terminal), if you are linux geek, like me :D. After downloading it, make sure you add in the virtual media manager, in VirtualBox. Then, open the settings for your newly created hard disk and choose to mount jeOS’s .iso. In the Network part, choose NAT. I’ll explain that latter. Then ruuuun the coolest virtual machine ever :).

In the mean time, as you install jeOS, let me say that it is based on Ubuntu 8.04 LTS server, where LTS is for Long Time Support. I read somewhere that it is going to be supported until 2013!!! That means, you wont have to think of setting a new virtual machine for a looong time. Cool, isn’t it? 😉

Now that you have installed the jeOS, we are going to update and upgrade installation. First, you can use sudo vi for editing the /etc/apt/sources.list file, and if you know what you are doing, removing some pound symbols. After successfully editing it, run sudo apt-get update for updating the list of available packages. After that, run sudo apt-get upgrade for making sure that installed packages are going to be newest.

Until that happens, I’m going to tell you, that jeOS is Ubuntu based server edition made only for virtual machines, so it doesn’t have all the packages that real 8.04 LTS server edition has. That is going to make our job slightly harder, because there are going to be some dependencies that we are going to have to solve. No need for panic, I already did this, so you are getting this without sleepless nights and red eyes, as I did. Poor mee! 😦 😀

Anyway, thanks for ppl who helped us as much as they could and made us a package called lamp-server^. It basically installs Apache, PHP, MySQL in one, without making us install all these packages one by one, by apt or downloading and compiling them. Compiling is much better if you have to make some slightly changes and fine tune the server. That is not the subject of this post, so we are not going to do that.

So, we install lamp server with sudo apt-get install lamp-server^. Make sure that you put ^ at the end of package name. Next to do is installing the SSH support, so you do not have to do all this from virtual machine, but by accessing it through the terminal or putty. Of course, this is just installing it, for accessing it you will have to to some things that I’m going to explain latter. So, to install ssh server, run sudo apt-get install openssh-server.

After this, the best way to administrate your server machine is to install Webmin. You can get it by wget, that I suggest, because if you download it on host machine at this point, you wont be able to transfer it to virtual machine. So, use wget! How coooool, back to the command line! 😀 Whis is the site where you can get the latest version of webmin, http://www.webmin.com/download.html. After downloading it,if you try to install it, it will print some broken dependencies, about some perl libraries. So before installing webmin, type sudo apt-get install libnet-ssleay-perl openssl libauthen-pam-perl libio-pty-perl libmd5-perl. This is going to fix all dependencies and then run sudo dpkg -i <nameofdownloaded-file>, for installing it. Of course, you have to download the .deb package to install it with dpkg -i, oooor you can download and .rpm for example and use alien to conver it to .deb. This is just an info, we are not going to to that! 🙂 coz there is no need for it.

That is it, now you could access webmin by typing the ip of the machine and choosing the port 10000. Only problem is that virtual machine is accessing the internet over the NAT, so it has IP from 10.0.0.0 private domain, and you can’t see it. No big deal, we will fix that very soon.

Now, to install SVN. This is very useful tool for you if you are working on some project with your colleagues or buddies. It can make work on project a piece of cake. To install it type sudo apt-get install subversion libapache2-svn. The second package is module for Apache, so you can access your svn repository over http with Apache. Cool stuff, but if you are doing some classified project, better use it with https protocol, to make sure it is crypted over the internet. You are going to think that this is the end of setting up the SVN, and I’d like to tell you that! 🙂 Buuuut, it is not! You have to use adduser or useradd commands in command line and add the svn user. Make sure that when you add it, edit the /etc/passwd file with super user permissions and edit the default shell for svn to /bash/false. That way, no one will be able to log in on server as svn user. Next thing is to edit /etc/group file, agains as SU and add you as member of svn group. You can add all users that are going to be using svn repository. After finishing that, we are going to make repository directory. Now, I made it on /srv/svn/, but you can choose whatever you like. When you make a directory, run sudo svnadmin create /path/to/your/directory/repos. I did svnadmin create /srv/svn/repos. Now run sudo chown -R svn.svn /srv/svn for making the svn user a owner of that directory, and then sudo chmod -R g+w /srv/svn, for letting all members of svn group to access and write in your svn repository.

So, now you can access your svn repository ove svn+ssh://machineip/path/to/svn/repos oooor making it available over http or https with Apache. To do the Apache way, you have to turn off the machine. Now is the time for changing the Network settings. When virtual machine is turned of,  go to settings and change from NAT to Host only networking. This way, your host and your virtual machine are going to be able to see each other as if they were in local network. Bad thing is that virtual machine will only see host machine then. But, we installed all the packages we are going to need so that is not the problem. Just for info, internal network is for virtual machines to see each other, and bridged network is for making the virtual machine as real computer on your LAN. That way, it will get real 192.168.. adress and be more like a real server. But this part is more complicated, cuz you have to make some changes on host. Anyway, run the virtual machine, and when you log in run ifconfig and see that it is ip address of virutal machine. Type that address in web browser on host, and you should see the words “Ii works!”. If you use https protocol and name the port 10000, you will be able to access webmin. There you will be able to set a virtual host, or even change settings for svn repository. The way we are going to edit apache’s settings is over the command line! Yey! 😀

So then, edit the /etc/apache2/sites-enabled/000-default file, with SU permissions and add before closing the VirtualHost tag, this:

<Location /svn/repos>
DAV svn
SVNPath /srv/svn/repos
AuthType Basic
AuthName “Subversion Repository”
AuthUserFile /etc/apache2/passwords
Require valid-user
</Location>

Dav svn – Instructs Apache to pass the request onto the DAV layer for processing as a subversion (svn) request. SVNPath is saying where is the repository. AuthType is for authentication, AuthUserFile is file where you specify  the users that are permitted to access repository. There are crypted passwords. Since you create it and it is empty, you can add user and password with this command, sudo htpasswd -cb /etc/apache2/passwords username password. Of course, it is not suggested to type password, coz it is going to be seen in command line history. To make htpasswd propmt for password, exclude the b flag.

Now, you have to reload apache daemon, with sudo /etc/init.d/apache2 force-reload. This way, when you type in hosts browser http://ipofthevirtualmachine/svn/repos login window should appear and when you enter password, it should show you the repository.

I had in mind showing you the basic commands for managing the virtual machines from command line, but since this post took so much time, I’ll leave vbox managing for another time.

I hope my english was good enough, and be free to comment this post, if it is good or bad, or if you have some problems about setting up the LAMP on jeOS. I’d be glad to help.

Bye!!! 🙂