Loaded Configuration File => (none) Apache not reading php.ini

php.ini is a core file to handle the behavior of PHP and sometimes apache might not pick it and php might not be using and it will create problem.

To resolve this, just see the output of phpinfo first.
Just add the following code snippet in the php file and run it through your server

<?php
phpinfo();

Then look of configuration file (php.ini) path, by default it would be /etc
If you don’t have the file php.ini in that mentioned directory, just look for related ones like php.ini.default or something and just copy that as php.ini and restart your apache.

do you postfix?

Recently I was engaged on setting up mail client on the new redhat (rhel6) server for one of my clients. The server was on its default setup of sendmail. Since it is a bit outdated, I decided to use postfix relaying on gmail SMTP.

First thing first, make sure sendmail is not running by running this command

sudo service sendmail stop

Make sure if there are any lingering processes out there by issuing proper process listing commands on your server and kill those if you have to

Then check if you have postfix installed your machine

sudo service postfix start

If you got any complaint like service not found or something along that line, just install the postfix

sudo yum install postfix

Ok now lets go to the juicy part of integrating the postfix with gmail SMTP.
Lets assume your username is gopostfixgo@gmail.com and password is #nomoresendmail

Now lets proceed to the configuration part of the postfix.
go to postfix config folder

cd /etc/postfix

Here you will see a couple of files. Our interest would be on the main.cf file
First, before you start messing with the file, create a copy of it

sudo cp mail.cp main.cp.bak

Just go to the end of file and add the following snippet in there

smtp_use_tls = yes
smtp_sasl_auth_enable = yes
smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd
smtp_sasl_security_options = noanonymous
smtp_tls_CAfile = /etc/pki/tls/certs/self.pem
relayhost = [smtp.gmail.com]:587    

That last line right there would tell the postfix it has to relay the SMTP to other server.

Now lets create the sasl_passwd file

sudo touch sasl_passwd
echo "[smtp.gmail.com]:587 gopostfixgo@gmail.com:#nomoresendmail" > sasl_passwd

The above command would add the content to the sasl_passwd file.

Then to obscure the password information you placed on in the sasl_passwd file,

sudo postmap /etc/postfix/sasl_passwd

The other point would be creating a self certificate you would be using for your secure communication. If you have a certificate you are using already, then just point it to the right place and you should be fine

cd /etc/pki/tls/certs/
make self.pem

The above command would give you interactive wizard that you will follow and create the certificate.

After this, you need to tell the postfix to pick the changes you have been ramming. For that just restart postfix

sudo service postfix restart

Then open your logger to see if there are anything that are suspicious going or if mail is not working, you can tail it as

tail /var/log/maillog

Common Errors
1. Google might be sending some kind of error saying you have to log into the web browser bla bla bla.. then do the following
Go to https://www.google.com/settings/security/lesssecureapps and login with your google account and turn it on

Mount to NSF Server timed out on Vagrant

I had a bit rough weekend 🙁 after successful update of some packages and successful breakage of my guest machine aka vagrant.
The thing is my symfony app is running on vagrant and all of a sudden I can’t ssh or after halt I can’t vagrant up – it is giving me the mount to NFS server timed out

This has something to do, unfortunately, with the firewall setting. After the guest and the host are two, at least technically, machines and firewall decided to block the packets for some of the host machine applications.

You can comb those needed for it by looking from the list of the firewall..
On Mac => go to System Preferences and click on Security and Privacy and Turn off the firewall to make sure the issue is associated with it and then you can turn it back with applications related to virtual host to accept all the incoming traffic.

t h a t i s IT

Working From Home? Here are some tips for ya

As it sounds nice, unless you follow some guidelines, working from home can be quite boring and unpleasing, been there :).. here are some tips I will share with you to be as effective as possible

You and Your House – Nothing Technical

#1 – Hygiene – Looks trivial ha? Working from, unfortunately, is highly associated with working in pajamas which is mostly correct. Think about it and you can’t find any other thing filthier than that, you are working with what you wore the whole night ugh.. Guess what comes along with that – you might not take shower too.
So the fix, make sure that is your priority, dart into your shower before hitting your desk. Brush your teeth, wear your deodorants.. basically do what you would have done if you were to fly to your office. This has a very refreshing effect on you especially on the morning.

#2 – Dress Nice – yeah mostly if you have done tip #1, this would come natural. Just wear something other than your pajama. Also, use this opportunity to wear what you want, shorts, flipflops, hoodies.. you are not supposed to follow dress code here – just dress nice.
This has a good effect on you especially when you want to go out – you are just ready and you won’t have excuse not to go out and get fresh air 🙂

