Instagram

Wiki It

Search results

Saturday 8 June 2013

Importing large files into mysql using phpmyadmin and command line



Before I forget to save this information somewhere I thought I would write this blog. I have had enough trouble just because of this error that I used to get when ever I tried importing large SQL files into MySQL.

If you had ever got this error message below then you must thank me for this tutorial for solving your problem :P


PHPMyAdmin already has an inbuilt import functionality but I have had problems importing large database files.

Firstly search for the config.inc.php file which in my case was in the following path

C:\Program Files (x86)\EasyPHP-DevServer-13.1VC9\modules\phpmyadmin3581x130608223830\

Find the line with:
$cfg['UploadDir'] = 'some path'; and update it to $cfg['UploadDir'] = 'upload';

Save and exit the file. After doing this, create a folder by name 'upload' inside 

C:\Program Files (x86)\EasyPHP-DevServer-13.1VC9\modules\phpmyadmin3581x130608223830\

and paste your large SQL file inside this directory. After doing so you will see a dropdown inside the Import section of your PHPMyAdmin and your file listed in the dropdown. Select it and click GO to import it. 

If at all if you like to do it via command line then,

C:/path_to_your_upload_dir> mysql -h hostname -u username -p databasename > filename.sql

Replace the host, username and database with the one you want to import. Before trying this you need to make sure that you have a username, database created for the file you are going to import into the database. This will ask for the password as well for which you should give the one you created while creating the user. 

This would take a few minutes depending upon your file size. Thanks once again, hope this helps someone. Thank you!
















Monday 18 March 2013

Installing Drupal in Ubuntu

We can create our own blogs, websites using a very famous Content Management Systems (CMS). One such CMS is Drupal.

I assume you have XAMPP installed in your pc. If not please check out my other blog on how to install lampp server in ubuntu

Before starting download your latest copy of Drupal here.

Pre-Installation:
By now you would have downloaded this file drupal-7.21.tar.gz

Install Drupal:
Lets install Drupal by extracting its content to "/opt/lampp/htdocs"

1.) Locate the file in your local system (mine was in the Downloads folder).
2.) Now open the terminal and type the following command.
  • cd Downloads (if its in Downloads folder)
  • sudo tar xvfz drupal-7.21.tar.gz -C /opt/lampp/htdocs
Now the files will be extracted to /opt/lampp/htdocs under the folder name drupal-7.21. Lets refactor the name of the folder to drupal(to make it simple).

3.) Open your terminal and type the following command.
  • sudo mv /opt/lampp/htdocs/drupal-7.21 /opt/lampp/htdocs/drupal
Test Drupal:
Now lets test Drupal whether its installed properly or not.

1.) Open your browser.
2.) Type the following url : http://localhost/drupal

You should see this page:



Create a database now:
Now in this section we are going to create a database to save our data:

1.) Open your browser.
2.) Type the following url: http://localhost/phpmyadmin
3.) Click on databases section and type your database name (my db name is drupaldb) and then click Create Database button.
4.) Go to privileges and create a new user for this newly created database. Remember the username and password.

Configuring Drupal:

After installing Drupal and creating a database, now we can go ahead and configure Drupal.

1.) Click the Install in English language button.
2.) You will likely encounter with this page.



3.) If you encounter with any errors then Open your terminal and type the following command. Here we are just making a copy og default.setting.php and renamed it to settings.php
  • sudo cp /opt/lampp/htdocs/drupal/sites/default/default.settings.php /opt/lampp/htdocs/drupal/sites/default/settings.php
4.) Now we need to grant permissions to settings.php so that it's writable.
5.) Open your terminal and type the following command.
  • cd /opt/lampp/htdocs/drupal/sites
  • sudo chmod a+w default
  • sudo chmod a+w default/settings.php
6.) Finally we need to increase our php memory limit size in php.ini. Open php.ini in your favourite editor. I chose vim.
  • sudo vim /opt/lampp/etc/php.ini
7.) Check for memory_limit parameter and if its already set to maximum of 128M then do not change it and if its set to 8 then change it to 16. Press esc and type :wq to save and exit. If you made any changes then restart your server once for the changes to be updated.

8.) That should have solved all the problems! Okay, now you should be able to see the Database configuration page in your browser:


9.) Notice that I have entered a name for my database, the same name I’d used earlier. Make sure you do the same. Once you clicked the Save and continue button on the Set up database page, you will be directed to the Configure site page, like the picture below:


10.) For security purposes, it tells you to remove write permissions to the settings.php file. Let’s do that: Type the following command in your terminal.
  • sudo chmod a-w /opt/lampp/htdocs/drupal/sites/default/settings.php
11.) Finally! You are now ready to enter some important informations for your new web site. Fill out the the required information for the Site information and Administration account sections. Make sure you remember the username and password you’ve entered!


12.) Once all the informations are filled out, click the Save and continue button. Voila! Give yourself a pat on the back! You have just completed installing Drupal on your computer!


13.) Now when you saved and continued you will presented with the home screen of your website.

NOTE: This will be saved in your localhost and once you think that its perfect then you can host your website live.

That's all for today folks hope this blog helps. Cheers!










Tuesday 26 February 2013

PHP Web Page Scraping in Codeigniter


