11 min read

In this article by Mukund Chaudhary and Ankur Kumar, authors of the book PhpStorm Cookbook, we will cover the following recipes:

  • Getting a VCS server
  • Creating a VCS repository
  • Connecting PhpStorm to a VCS repository
  • Storing a PhpStorm project in a VCS repository

(For more resources related to this topic, see here.)

Getting a VCS server

The first action that you have to undertake is to decide which version of VCS you are going to use. There are a number of systems available, such as Git and Subversion (commonly known as SVN). It is free and open source software that you can download and install on your development server. There is another system named concurrent versions system (CVS). Both are meant to provide a code versioning service to you. SVN is newer and supposedly faster than CVS. Since SVN is the newer system and in order to provide information to you on the latest matters, this text will concentrate on the features of Subversion only.

Getting ready

So, finally that moment has arrived when you will start off working in a team by getting a VCS system for you and your team. The installation of SVN on the development system can be done in two ways: easy and difficult. The difficult step can be skipped without consideration because that is for the developers who want to contribute to the Subversion system. Since you are dealing with PhpStorm, you need to remember the easier way because you have a lot more to do.

How to do it…

The installation step is very easy. There is this aptitude utility available with Debian-based systems, and there is the Yum utility available with Red Hat-based systems. Perform the following steps:

  1. You just need to issue the command apt-get install subversion. The operating system’s package manager will do the remaining work for you. In a very short time, after flooding the command-line console with messages, you will have the Subversion system installed.
  2. To check whether the installation was successful, you need to issue the command whereis svn. If there is a message, it means that you installed Subversion successfully.

If you do not want to bear the load of installing Subversion on your development system, you can use commercial third-party servers. But that is more of a layman’s approach to solving problems, and no PhpStorm cookbook author will recommend that you do that. You are a software engineer; you should not let go easily.

How it works…

When you install the version control system, you actually install a server that provides the version control service to a version control client. The subversion control service listens for incoming connections from remote clients on port number 3690 by default.

There’s more…

If you want to install the older companion, CVS, you can do that in a similar way, as shown in the following steps:

  1. You need to download the archive for the CVS server software.
  2. You need to unpack it from the archive using your favorite unpacking software.
  3. You can move it to another convenient location since you will not need to disturb this folder in the future.
  4. You then need to move into the directory, and there will start your compilation process. You need to do #. /configure to create the make targets. Having made the target, you need to enter #make install to complete the installation procedure.

Due to it being older software, you might have to compile from the source code as the only alternative.

Creating a VCS repository

More often than not, a PHP programmer is expected to know some system concepts because it is often required to change settings for the PHP interpreter. The changes could be in the form of, say, changing the execution time or adding/removing modules, and so on. In order to start working in a team, you are going to get your hands dirty with system actions.

Getting ready

You will have to create a new repository on the development server so that PhpStorm can act as a client and get connected. Here, it is important to note the difference between an SVN client and an SVN server—an SVN client can be any of these: a standalone client or an embedded client such as an IDE. The SVN server, on the other hand, is a single item. It is a continuously running process on a server of your choice.

How to do it…

You need to be careful while performing this activity as a single mistake can ruin your efforts. Perform the following steps:

  1. There is a command svnadmin that you need to know. Using this command, you can create a new directory on the server that will contain the code base in it. Again, you should be careful when selecting a directory on the server as it will appear in your SVN URL for the rest part of your life. The command should be executed as:

    svnadmin create /path/to/your/repo/

  2. Having created a new repository on the server, you need to make certain settings for the server. This is just a normal phenomenon because every server requires a configuration.
  3. The SVN server configuration is located under /path/to/your/repo/conf/ with the name svnserve.conf. Inside the file, you need to make three changes. You need to add these lines at the bottom of the file:
    anon-access = none
    auth-access = write
    password-db = passwd

There has to be a password file to authorize a list of users who will be allowed to use the repository. The password file in this case will be named passwd (the default filename). The contents in the file will be a number of lines, each containing a username and the corresponding password in the form of username = password.

Since these files are scanned by the server according to a particular algorithm, you don’t have the freedom to leave deliberate spaces in the file—there will be error messages displayed in those cases.

Having made the appropriate settings, you can now make the SVN service run so that an SVN client can access it.

You need to issue the command svnserve -d to do that.

It is always good practice to keep checking whether what you do is correct. To validate proper installation, you need to issue the command svn ls svn://user@host/path/to/subversion/repo/.

The output will be as shown in the following screenshot:

 

How it works…