#3 – Clean your Surrounding – This would apply if you are single mostly. It would come easy to toss papers and pizza boxes here and there, not to clean your kitchen and bathroom, not to fix your bed and not to let fresh air to your room. This would be a simple reason to hate your room. It is difficult to keep up with it as I have trouble to do that, but if you make it habit, then the flip side would be impossible in return.

#4 – Make sure You Are Well Fed – One thing I noticed working from home is how easy it is to miss lunch and breakfasts most of the time. I think I was OK when I was working in the office as there would be others reminding for lunch or to a short trip to the near by corner store. I don’t have to explain why you should not be hungry – you will easily be angry and angry programmer is the one you don’t want to be.
The fix – make sure you have snacks, fruits, candies, string cheese, yogurt or something that can be consumed immediately in your house, some protein bars are good too. They might not be healthy in most cases, but be selective and store them. Have your stack of water and beverages at hand as well.
But, the biggest thing would be to be able to cook. One thing, it would help you for break, and second you feel great that you are eating what prepared which is healthier and cheaper.

#4 – Exercise – Yup, it is like blinking of an eye when 10-12 hours of your day flies by before your eyes. The more you do that, the more your body would get used to it and hence less metabolism and high carbs would be your immediate friends. You definitely don’t want that.
the fix – Have smaller dumbbells at your house it could range from 6-50lb and make sure you play with them every 2 hours or so, you can set your mobile alarm or one of those gadgets which would help you remind that you should get up and do some exercise. Pushups, pullups, situps, stretches, head to knees, joggings, boxings.. there are numerous of those you can do in your house – just make sure you know your limit and you do it drop at a time. If you over do it, since you know where the bed is..

#5 – Have Natural Light – In the morning, open your blinds and let the light fill your room. It is natural and energetic than the lamp hanging on your roof. Also, let the air visit your surrounding as well.

#6 – Get Office Chair and Desk – You might be tempted to work from bed. nahh.. Avoid that for a lot of reasons. The first, you are breaking tip #1, as you might still be in your pajamas if you work from bed :), two it not healthy for your back as you might be curling yourself, third, you are way near for sleeping and productivity might not look good.
The fix – Get office chair and desk. There are a lot of Ergonomic chairs out there that are meant to be helpful for longer hours of working, the desk too..

#7 – Reminder for taking break – If you were in the office, there are quite successive breaks you would take without your conscious. A co-worker might be sharing a story what she and her husband run into when they were dining in the neighborhood, a fellow programmer requesting for review or help, breaking news on the TV, funny links being passed around on the communication tools and the like.. all those are effective ways of staying alert and taking a break. You won’t get those when you are in your own dungeons – so do that reminder on your one-of-many gadgets you sport.
But, make sure you know your limit as well, it is easy to get carried away on youtube or huffingtonpost..

#8 – Limit Your Communication – It would come handy talking to phone and responding to texts when you work from home. But somehow people would respond or call per your rate of communication. Though it is good to communicate, you should also tell yourself that you are at “work” and all the ethics and discipline would 100% apply here too. So, be cautious about it and setback.

#9 – Hangout Online With Coworkers – You work from home and so does others, they are your co-workers. So you can still hangout with them and chitchat a bit on work related or completely non-work related stuff. That would make it more natural – you are sharing thoughts or concerns and what nots with co-worker. This is even more effective way to learn about the work itself and about your virtual friends. Still business as usual, you are working with/for them and communication with them shall not and will not deter the professionalism you have.

#10 – Music – There are quite number of researches out there on how music would affect the ability of concentration while programming. For me, it is working fine, I can put on my headphone and just work fine – probably this is something I picked from my co-workers. I am just mentioning it – this is absolutely personal color choice. The good thing is working from home serves both choices equally.. if you like woking in a silent or in music, the actions to be taken are entirely in your hands.

#11 – Work outside 2 Days a Week – I have worked from Starbucks, public libraries, college libraries[this has some limitation], hotel lobbies, restaurants and literally anywhere I see that wifi logo.. but I have to admit Starbucks is the number one. It is great to work outside of your home for the sake of change. It provides the best of two worlds – you are alone and you are with peoples as well – what a goodie! Just make sure the rules of the places, some places like Panera Bread would allow you to work for 30 mins only during their busy hours, others like college libraries might not allow you to tunnel, and others have cap on bandwidth usage. Worst case, you can tether from your phone and work till you make it to your home. But, going out and working from those areas would make you feel active outgoing

