LINUX



Visit Symfony Section
Visit Ubuntu Section
Visit MySQL Section

Symfony


Symfony is framework for developing PHP applications. I tried Symfony in my Ububtu 12.04 Desktop.
Step 1) Download LAMP server: $sudo apt-get install lamp-server^
Open browser and type http://localhost
If You see (It Works!), then it's fine.

Step 2) Download PHPMYADMIN for future use.
$sudo apt-get install phpmyadmin
Provide necessary passwords as prompted.
Open browser and type http://localhost/phpmyadmin
User name: root and Password as provided by you. (Everything should look fine)

Step 3) Now let's start Symfony. ( I have used Symfony 2.3.0)
composer.phar is a file that will be our guide. it plays the most important role. So where to get it?
Go to getcomposer.org and click on download. Now you will see a line curl -sS .... Copy it.
Open your terminal window. (Use sudo command always or $sudo su to make your journey comfortable.)
$sudo curl -sS https://getcomposer.org/installer | php
Now you are ready with composer.phar ( I have issued this command when I was in /var/www directory)

Step 4) We will start creating a project
Open Terminal window and issue this command
$php composer.phar create-project symfony/framework-standard-edition path/ 2.3.0
(here 'path' is the destination folder where you like to create your project. For me this command is
$php composer.phar create-project symfony/framework-standard-edition gpd/ 2.3.0)
This may take a few minutes to complete. When completed I got the following message.
[ The result shows like this.
Installing symfony/framework-standard-edition (v2.3.0)
- Installing symfony/framework-standard-edition (v2.3.0)
Loading from cache

Created project in gpd/
Loading composer repositories with package information
Installing dependencies (including require-dev)
- Installing jdorn/sql-formatter (v1.2.9)
Loading from cache

- Installing doctrine/common (2.3.0)
Loading from cache

- Installing doctrine/dbal (2.3.4)
Loading from cache

- Installing psr/log (1.0.0)
Loading from cache

- Installing twig/twig (v1.13.1)
Loading from cache

- Installing symfony/symfony (v2.3.1)
Loading from cache

- Installing symfony/icu (v1.0.0)
Loading from cache

- Installing doctrine/doctrine-bundle (v1.2.0)
Loading from cache

- Installing twig/extensions (v1.0.0)
Loading from cache

- Installing kriswallsmith/assetic (v1.1.1)
Loading from cache

- Installing symfony/assetic-bundle (v2.3.0)
Loading from cache

- Installing monolog/monolog (1.5.0)
Downloading: 100%

- Installing symfony/monolog-bundle (v2.3.0)
Downloading: 100%

- Installing incenteev/composer-parameter-handler (v2.0.0)
Downloading: 100%

- Installing doctrine/orm (2.3.4)
Downloading: 100%

- Installing swiftmailer/swiftmailer (v5.0.1)
Downloading: 100%

- Installing symfony/swiftmailer-bundle (v2.3.1)
Downloading: 100%

- Installing sensio/distribution-bundle (v2.3.1)
Downloading: 100%

- Installing sensio/framework-extra-bundle (v2.3.1)
Downloading: 100%

- Installing sensio/generator-bundle (v2.3.1)
Downloading: 100%

kriswallsmith/assetic suggests installing leafo/lessphp (Assetic provides the integration with the lessphp LESS compiler)
kriswallsmith/assetic suggests installing leafo/scssphp (Assetic provides the integration with the scssphp SCSS compiler)
kriswallsmith/assetic suggests installing ptachoire/cssembed (Assetic provides the integration with phpcssembed to embed data uris)
kriswallsmith/assetic suggests installing leafo/scssphp-compass (Assetic provides the integration with the SCSS compass plugin)
monolog/monolog suggests installing mlehner/gelf-php (Allow sending log messages to a GrayLog2 server)
monolog/monolog suggests installing raven/raven (Allow sending log messages to a Sentry server)
monolog/monolog suggests installing doctrine/couchdb (Allow sending log messages to a CouchDB server)
monolog/monolog suggests installing ext-amqp (Allow sending log messages to an AMQP server (1.0+ required))
monolog/monolog suggests installing ext-mongo (Allow sending log messages to a MongoDB server)
Writing lock file
Generating autoload files
Creating the "app/config/parameters.yml" file.
Some parameters are missing. Please provide them.
database_driver (pdo_mysql):
database_host (127.0.0.1):
database_port (null):
database_name (symfony):
database_user (root):
database_password (null):your MySQL Password
mailer_transport (smtp):
mailer_host (127.0.0.1):
mailer_user (null):
mailer_password (null):
locale (en):
secret (ThisTokenIsNotSoSecretChangeIt):
Clearing the cache for the dev environment with debug true
Installing assets using the hard copy option
Installing assets for Symfony\Bundle\FrameworkBundle into web/bundles/framework
Installing assets for Acme\DemoBundle into web/bundles/acmedemo
Installing assets for Sensio\Bundle\DistributionBundle into web/bundles/sensiodistribution
root@gpdas:/var/www#
]
Alternative way:
Why to waste time in doing step 4? Download Symfony 2.3.x .tgz tar file from symfony.com
Untar this directly in /var/www/gpd ( It creates all directory structure with a Demo site)

