Saturday, 26 November 2016

Install XDebug in Fedora25 and configure Netbeans

Installation

It is definitelly worth to read oficial installation docs before proceeding, it's quite short and it can help to avoid basic mistakes that are sometimes recomended elsewhere. You don't have to read it all - just pick the part which you need - pecl  - homebrew - from source.

Installation of XDebug in Fedora is really simple as there is the newest version in Fedora repositories. We can simply use the pecl installation.
> sudo dnf install php-pecl-xdebug


XDebug Configuration

This type of installation already enables xdebug extension. At least in my case the file /etc/php.d/15-xdebug.ini was already there after installation.

Wednesday, 23 November 2016

Cntlm proxy - my experience

When you work in a company where you have to use proxy, some things can get more complicated. In this article I'd like to summarize my settings and experience of using proxy on my linux Fedora27 laptop.

Linux - configuration of a proxy 

Settings of a proxy on linux machines differs per distribution. On some user friendly distributions you can use a Graphical interface and on others, you do it in a configuration file.

The easiest way to find it out for your distribution is to put a phrase like "Fedora 24 proxy configuration" into google, where you replace Fedora 24 with your distribution ;)

For example I use for my proxy configuration file /etc/profile.d/proxy.sh
And it looks almost like the first example file which you'll find via google.
MY_PROXY_URL="http://prox.srv.world:3128/"
HTTP_PROXY=$MY_PROXY_URL
HTTPS_PROXY=$MY_PROXY_URL
FTP_PROXY=$MY_PROXY_URL
http_proxy=$MY_PROXY_URL
https_proxy=$MY_PROXY_URL
ftp_proxy=$MY_PROXY_URL
export HTTP_PROXY HTTPS_PROXY FTP_PROXY http_proxy https_proxy ftp_proxy
export no_proxy="localhost,127.0.0.1,localaddress,.localdomain.com"
Additionaly (in Fedora) you have to specify proxy for dnf in a separate file - /etc/dnf/dnf.conf
For those who don't know dnf is a package manager - similar to apt-get in debian-like distributions.

Saturday, 19 November 2016

/etc/resolv.conf hostname domain name and search configuration option

Until recently I had no idea about search configuration option of /etc/resolv.conf and because I find it interesting, I decided to write about it on my blog.

I'm connected to a company network with domain exampldom.com. Our servers has cool host names like apolo01, apolo-p02 etc. Full domain names of those servers are apolo01.exampldom.com etc.

My colleagues with Windows OS were able to accces those servers just with their hostname, but I, from my Fedora24 laptop, I always had to specify a "long host name" to be able to access them for example via ssh.

I was wondering how this automatic adding of a domain to a hostname works and after a while I found it out.

At first I thought I will solve it via creating an aliases for those "short names". Because instead of using proper naming and realizing that I have host name and domain name in front of my eyes, I called it short name and long name with domain or mayble little bit differenty but still not correctly ;)  Therefore I was googling things like "linux alias for a domain" or similar. But with this I was only getting results about what can and can't be done via /etc/hosts file. After a while I asked a colleague who takes care of linux servers and he pointed me to the right direction.