#12 Have Something To Play With Yoyo is the best one in this category. Just have yoyo, some, rubik’s cube, small robots and the like that you would invest maybe 5 minutes when your brain is tied up with solving a problem and/or trying to come up with better algorithm for the problem you are facing.. again..

Next time I will share a thought on You and Tech – on how to stay sharp and upto the technology, tools to help that, news and selected articles sites..

Let me get back …

Apache listing directory – I swear I have index file!

OK, the ultimate wisdom is you will put your index file on the webserver accessible directory and your website would be visible – right? Well, not all the time.
Apache might decide to list your files even though you put your index.php in the directory you are expecting..
The thing lies on the default configuration of your server. If the default http.conf file has the directory setting to list then it will list even in the virtual hosts.
The fix Add your DirectoryIndex

So typical .htaccess or your setting in http.conf file would look like

...you other configs
   DirectoryIndex index.php //or whatever you want it to start from 
....your other configs

vOILa

Vim not syntax highlighting in sudo/root huh..

So I had to deal with the server issue and I ssh into it. Then opened the file looked at it and wanted to change the content, I had to be on root and I noticed the syntax highlighting was off..
Here are the steps I took to check what went wrong.
Basically when I am sudo-ing the user has changed a bit. So the configuration per that user is the area of focus.
Also, there could be multiple installations and vanilla versions for the vim as well, so check which one the sudo is using

sudo which vim

I was able to locate the right vim the sudo was using and I applied that one to fix the issue

:insert not working for pasting on Vim editor

I will not explain how useful vim is, if you a developer on the *nix systems, then that is number one tool to tuck into your toolbox.

Now you want to paste huge text into vim and it looks all wacky, and the insert mode is not handling it.. here is what you would do..

Open your vim with

vi filename.ext

then do

:set paste

This will allow your vim to be in the paste mode and you can dump all you have without any problem then change the mode using esc and save it as :w

Access MySQL from Host being on Vagrant

For this all you would need is tunneling/port forwarding from vagrant to mysql.

Being on vagrant machine, figure out what the host ip is, usually netstat would tell you that.
The default being 10.0.2.2 and assuming you have 3306 port on host machine do the following

ssh username@10.0.2.2 -L 3306:127.0.0.1:3306 -N

The above would forward the 3306 [ the one on the left ] to the hosts port. Mind you, you have to use 127.0.0.1 to access your vagrant machine in place of localhost which might not work.

Setting new Vagrant machine for PHP-Mysql development

As a developer you would know how stressful it would be to setup a machine. Even once you figure this out and set your machine working, you might be surprised by how it would get wacky easily when you update OS for specific packages. This is specially true mostly for *nix boxes.
Also this holds true for the new developer joining the team. Someone has to help him and all the time something might now work b/c of newer version of OS or something else.

The solution? Vagrant
Vagrant is relatively the new kid in this area. In short, it is like having a computer in your computer that is preconfigured with all what you need so that you can just start coding without having the hustle of installing 40+ packages.

Lets have PHP+MySQL+Memcached+.. setup using Vagrant

1. First thing first Get the provider
I am assuming the dev machine in this tutorial so the provider would be VirtualMachine
Get your share from Here

2. Install vagrant from Here

Go through the above links, download them and install them.. I am sure you rock star on this one 🙂

3. Start the provision. The advanced way to have provision would be either through the puppet or chef files.
But, for the php there is awesome site for simulating this. Go to Here and invest sometime there..
For now, just follow the wizard there until you get the box, we will replace the config file anyway.

4. Once you got your zip file unzip it wherever you want and replace the config file with the following

---
vagrantfile-local:
    vm:
        box: puphpet/ubuntu1404-x64
        box_url: puphpet/ubuntu1404-x64
        hostname: 'vagrant-local'
        memory: '1024'
        cpus: '1'
        chosen_provider: virtualbox
        network:
            private_network: 192.168.56.101
            forwarded_port:
                BXfJQibZ50h1:
                    host: '8640'
                    guest: '22'
                mysql:
                    host: '3307'
                    guest: '3306'
        post_up_message: ''
        provider:
            virtualbox:
                modifyvm:
                    natdnshostresolver1: on
            vmware:
                numvcpus: 1
            parallels:
                cpus: 1
        provision:
            puppet:
                manifests_path: puphpet/puppet
                manifest_file: site.pp
                module_path: puphpet/puppet/modules
                options:
                    - '--verbose'
                    - '--hiera_config /vagrant/puphpet/puppet/hiera.yaml'
                    - '--parser future'
        synced_folder:
            K2NewVabIO4S:
                owner: www-data
                group: www-data
                source: ./
                target: /var/www
                sync_type: nfs
                rsync:
                    args:
                        - '--verbose'
                        - '--archive'
                        - '-z'
                    exclude:
                        - .vagrant/
                    auto: 'false'
        usable_port_range:
            start: 10200
            stop: 10500
    ssh:
        host: null
        port: null
        private_key_path: null
        username: vagrant
        guest_port: null
        keep_alive: true
        forward_agent: false
        forward_x11: false
        shell: 'bash -l'
    vagrant:
        host: detect