Step 5)
Create Virtual Host 'gpd'. Copy the following code in /etc/apache2/sites-available/gpd)

ServerName gpd

DocumentRoot /var/www/gpd/web

Options FollowSymLinks
AllowOverride None


Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all



Instead of 'gpd', you write your name as you like.
Now enable this virtual host in /etc/apache2/sites-enabled directory.
This can be achieved by 2 ways.
a) $sudo $a2ensite gpd
Or
b) Be inside /etc/apache2/sites-enabled directory and issue this command
$ln -s ../sites-available/gpd

Then define gpd in /etc/hosts file by adding this line below the line meant for localhost
127.0.0.1 gpd

Now restart/reload apache by issuing this
$sudo /etc/init.d/apache2 restart

Now you are ready to work with your new Symfony project. Have Fun....


Ubuntu


Visit Symfony Section
Visit Ubuntu Section
Visit MySQL Section
How to check COM / Serial port availability and name
In terminal give the command
$dmesg|grep tty
I have connected USB to Serial converter cable, it shows ttyUSB0

You can check all HW by this command
$checkbox-gtk (If checkbox-gtk is not installed the install it by using apt-get)

OR

$lshw

OR

$lspci -v

How to check 32 bit OR 64 bit OS
$uname -a

Kannel Issues
For installing kannel in your system
$sudo apt-get install kannel
The configuration file will be at /etc/kannel
To run kannel, Open a terminal and give command $sudo bearerbox kannel.conf
Then open another terminal and give the command $sudo smsbox kannel.conf
To send sms http://localhost:13002/cgi-bin/sendsms?username=xxx&password=yyy&from=111&to=222&text=msg
If kannel is not properly initialised with the error "Address already in use"
The kill kannel related processes as follows
$ps -ef|grep kannel ( It will show 3 processes)
$sudo kill -9 ProcessID

How to check LAN and WLAN addresses
Open a terminal window and enter the following command:
$nm-tool

U can also type
$ip addr

How to capture TCP/IP packets
sudo tcpdump -qnnpi eth1
sudo tcpdump -Annpi eth1 (View packets in ASCII format)
sudo tcpdump -Xnnpi eth1 (View packets in HEX and ASCII format)
sudo tcpdump -eqnnpi eth1 (View packets with L2 Layer)
sudo tcpdump -qnnpi eth1 -w capture.pcap (To save captured packets)
capture.pcap can be opened wsing Wireshark.





MySQL


Visit Symfony Section
Visit Ubuntu Section
Visit MySQL Section
Visit the Useful MySQL Section
Problem: In the latest version of MySQL 5.5 LOAD DATA LOCAL INFILE does not work.
Solution: In Ubuntu edit the file /etc/mysql/my.cnf as follows.
[mysqld] (This line is already available)
local-infile = 1 (This line is to be added below the [mysqld] line)

Then some stuff

[mysql] (This line is already available)
local-infile = 1 (This line is to be added below the [mysql] line)

Now save the file.

Now I can use LOAD DATA LOCAL INFILE from the command prompt.

But this is not working inside the PHP script.
To solve this problem I googled a lot and found the following line from stackoverflow.com
$conn=mysql_connect("localhost","username","password", false, 128) or die("Unable to Connect to Server");
By adding 'false and 128' arguments surprisingly it works.

One more suggestion is there, but I have not tried..
while starting MySQL do as follows
mysql --local-infile -u root -p password db-name