The secret (it's not a secret ;) lies in configuraton of resolver - file /etc/resolv.conf.

When I opened that file on my PC I saw:
» cat /etc/resolv.conf 
# Generated by NetworkManager
search rz.exampldom.com
nameserver 100.100.128.12
nameserver 100.100.128.9
After reading man pages for "resolv.conf" it was quite clear.

Tuesday, 25 October 2016

Cntlm daemon restart is slow (Fedora23)

Everything started with 

$ sudo systemctl restart cntlm.service being very slow - it takes a minute or more.

So I started digging why.
I simply tried to stop it and then check how it looks during stopping.

Reproduced in Fedora23 and Fedora24

Running:

$ sudo systemctl start cntlm.service

$ sudo systemctl status cntlm.service -l
● cntlm.service - CNTLM HTTP Accelerator For NTLM Secured Proxies Authenticator
   Loaded: loaded (/usr/lib/systemd/system/cntlm.service; enabled; vendor preset: disabled)
   Active: active (running) since Tue 2016-10-25 12:34:33 CEST; 6min ago
  Process: 23537 ExecStart=/usr/sbin/cntlm -c /etc/cntlm.conf -U cntlm -P /run/cntlm/cntlmd.pid (code=exited, status=0/SUCCESS)
 Main PID: 23540 (cntlm)
   Memory: 2.5M
      CPU: 257ms
  CGroup: /system.slice/cntlm.service
           └─23540 /usr/sbin/cntlm -c /etc/cntlm.conf -U cntlm -P /run/cntlm/cntlmd.pid

Oct 25 12:39:23 mylaptop cntlm[23540]: 127.0.0.1 CONNECT ssl.gstatic.com:443
Oct 25 12:39:24 mylaptop cntlm[23540]: 127.0.0.1 CONNECT lh5.googleusercontent.com:443
Oct 25 12:39:24 mylaptop cntlm[23540]: 127.0.0.1 CONNECT csi.gstatic.com:443
Oct 25 12:39:24 mylaptop cntlm[23540]: 127.0.0.1 CONNECT plus.google.com:443
Oct 25 12:39:25 mylaptop cntlm[23540]: 127.0.0.1 CONNECT i18n-cloud.appspot.com:443
Oct 25 12:39:26 mylaptop cntlm[23540]: 127.0.0.1 CONNECT play.google.com:443
Oct 25 12:39:27 mylaptop cntlm[23540]: 127.0.0.1 CONNECT play.google.com:443
Oct 25 12:39:40 mylaptop cntlm[23540]: 127.0.0.1 CONNECT webpoolam30e10.infra.lync.com:443
Oct 25 12:40:35 mylaptop cntlm[23540]: 127.0.0.1 CONNECT accounts.google.com:443
Oct 25 12:40:36 mylaptop cntlm[23540]: 127.0.0.1 CONNECT beacons.gvt2.com:443

After recieving stop signal:

$ sudo systemctl stop cntlm.service

$ sudo systemctl status cntlm.service -l

● cntlm.service - CNTLM HTTP Accelerator For NTLM Secured Proxies Authenticator
   Loaded: loaded (/usr/lib/systemd/system/cntlm.service; enabled; vendor preset: disabled)
   Active: deactivating (stop-sigterm) since Tue 2016-10-25 12:41:10 CEST; 11s ago
  Process: 23537 ExecStart=/usr/sbin/cntlm -c /etc/cntlm.conf -U cntlm -P /run/cntlm/cntlmd.pid (code=exited, status=0/SUCCESS)
 Main PID: 23540 (cntlm)
   Memory: 2.5M
      CPU: 260ms
   CGroup: /system.slice/cntlm.service
           └─23540 /usr/sbin/cntlm -c /etc/cntlm.conf -U cntlm -P /run/cntlm/cntlmd.pid
Oct 25 12:39:24 mylaptop cntlm[23540]: 127.0.0.1 CONNECT csi.gstatic.com:443
Oct 25 12:39:24 mylaptop cntlm[23540]: 127.0.0.1 CONNECT plus.google.com:443
Oct 25 12:39:25 mylaptop cntlm[23540]: 127.0.0.1 CONNECT i18n-cloud.appspot.com:443
Oct 25 12:39:26 mylaptop cntlm[23540]: 127.0.0.1 CONNECT play.google.com:443
Oct 25 12:39:27 mylaptop cntlm[23540]: 127.0.0.1 CONNECT play.google.com:443
Oct 25 12:39:40 mylaptop cntlm[23540]: 127.0.0.1 CONNECT webpoolam30e10.infra.lync.com:443
Oct 25 12:40:35 mylaptop cntlm[23540]: 127.0.0.1 CONNECT accounts.google.com:443
Oct 25 12:40:36 mylaptop cntlm[23540]: 127.0.0.1 CONNECT beacons.gvt2.com:443
Oct 25 12:41:10 mylaptop systemd[1]: Stopping CNTLM HTTP Accelerator For NTLM Secured Proxies Authenticator...
Oct 25 12:41:10 mylaptop cntlm[23540]: Signal 15 received, issuing clean shutdown

After waiting a minute or more:

Thursday, 6 October 2016

PhpStorm XDebug configuration when using VM (Vagrant)

I would like to take notes how I did my set up of PhpStorm IDE for debugging with XDebug with the server running on VM (Vagrant). I assume that this configuration will work also for other type of environments where you need to use remote debugging.

Server configuration

At first you have to install XDebug (out of scope of this article).

On the vagrant machine we need kind of this configuration in /etc/php.ini
[xdebug]
zend_extension=/home/www/PHP/php-5.5.22/lib/php/extensions/xdebug.so
xdebug.max_nesting_level=9999
xdebug.profiler_output_dir=/tmp/
xdebug.profiler_output_name=xdebug-%p
xdebug.profiler_append=1
xdebug.profiler_enable_trigger=1
xdebug.remote_enable=1
xdebug.remote_handler=dbgp
xdebug.remote_mode=req
xdebug.remote_host=10.0.25.21
;xdebug.remote_connect_back=1
xdebug.remote_port=9000
xdebug.idekey="PHPSTORM"
xdebug.remote_autostart=1
xdebug.profiler_enable=0
xdebug.trace_options=1

Restart apache or php processes (depending on your server setup).

Important settings are: remote_host, idekey, remote_enable, remote_autostart

Sunday, 17 January 2016

Resize encrypted lvm partitions in Fedora23

In this article I will describe how to shrink one Logical Volume and extend another one in the same volume group.

My setup

During Fedora23 installation I let the installer to partition my disk automatically. I also checked that I want to encrypt my data.
The installer created Logical Volumes: 50GB root partition, 60GB home and 8GB swap.

After some time of using the system I found out that there is only 15GB left in /home and that there is 40GB of free space in / (root). I've decided that I will extend home and shrink root.

Preparation for the action

I spent some time reading about lvm and also LUKS disk encryption in fedora, and then I found this great page about resizing of lvm encrypted partitions - exactly what I needed, even little bit more.

I will try to describe exactly how it went in my case, so this article should be little bit shorter then the one I linked.

Initialization

When you want to shrink a partition you have to do it in unmounted state. For the root partition it means to boot from a live CD. I used Fedora23 CD for that.

Everybody warns you that you should backup your data before doing this, because you can easily loose them if something goes wrong. As I have all my important data in clouds (Dropbox, Google drive) I just restarted my laptop and booted Fedora live.

Thursday, 14 January 2016

MTP in Fedora23 for Android phone

I've recently installed fresh Fedora23 LXDE spin and when I connected my Android phone with 5.0.2 android version which supports MTP and PTP protocols for transferring files it appeared that it's not supported out of the box.

Luckily the solution is easy. You just need to install one utility.
sudo dnf install gvfs-mtp
After installation I had to restart my notebook (maybe starting some service would be enough, but I wanted to boot with new kernel anyway).

And when I connect the phone by USB cable now it automatically appears in the file manager as LGE Android Phone.

I want to add that at first I was afraid that it doesn't work properly, because when I clicked on the device in the file manager for the fist time, nothing appeared. But it just took some time till the device was scanned and its internal storage appeared.


Saturday, 9 January 2016

Symfony console no colors, symfony console progressbar on many lines

When you install symfony installer and after executing symfony command you don't see colorized help text, you might also experience problem with progress-bar on many lines. Progressbar is used when you're creating new symfony project by command symfony new myproject.

Symfony help text without colors Symfony installer progressbar on many lines, because of not installed php posix module


Both problems are probably caused by a lack of POSIX support in your php environment.

Solution

Just install php posix module.

The package named php-process in current Fedora distribution.

So you just need to do:
sudo dnf install php-process

See the result after the installation of the module:

Symfony help text with colors
Symfony progressbar after installation of php posix module


Wednesday, 6 January 2016

How to fix vagrant hanging when mounting folders on fedora (Fedora firewall configuration for Vagrant NFS synced folders)

Situation

If you use Fedora distribution on your host machine and you configure your vagrant box to use NFS type of synced folders, you might get into trouble with vagrant hanging during mounting of those NFS shared folders.
$ vagrant up
...
...
==> default: Mounting NFS shared folders...

Verify if the firewall configuration is the problem

If you haven't changed default firewall settings, the problem is probably there because Fedora has pretty securely configured firewall by default.

To quickly check if the problem is in the firewall settings you can try to disable it:
sudo systemctl stop firewalld
If you want to double check that firewall is really disabled, you can check iptables rules. Disabled firewall looks like this:
$ sudo iptables -L
Chain INPUT (policy ACCEPT)
target     prot opt source               destination         

Chain FORWARD (policy ACCEPT)
target     prot opt source               destination         

Chain OUTPUT (policy ACCEPT)
target     prot opt source               destination

But of course disabling the firewall permanently is not a good idea so let's configure it that it allows mounting of NFS folders for the vagrant box.

Don't forget to enable the firewall again:
sudo systemctl start firewalld

Virtualbox network interfaces and fedora firewall

By default Virtualbox uses network interface vboxnet0 but when you reload your vagrant box it might happen that new interface will be created and used by the box (vboxnet1, vboxnet2 etc). So if you see hanged mounting in the future, check if the box uses interface which is allowed in the firewall config.

As I described in my older article about fedora firewall, fedora uses zones into which you assign network interfaces and then you set specific configuration for each zone.

Therefore what we need to do is to assign vboxnet0 (vboxnet1,...) interface into zone "internal" and then allow apropriate ports (services). We can do it via GUI firewall-config or via terminal firewall-cmd.

As clicking into the gui is something what you can probably handle by yourself, I will use the terminal. Another advantage of firewall-cmd is that you can simply copy following commands and paste them intoto your terminal so it's much quicker.

Change the firewall settings to allow NFS mount

sudo su
firewall-cmd --zone internal --add-interface vboxnet0
firewall-cmd --permanent --zone internal --add-service nfs
firewall-cmd --permanent --zone internal --add-service rpc-bind
firewall-cmd --permanent --zone internal --add-service mountd
firewall-cmd --permanent --zone internal --add-port 2049/udp
firewall-cmd --reload

If you do this when nfs directory mounting is hanged you can see that mounting will continue just after you reload the firewall settings.
==> default: Mounting NFS shared folders...
==> default: Machine already provisioned. Run `vagrant provision` or use the `--provision`
==> default: flag to force provisioning. Provisioners marked to run always will still run.

If you got troubles to make it work, just leave a comment and I will try to help.

Monday, 4 January 2016

Ansible provisioning fails with fedora/23-cloud-base box

I have been playing with Vagrant and ansible recently and got into trouble to make it work.

At first I want to say that I'm not an experienced user of ansible, but I'm sure that there are many people like me therefore I will try to describe it in a way that even I would understand it ;)