Hey there guys and welcome to my another interesting blog! Interesting because today I am going to show you how to scrape contents from a web page. 

First of all we need to understand what is Web page scraping. 

Web Scraping is a technique of extracting information from the websites using specially coded programs!

There are 3 ways to access a website data. One is through web browser, other is using an API(if the site provides one) and the last one is known as Web Scraping, which is what I am going to show you today!

Before starting with scraping we need to download one cool library which is available for free from SourceForge

This writing shows a simple scraper using the simplehtmldom library. But before we continue we need to be careful that if a website does not provide any RSS feed or an API to extract information from their web pages then their website is probably copyright protected and grabbing information from a site and use it somewhere else may well be a violation of someone's rights and eventually may land you in trouble! So keep this in mind.

Lets get started,

INSTALLING simplehtmldom IN CODEIGNITER:

After downloading your library from SourceForge unzip the library and copy simple_html_dom.php file into your library folder present inside your application folder.

And as you may know this you need to open your autoload.php file from config folder and add the following line

$autoload['libraries'] = array('simple_html_dom');

Save it and close. That's it you have successfully loaded your library to your application! Now lets create a controller file in the next step.

CREATING A SCRAPING CONTROLLER:

Copy paste this code into your php class file and save it.

class Scraper extends CI_Controller
{
    public function __construct()
    {
        parent::__construct();
    }
   
    public function get_html_dom()
    {
        $url = "http://play.google.com/";
        $html = file_get_html($url);
        $data =  $html->find('.top-list-container');
       
        if(isset($data[0]))
        {
            echo $data[0]->children(1)->children(1);
        }
    }
}


Lets go through the method now.

If you take a look then you will probably come to know that I am scraping content from Google Play Store!! :P

The id and class selectors may change in the future when Google will change their page templates or make any changes to their selectors so you need to make changes in your program too!

The function  file_get_html( )  is a function of the simple_html_dom.php class to which I am passing in the play store url. 

Now we need to traverse the DOM using find( ) function as shown above. I am finding 
class = top-list-container from the html page and then I am echoing out the child tag inside the container! Refresh your browser you will see how the library fetches the contents from the web page! 

This is a simple example you can even use foreach loop to loop through more than one conatiners inside the html page and so on! 

Hope you people like this blog! Thank you see you next time.


Saturday 23 February 2013

How to install JDK, LAMPP server and Netbeans IDE(UBUNTU 12.04)

Installing OpenJDK:

Hey there again every one! Today I am going to show you how to set up the LAMPP server(XAMPP) on your Ubuntu 12.04.

Lets start with installing JDK(OpenJDK). The steps are as follows:

1) Open the terminal and key in the following commands:

$ sudo apt-get install openjdk-7-jre   // wait until the process downloads and installs the jre.

$ sudo apt-get install openjdk-7-jdk  // again wait until the process downloads and installs the jdk.

That's it this should install your jdk!

2)In case if you want to remove the installed jdk then key in this command in your terminal

$ sudo apt-get remove openjdk-7-jdk openjdk-7-jre

That's it this should uninstall your openjdk!

 

Installing Netbeans IDE:

To install the IDE first of all you need to download the latest IDE from Netbeans website.

After downloading key in the following command in your terminal

$ sudo bash filename 

My filename here was netbeans-7.2.1-ml-linux.sh and click enter and thats it! Your IDE should be installed through a netbeans wizard!

 

Installing XAMPP server:

To install xampp you need to be sure to have a tar.gz downloaded before and place them in Downloads folder and if so then use this following commands

$ cd Downloads  // go into the downloads folder

~/Downloads $ sudo tar xvfz xampp-linux-1.8.1.tar.gz -C /opt

This should extract the lampp folders into the /opt folder. you can choose your own folder to extract as well.

Now start your xampp server using

$ sudo /opt/lampp/lampp start

Sometimes we need vim editor to make changes to the files. So we need to install it. Use,

$ sudo apt-get install vim

This will install the vim editor.

Now point your browser to http://localhost and click enter. You will see your XAMPP start up page. Choose your language and click on phpmyadmin on the left panel. You will get Access Forbidden Error Page. This is because we have not granted permissions to the user. To make changes open httpd-xampp.conf file from /opt/lampp/etc/extra/ path like below,

$ vim /opt/lampp/etc/extra/httpd-xampp.conf

If at all if you get permissions error then change permissions using the following command,

$ sudo chmod -R 777 /opt/lampp/etc/extra/httpd-xampp.conf

Now again run the previous command to make changes to your file and then search for the following 

<Directory "/opt/lampp/phpmyadmin"> and add this line 

Require all granted

</Directory>

and save it. To save press esc key then :wq and then enter.

After this restart your server to do this use this command

$ sudo /opt/lampp/lampp restart

now refresh your page in the browser you will be displayed with the phpmyadmin page.

NOTE: One more important thing is that when people cannot create their project inside htdocs folder in Ubuntu. This is because the directory in which the project is created does not have permission to be created. So you need to use the following command

$ sudo chmod -R 777 /opt/lampp/htdocs

Now you can create your project in htdocs folder!

That's it for today! hope you like this blog on configuring your lampp server on ubuntu 12.04!