37 comments:

  1. SELECT (UNIX_TIMESTAMP( dt5 ) - UNIX_TIMESTAMP( dt6))/3600 from testdate
    TO GET DIFF OF DATES IN HOURS

    ReplyDelete
  2. insert into faultreport(btsid, bscid,status, flttime, restime, duration) (SELECT btsid, bscid, status, flttime, restime, (UNIX_TIMESTAMP( restime ) - UNIX_TIMESTAMP( flttime))/3600 from faultrlcrpbkp where status=1)

    ReplyDelete
  3. Counting duplicates like you are after is fairly easy.
    Put this in cell Z2:
    =countif($Y$2:$Y$50,Y2)
    and copy on down to Z50.
    This will count how many times a value appears in a range.
    Now sometimes you want just the unique entries and get rid of any duplicates. Not what you're after, but I'll provide it anyway.
    In cell Z2:
    =IF(COUNTIF($Y$2:Y50,Y2)>1,"duplicate","unique")

    ReplyDelete
  4. scp username@ipaddress_of_server:/path/to/file/in/server .

    This will copy the file to your Current working directory, dot at the end indicates Present working directory.

    ReplyDelete
  5. # download: remote -> local
    scp user@remote_host:remote_file local_file

    # upload: local -> remote
    scp local_file user@remote_host:remote_file

    ReplyDelete
  6. PUTTY USER https://community.freescale.com/thread/220596
    At the Windows command prompt, enter:
    pscp source_file_name userid@server_name:/path/destination_file_name.

    For example:
    c:\>pscp june06extract wrhse@warehouse.cit.cornell.edu:/mydata/june06extract.
    It is tested by me. Only thing is you have to download pscp.exe from putty site http://www.chiark.greenend.org.uk/~sgtatham/putty/download.html

    ReplyDelete
  7. DELETE n1 FROM names n1, names n2 WHERE n1.id > n2.id AND n1.name = n2.name
    Delete Duplicate rows keeping lowest id record.
    DELETE n1 FROM names n1, names n2 WHERE n1.id < n2.id AND n1.name = n2.name
    Delete Duplicate rows keeping highest id record

    ReplyDelete
  8. How to import large CSV files into mysql 5.5 above
    #mysql --local-infile -u root -p
    give password,
    mysql>use dbname;
    load data local infile '/tmp/filename.csv' INTO TABLE tbl_name FIELDS TERMINATED BY ',' ENCLOSED BY '"' LINES TERMINATED BY '\r\n' IGNORE 1 LINES;

    ReplyDelete
  9. That's difficult to read, but I think you asked how to set up two network cards. Here is some help for static addressing. Edit the interfaces file and restart networking. Use your favorite text editor to...

    sudo vim /etc/network/interfaces

    And the contents of the file:

    auto lo
    iface lo inet loopback

    auto eth0
    iface eth0 inet static
    address 192.168.2.100
    netmask 255.255.255.0
    network 192.168.2.0
    broadcast 192.168.2.255
    gateway 192.168.2.1

    auto eth1
    iface eth1 inet static
    address 192.168.2.99
    netmask 255.255.255.0
    network 192.168.2.0
    broadcast 192.168.2.255
    gateway 192.168.2.1

    Save and restart networking:

    sudo /etc/init.d/networking stop
    sudo /etc/init.d/networking start

    ReplyDelete
  10. HOW TO send sms from linux terminal
    wget "http://localhost:13002/cgi-bin/sendsms?username=xxx&password=yyy&from=111&to=222&text=msg"

    ReplyDelete
  11. How to view triggers
    SQL query show triggers
    print full text displayed at bottom
    copy the contents of trigger using mouse.

    ReplyDelete
  12. To find and replace text within the current document in NANO EDITOR:

    Ctrl \

    ReplyDelete
  13. How to take back up of databases using mysqldump
    shell>mysqldump dbname > dump.sql
    shell>mysqldump --databases dbname1 dbname2 dbname3 > dump.sql
    shell>mysqldump --all-databases > dump.sql

    ReplyDelete
  14. ASP.NET - faced problem while updating a docket in docmod1101 application. While browsed in server error was 'use an updateable query'. Right click 'orissagsmfault' inside which the mdb file is there, Properties- Security- select User- double click- Allow full control. In asp.net program, default.aspx, define datasource. That's all

    ReplyDelete
  15. How to know Apache version in Ubuntu
    In command line type this
    curl --head http://localhost

    ReplyDelete
  16. phpmyadmin was not showing table contents.
    Error was shown like this
    Select 'prefs' from phpmyadmin.pma__tables_uipref.....
    Solution
    step 1: Replace all _ by __ in the file /etc/phpmyadmin/config.inc.php line 81 to 94
    Step 2: Copy create_table.sql.gz from /examples folder to local PC using pscp
    This file can be found out by using command locate file-name
    Step 3: Open phpmyadmin in local PC, go to the start page, not inside any db.
    Import->browse-> create_tables.sql.gz->go
    That's it.

    ReplyDelete
  17. Compare two tables to find the common and uncommon fields

    [Get common fields from two tables] - SELECT x.name from testjoin1 x inner join testjoin2 y on x.name=y.name

    [Get one field of x that is not in y] - SELECT x.name from testjoin1 x left outer join testjoin2 y on x.name=y.name where y.name is null

    ReplyDelete
  18. How to Export and import crontab contents

    Create the backup:

    crontab -l > /some/shared/location/crontab.bak

    Import it from the new user:

    crontab /some/shared/location/crontab.bak

    ReplyDelete
  19. Check status of RAM in linux system 4 commands given below
    free -m
    top
    htop
    vmstat -s
    How to free cache memory
    sudo sh -c "sync; echo 3 > /proc/sys/vm/drop_caches"
    echo 1 clears 'Page Cache' echo 2 clears 'dentries and inodes, echo 3 clears both

    ReplyDelete
  20. How to check the disk usage, which folder is eating the space.
    df to see the disk free
    To see Directory-wise usage
    sudo du -h --max-depth=1 -x /
    Instead of / we can specify /tmp, /var etc to avoid delay.

    ReplyDelete
  21. Find out top 10 large files
    sudo du -a /home | sort -n -r | head -n 10 (/home, /var, even / can be given)
    To find out who is eating space
    sudo du -sh /*

    ReplyDelete
  22. How to start & stop networking
    sudo ifdown eth0 && sudo ifup eth0

    ReplyDelete
  23. ftp_connect('IP Address', port no.);
    Pl note IP Address will be inside Single Quote, the Comma, then Port no. will not ne inside Quote.
    If IP is 127.0.0.1 and port is 2111, then
    ftp_connect('127.0.0.1', 2111);

    ReplyDelete
  24. # This file describes the network interfaces available on your system
    # and how to activate them. For more information, see interfaces(5).

    # The loopback network interface
    auto lo
    iface lo inet loopback

    # The primary network interface
    auto eth0
    iface eth0 inet static
    address 172.27.4.64
    netmask 255.255.0.0
    gateway 172.27.4.1
    dns-nameservers 8.8.8.8
    auto eth0:1
    iface eth0:1 inet static
    address 192.168.6.51
    netmask 255.255.0.0
    auto eth0:2
    iface eth0:2 inet static
    address 10.210.135.47
    netmask 255.255.0.0
    auto eth0:3
    iface eth0:3 inet static
    address 10.202.51.37
    netmask 255.255.0.0
    post-up route add -net 192.168.0.0 netmask 255.255.0.0 gw 192.168.6.1
    post-up route add -net 10.210.0.0 netmask 255.255.0.0 gw 10.210.135.62
    post-up route add -net 10.202.0.0 netmask 255.255.0.0 gw 10.202.51.1
    post-up route add -net 10.228.0.0 netmask 255.255.0.0 gw 172.27.4.253

    ReplyDelete
  25. You can accomplish this using the mysqldump command-line function.

    For example:

    If it's an entire DB, then:

    $ mysqldump -u [uname] -p[pass] db_name > db_backup.sql
    If it's all DBs, then:

    $ mysqldump -u [uname] -p[pass] --all-databases > all_db_backup.sql
    If it's specific tables within a DB, then:

    $ mysqldump -u [uname] -p[pass] db_name table1 table2 > table_backup.sql
    You can even go as far as auto-compressing the output using gzip (if your DB is very big):

    $ mysqldump -u [uname] -p[pass] db_name | gzip > db_backup.sql.gz
    If you want to do this remotely and you have the access to the server in question, then the following would work (presuming the MySQL server is on port 3306):

    $ mysqldump -P 3306 -h [ip_address] -u [uname] -p[pass] db_name > db_backup.sql
    It should drop the .sql file in the folder you run the command-line from.

    ReplyDelete
  26. How to restore database from a dump file.
    mysql -u root -p db_restore < bkpfile.sql

    ReplyDelete
  27. How to add route in Linux
    route add -net 192.168.3.0 netmask 255.255.255.0 gw 192.168.3.10

    ReplyDelete
  28. grep -nr 'CELL ' rldepData.txt | gawk '{print $1}' FS=':' > cgiLineNo.txt

    grep -n gets the line number of each line.
    grep -nr gets the line number recursively including sub-directories.

    'CELL ' indicates a match occurs when there is 'CELL ' in the
    gawk '{print $1}' FS=':' Prints the 1st field. FS=':' is not clear to me.

    ReplyDelete
  29. Set date and time in linux
    sudo timedatectl set-time '2016-05-22 07:38:40'
    If the Error comes like this
    Failed to set time: Automatic time synchronization is enabled
    then sudo apt-get install ntp
    then issue that command

    ReplyDelete
  30. Set date and time in linux
    sudo timedatectl set-time '2016-05-22 07:38:40'
    If the Error comes like this
    Failed to set time: Automatic time synchronization is enabled
    then sudo apt-get install ntp
    then sudo timedatectl set-ntp 0 [ to disable auto update ]
    then issue that command

    ReplyDelete
  31. Install Kannel with MySQL in Ubuntu Server
    I downloaded kannel 1.4.4, but it has problem in 'make'
    So I downloaded kannel 1.4.3
    Before this do the following

    sudo apt-get update
    sudo apt-get install build-essential
    sudo apt-get install bison
    sudo apt-get install libmysqld-dev
    sudo apt-get install libxml2 libxml2-dev

    tar -xvzf gateway-1.4.3.tar.gz

    cd gateway-1.4.3/
    ./configure --with-mysql
    make
    sudo make install

    ReplyDelete
  32. How to zip a folder in linux ubuntu

    zip -r filename.zip folderWishztoZip

    ReplyDelete
  33. What is #! at the beginning of a file?

    If you have several versions of Python installed, /usr/bin/env will ensure the interpreter used is the first one on your environment's $PATH. The alternative would be to hardcode something like #!/usr/bin/python; that's ok, but less flexible.

    In Unix, an executable file that's meant to be interpreted can indicate what interpreter to use by having a #! at the start of the first line, followed by the interpreter (and any flags it may need).

    If you're talking about other platforms, of course, this rule does not apply (but that "shebang line" does no harm, and will help if you ever copy that script to a platform with a Unix base, such as Linux, Mac, etc).

    ReplyDelete
  34. Remote IP of Visitors
    _____________________

    // get user details
    $user_agent = $_SERVER['HTTP_USER_AGENT']; //user browser
    $ip_address = $_SERVER["REMOTE_ADDR"]; // user ip adderss
    $page_name = $_SERVER["SCRIPT_NAME"]; // page the user looking
    $query_string = $_SERVER["QUERY_STRING"]; // what query he used
    $current_page = $page_name."?".$query_string;


    // get location
    $url = json_decode(file_get_contents("http://api.ipinfodb.com/v3/ip-city/?key=/*userapikey*/
    // you can get your api key form http://ipinfodb.com/
    ip=".$_SERVER['REMOTE_ADDR']."&format=json"));
    $country=$url->countryName; // user country
    $city=$url->cityName; // city
    $region=$url->regionName; // regoin
    $latitude=$url->latitude; //lat and lon
    $longitude=$url->longitude;

    // get time
    date_default_timezone_set('UTC');
    $date = date("Y-m-d");
    $time = date("H:i:s");

    ReplyDelete
  35. Transfer Files from Remote Server to Local disk and Vice-versa

    The syntax for scp is:

    If you are on the computer from which you want to send file to a remote computer:

    scp /file/to/send username@remote:/where/to/put
    Here the remote can be a FQDN or an IP address.

    On the other hand if you are on the computer wanting to receive file from a remote computer:

    scp username@remote:/file/to/send /where/to/put
    scp can also send files between two remote hosts:

    scp username@remote_1:/file/to/send username@remote_2:/where/to/put
    So the basic syntax is:

    scp username@source:/location/to/file username@destination:/where/to/put

    ReplyDelete
  36. NETWORK CARD IN UBUNTU
    ifconfig // show status
    lspci // show network card
    $ ifconfig -s -a // show alias name of network card

    ReplyDelete
  37. Accidentally deleted /var/log files in Ubuntu 16.04

    I've recently removed contents of several directories in /var/log so it was no surprise. The solution was to create the directory and make it owned by mysql user as in

    $ sudo mkdir /var/log/mysql
    $ sudo chown -R mysql:mysql /var/log/mysql

    please check
    https://stackoverflow.com/questions/42317139/job-for-mysqld-service-failed-see-systemctl-status-mysqld-service

    ReplyDelete