Situation

I have Fedora 23  on the host machine with installed Vagrant, ansible, python3, python2 etc. I have Vagrantfile with fedora/23-cloud-base as config.vm.box and provision by ansible.

When I started vagrant provision comand I got this error:
$ vagrant provision
==> default: Running provisioner: ansible...     default: Running ansible-playbook... PLAY [vagrant] **************************************************************** GATHERING FACTS *************************************************************** failed: [192.168.25.25] => {"failed": true, "parsed": false} BECOME-SUCCESS-afwahqttsdeueajwfcuqsvaulkoxjixf /bin/sh: /usr/bin/python: No such file or directory OpenSSH_7.1p1, OpenSSL 1.0.2e-fips 3 Dec 2015 debug1: Reading configuration data /etc/ssh/ssh_config debug1: /etc/ssh/ssh_config line 56: Applying options for * debug1: auto-mux: Trying existing master debug1: mux_client_request_session: master session id: 2 Shared connection to 192.168.25.25 closed. TASK: [apache | Install Apache] *********************************************** FATAL: no hosts matched or all hosts have already failed -- aborting
PLAY RECAP ********************************************************************            to retry, use: --limit @/home/tomor/playbook.retry 192.168.25.25              : ok=0    changed=0    unreachable=0    failed=1
Ansible failed to complete successfully. Any error output should be visible above. Please fix these errors and try again.
When I enabled debugging by ansible.verbose="vvv" I saw more output but it didn't help me.