server:
    install: '1'
    packages:
        - build-essential
        - memcached
        - vim
        - curl
        - git-core
        - imagemagick
        - sendmail
        - libmemcached-dev
        - htop
        - unzip
        - mercurial  
users_groups:
    install: '1'
    groups: {  }
    users: {  }
cron:
    install: '1'
    jobs: {  }
firewall:
    install: '1'
    rules: null
apache:
    install: '1'
    settings:
        user: www-data
        group: www-data
        default_vhost: true
        manage_user: false
        manage_group: false
        sendfile: 0
    modules:
        - rewrite
    vhosts:
        ekjd369uxkx8:
            servername: my-local-website.com
            serveraliases:
                - www.my-local-website.com
            docroot: /var/www/local-website
            port: '80'
            setenv:
                - 'APP_ENV dev'
            directories:
                twe3plnvcymi:
                    provider: directory
                    path: /var/www/local-website
                    options:
                        - Indexes
                        - FollowSymlinks
                        - MultiViews
                    allow_override:
                        - All
                    require:
                        - all
                        - granted
                    custom_fragment: ''
            engine: php
            custom_fragment: ''
            ssl_cert: ''
            ssl_key: ''
            ssl_chain: ''
            ssl_certs_dir: ''
    mod_pagespeed: 0
nginx:
    install: '0'
    settings:
        default_vhost: 1
        proxy_buffer_size: 128k
        proxy_buffers: '4 256k'
    upstreams: {  }
    vhosts:
        ayer2gfhqh9a:
            proxy: ''
            server_name: my-local-website.com
            server_aliases:
                - www.my-local-website.com
            www_root: /var/www/local-website
            listen_port: '80'
            location: .php$
            index_files:
                - index.html
                - index.htm
                - index.php
            envvars:
                - 'APP_ENV dev'
            engine: php
            client_max_body_size: 1m
            ssl_cert: ''
            ssl_key: ''
php:
    install: '1'
    version: '55'
    composer: '1'
    composer_home: ''
    modules:
        php:
            - cli
            - intl
            - mcrypt
            - curl
            - memcached
            - sqlite
        pear: {  }
        pecl:
            - pecl_http
    ini:
        display_errors: On
        error_reporting: 'E_ALL & ~E_STRICT'
        session.save_path: /var/lib/php/session
    timezone: America/Los_Angeles
    mod_php: 0
hhvm:
    install: '0'
    nightly: 0
    composer: '1'
    composer_home: ''
    settings:
        host: 127.0.0.1
        port: '9000'
    ini:
        display_errors: On
        error_reporting: '-1'
    timezone: null
xdebug:
    install: '1'
    settings:
        xdebug.default_enable: '1'
        xdebug.remote_autostart: '0'
        xdebug.remote_connect_back: '1'
        xdebug.remote_enable: '1'
        xdebug.remote_handler: dbgp
        xdebug.remote_port: '9000'
xhprof:
    install: '0'
wpcli:
    install: '0'
    version: v0.17.1
drush:
    install: '0'
    version: 6.3.0
ruby:
    install: '1'
    versions:
        t4DlEFgKoFSk:
            version: ''
nodejs:
    install: '1'
    npm_packages: {  }
python:
    install: '1'
    packages: {  }
    versions:
        juTtbSrrnLMG:
            version: ''
mysql:
    install: '1'
    override_options: {  }
    root_password: '123'
    adminer: 0
    databases:
        YET9UxaCD4KV:
            grant:
                - ALL
            name: dbname
            host: localhost
            user: dbuser
            password: '123'
            sql_file: ''
postgresql:
    install: '0'
    settings:
        root_password: '123'
        user_group: postgres
        encoding: UTF8
        version: '9.3'
    databases: {  }
    adminer: 0