The svnadmin command is used to perform admin tasks on the Subversion server. The create option creates a new folder on the server that acts as the repository for access from Subversion clients.

The configuration file is created by default at the time of server installation. The contents that are added to the file are actually the configuration directives that control the behavior of the Subversion server. Thus, the settings mentioned prevent anonymous access and restrict the write operations to certain users whose access details are mentioned in a file.

The command svnserve is again a command that needs to be run on the server side and which starts the instance of the server. The -d switch mentions that the server should be run as a daemon (system process). This also means that your server will continue running until you manually stop it or the entire system goes down.

Again, you can skip this section if you have opted for a third-party version control service provider.

Connecting PhpStorm to a VCS repository

The real utility of software is when you use it. So, having installed the version control system, you need to be prepared to use it.

Getting ready

With SVN being client-server software, having installed the server, you now need a client. Again, you will have difficulty searching for a good SVN client. Don’t worry; the client has been factory-provided to you inside PhpStorm. The PhpStorm SVN client provides you with features that accelerate your development task by providing you detailed information about the changes made to the code. So, go ahead and connect PhpStorm to the Subversion repository you created.

How to do it…

In order to connect PhpStorm to the Subversion repository, you need to activate the Subversion view.

It is available at View | Tool Windows | Svn Repositories. Perform the following steps to activate the Subversion view:

  1. 1. Having activated the Subversion view, you now need to add the repository location to PhpStorm.
  2. To do that, you need to use the + symbol in the top-left corner in the view you have opened, as shown in the following screenshot:

Upon selecting the Add option, there is a question asked by PhpStorm about the location of the repository. You need to provide the full location of the repository. Once you provide the location, you will be able to see the repository in the same Subversion view in which you have pressed the Add button.

Here, you should always keep in mind the correct protocol to use. This depends on the way you installed the Subversion system on the development machine.

If you used the default installation by installing from the installer utility (apt-get or aptitude), you need to specify svn://. If you have configured SVN to be accessible via SSH, you need to specify svn+ssh://. If you have explicitly configured SVN to be used with the Apache web server, you need to specify http://. If you configured SVN with Apache over the secure protocol, you need to specify https://.

Storing a PhpStorm project in a VCS repository

Here comes the actual start of the teamwork. Even if you and your other team members have connected to the repository, what advantage does it serve? What is the purpose solved by merely connecting to the version control repository? Correct. The actual thing is the code that you work on. It is the code that earns you your bread.

Getting ready

You should now store a project in the Subversion repository so that the other team members can work and add more features to your code. It is time to add a project to version control. It is not that you need to start a new project from scratch to add to the repository. Any project, any work that you have done and you wish to have the team work on now can be added to the repository. Since the most relevant project in the current context is the cooking project, you can try adding that.

There you go.

How to do it…

In order to add a project to the repository, perform the following steps:

  1. You need to use the menu item provided at VCS | Import into version control | Share project (subversion). PhpStorm will ask you a question, as shown in the following screenshot:
  2. Select the correct hierarchy to define the share target—the correct location where your project will be saved.
  3. If you wish to create the tags and branches in the code base, you need to select the checkbox for the same. It is good practice to provide comments to the commits that you make.

The reason behind this is apparent when you sit down to create a release document. It also makes the change more understandable for the other team members. PhpStorm then asks you the format you want the working copy to be in. This is related to the version of the version control software. You just need to smile and select the latest version number and proceed, as shown in the following screenshot:

 

Having done that, PhpStorm will now ask you to enter your credentials.

You need to enter the same credentials that you saved in the configuration file (see the Creating a VCS repository recipe) or the credentials that your service provider gave you. You can ask PhpStorm to save the credentials for you, as shown in the following screenshot:

 

How it works…

Here it is worth understanding what is going on behind the curtains. When you do any Subversion related task in PhpStorm, there is an inbuilt SVN client that executes the commands for you. Thus, when you add a project to version control, the code is given a version number. This makes the version system remember the state of the code base. In other words, when you add the code base to version control, you add a checkpoint that you can revisit at any point in future for the time the code base is under the same version control system.

Interesting phenomenon, isn’t it?

There’s more…

If you have installed the version control software yourself and if you did not make the setting to store the password in encrypted text, PhpStorm will provide you a warning about it, as shown in the following screenshot:

Summary

We got to know about version control systems, step-by-step process to create a VCS repository, and connecting PhpStorm to a VCS repository.

Resources for Article:

 Further resources on this subject:


LEAVE A REPLY

Please enter your comment!
Please enter your name here