Reason of the fail

The problem is in the fact that 
  • ansible needs python 2.x on the remote system and Fedora23 has only python3 installed by default
  • python3 does not create /usr/bin/python - because it's not compatible with python2
and that's the reason why ansible provisioning fails - see the beginning of the fail:
failed: [192.168.25.25] => {"failed": true, "parsed": false}
BECOME-SUCCESS-afwahqttsdeueajwfcuqsvaulkoxjixf
/bin/sh: /usr/bin/python: No such file or directory
Python is needed for gathering of the facts (setup module).

Solution

To solve this situation you just have to install python 2 on the remote machine.

As I wanted to do the whole installation of the Vagrant box by ansible I solved it by:
  1. disable Gathering Facts
  2. add installation of python2
  3. start gathering facts manually (by setup module)
It means adapting basic playbook like this:
---
- hosts: vagrant
  sudo: true
  gather_facts: false # Fedora23 doesn't have python2 installed by default
  roles:
    - ansible_prepare # install python2, gather facts manually after python is prepared
    - my_another_role
And creation of ansible_prepare role task:
- name: Install python2 on the remote machine
  raw: dnf install -y python2 python2-dnf libselinux-python

- name: Gather facts
  setup:
Yes, there is just setup: which does gathering of the facts ;)
See the setup module docs for more details.


That's it. 

Sources