mariadb:
    install: '0'
    override_options: {  }
    root_password: '123'
    adminer: 0
    databases: {  }
    version: '10.0'
sqlite:
    install: '1'
    adminer: 0
    databases: {  }
mongodb:
    install: '1'
    settings:
        auth: 1
        port: '27017'
    databases: {  }
redis:
    install: '1'
    settings:
        conf_port: '6379'
mailcatcher:
    install: '1'
    settings:
        smtp_ip: 0.0.0.0
        smtp_port: 1025
        http_ip: 0.0.0.0
        http_port: '1080'
        mailcatcher_path: /usr/local/rvm/wrappers/default
        from_email_method: inline
beanstalkd:
    install: '0'
    settings:
        listenaddress: 0.0.0.0
        listenport: '13000'
        maxjobsize: '65535'
        maxconnections: '1024'
        binlogdir: /var/lib/beanstalkd/binlog
        binlogfsync: null
        binlogsize: '10485760'
    beanstalk_console: 0
    binlogdir: /var/lib/beanstalkd/binlog
rabbitmq:
    install: '1'
    settings:
        port: '5672'
elastic_search:
    install: '1'
    settings:
        version: 1.4.1
        java_install: true
solr:
    install: '1'
    settings:
        version: 4.10.2
        port: '8984'
php_memcached:
    install: '1'

** I have used 1G memory size for the guest. You can increase or decrease based on your physical memory accounting.

**Notice the usage of nfs here. In the case of windows OS, it might not work as expected so you might have to select samba or something to for the file synching part. I haven’t tried anything on windows for a while so don’t quote me on this.

As you might have guessed it, this is the heart of the provision. This will telling your little box what it should stuff to itself to be ready for PHP coding.
4. Now you have all the necessary stuff to get started. So far your machine has php, apache2 web server, mamcached and radis for your caching, mongodb incase you need it, git and mercurial for your versioning and more server goodies.
So if you want to add server based packages, go under the server and add your package. In this provision, ubuntu distro is used. There are many flavors out there. So, when you add the server package make sure the appropriate bundle is sited there to get away from surprises.

Being on the same directory as your config.yaml file, run

vagrant up

This one liner, will read the config file and populate your box with all the packages you listed with web server and and everything.

** If you see something strange like a bunch of red lines, please read it carefully and try to research it. You can also ask here and I will try to help.

Hopefully, it will all run nicely

5. Now you can say hi to your new machine by logging into it using

vagrant ssh

The above command will land you the virtual machine packed with all the software you have requested.. Feel free to move around, check apache, memacache and the like..

6. Now, if you notice, there is a part on the config.yaml file that mentions local-website
Lets talk a bit about it.
Vagrant will sync the folders between the host and the guest boxes. That is a great relief. You can work on any files from your favorite IDE on your host and all the changes would take effect on the guest machine – the trick is you are updating the same file. Thanks to nfs.
So, Vagrant will sync anything on the host directory that hosts the Vagrantfile to the guest sync folder in accordance to how you tell it. We have told it to match anything in the aforementioned folder to be syncd with /var/www inside the guest machine. So if you go to your /var/www folder inside your guest box, you will see the replica of the files and directories there.

Create a folder local-website inside the directory where you unzip the zip file, that is the one holding the Vagrantfile file.

mkdir local-website

And create an index file inside it

touch local-website/index.php

Inside the index.php just put the phpinfo()

<?php
phpinfo();

7. Moment of truth!
We will try to access the web from our guest machine being on the host machine.
Before that, we have tell to our host machine what my-local-website.com mean. See how this is used as server name in the config.yaml file

Go to your host’s /etc/hosts file and insert 192.168.56.101 my-local-website.com

sudo echo "192.168.56.101 my-local-website.com" >> /etc/hosts

What this does is, when you type my-local-website.com on your browser, before it is relayed to the outer DNS, it will check if it has to do something with it. In this case it will forward it to 192.168.56.101.
If you lookup for this ip-address in the config.yaml file we created, you will see it under the network. This is the ip-assigned for the host in the little host-guest network vagrant provides.

Now you can go to your favorite browser and type my-local-website.com to see the phpinfo() of your guest machine’s php settings.

This will end up the journey. Now you have a fully working box that you can save it somewhere and reuse it anytime.

8 Bonus.
To shutdown the box use

vagrant halt

To destroy the box – this will, as the name implies remove everything

vagrant destroy

If you update the config file, you have to re-provision it by

vagrant provision