Showing posts with label install. Show all posts
Showing posts with label install. Show all posts

Sunday, August 7, 2011

Installing PDO on Ubuntu

Requirements for this post:

Installed php 5.1+ engine, apache2 web server
installed Netbeans 7 or 6.9
Installed MySQL and MySQL WB.

If you havent already installed this visit my older posts and install whats missing.

So in this post I will explain what is PDO and how can be installed on Ubuntu/Windows.

PDO stands for PHP Data Objects. It is PECL extension for PHP 5.0 and ships with PHP 5.1 and newer versions of PHP. It is dependent on OO features of PHP so it will not work in older PHP versions.

It is data-access abstraction layer  which means that you can use same function for access and manipulation of db data no mather what type of db is behind. So depending on the type of the db behind, you use special PDO driver for that database.  Here is the official PDO docs PDO .

PDO is not dependent of other libraries and extensions so if you have PHP 5.0+ you are ready to go and install.

PDO is a PECL extension so you will need this package in order to install pdo php5-dev.

Open terminal and run this command:

$sudo apt-get install php5-dev

 No we will install PDO.

The easiest way to install on Ubuntu is to use these commands:

$ sudo apt-get install libmysqlclient15-dev
$ sudo pecl install pdo
$ sudo pecl install pdo_mysql
 
 I have PHP 5.3 so no need to edit the php.ini file. If you have other version 
you should edit the php.ini file and add these lines 
 
extension=pdo.so
extension=pdo_mysql.so
 
On PHP 5.3 php.ini is place in the /etc/php5/apache2 folder. 
On other PHP versions it should be in /etc/php5/cgi/php.ini or /etc/php/cli/php.ini.
 
So no open terminal and run this command 
 
$ sudo gedit /path/to/php.ini 
 
mine was 
 
$sudo gedit /etc/php5/apache2/php.ini
 
It will open text file. Find the Dynamic extensions section and add the lines
 
extension=pdo.so
extension=pdo_mysql.so 
 
Now save the file and close it. In terminal run 
 
$ sudo /etc/init.d/apache2 restart 
 
to restart the web server.   Now I will create a test project in Netbeans to test 
the installtion of PDO. 
In previous post I created new PHP project called HelloWorldPHP. If you haven't 
I will explain it again here. 
Open Netbeans and click file->new project. Choose new PHP application 
and click next. Add the name of the project HelloWorldPHP and place it in the 
sources folder /var/www/HelloWorldPHP. Click finish. This will open new 
project in the projects panel. 
 
Now, click right click on the  HelloWorldPHP node and click 
set as main project. Open the sources folder and double click the index.php file
It will open in the editor window. Now you will see a php segment 
 
<?php ?>
 
Add this line of code phpinfo(); 
 
Your page will look like 
 
<?php phpinfo(); ?>
 
 
Now open a browser and type this url: http://localhost/HelloWorldPHP/ 
or click run->run main project in Netbeans. You  should get the php info 
page with all settings. Now far below on the page you have to find PDO 
section and pdo_mysql section. If this is the case than you installed it succesfully. 
Otherwise check what's wrong and post a question. 
 
In the next post i will add some on installing PDO on Windows.

Friday, July 29, 2011

Installing Sakila sample database

Ok, so in this post I will show you how to install Sakila sample database on our MySQL server by using Netbeans IDE. So make sure you install Netbeans and all other necessary software for this to work. You might wanna visit Installing Netbeans or LAMP Installation .

Ok so now open Netbeans 7 or other version if you have and got to tools->plugins .

Now new window opens. In the Available plugins tab find and select "sakila sample database". Cliks Install. Accept the terms of agreement and click next.

The sample database installs. Ok so now open the services tab in the left panel where Projects and files tabs reside. Click the databases tree. You will see sub tree called " MySQL Server as localhost:3306[root] ". Right click on the entry and click create database. In the dropdown list select Sample database sakila. It will ask you whether you want to install the sample database on MySQL. Click yes.

Wait a moment and the database is installed with its own data.

Now open MySQL workbench and double click on the mysql connection. New window opens. You should see the Sakila database in the left panel. Thats it. I will use this sample database to explain some advances topics of php and how to manipulate data on MySQL server.

You might wanna visit Sakila on Netbeans .

Quick description of the Sakila database:

It is successor of a previous sample database called World. So it is improved and enriched. It has several tables,views , triggers and stored procedures in order to begin learning advanced work with databases.

Monday, July 18, 2011

Installing Netbeans 7 and JDK on Ubuntu

So we installed the needed software now we need a comprehensive IDE editor for developing php applications. I use Netbeans because it has support for PHP. 

You can also use Eclipse as an alternative by installing PHP plug-in. You can also use the adapted to PHP Eclipse version called Aptana. It has predefined PHP plug-in and also debuger. You can get it at this page aptana studio

Now before we install Netbeans or Eclipse we need jdk preinstalled on Ubuntu. jdk stands for Java Development Kit and is the needed environment for Netbeans/Eclipse since they are developed as Java applications.

So now go to this page java downloads. Since we are installing on Ubuntu download the second option with no RPM in it. The package with RPM is for Fedora and RedHat Linux distributions. You will download a bin file.

After the download run terminal and browse to the downloads folder of your system where you downloaded the bin file. 
Next, type this command:

$ chmod a+x jre-6u-linux-i586.bin

Now replace the with the version of the jdk you downloaded. This will make the file executable since it wasn't. If you get any error you also use this command:

$ chmod 777 jre-6u-linux-i586.bin

Now run this command

sudo ./jre-6u-linux-i586.bin

This will now install java development kit on your computer. After this finishes we are ready to install netbeans.

Note: Eclipse is a java base application it doesn't need to be installed like netbeans. Just download extract and you are ready to use it without installation.  You might wanna visit this page for eclipse eclipse downloads. Now it is preety much handy to create a shortcut to you desktop and also create menu item in you system menu(In other post).

Now we will install Netbeans 7.0 . Go to this page netbeans downloads and download the package that has dot in the php row. This package has preinstalled plug-ins for php, zend framework and also other stuff. No you will get an *.sh file. When download finishes open terminal and go to the downloads folder.

Run this command:

$ sudo chmod +x name_of_netbeans_file.sh

This will make it executable file. Now run this command 

$ sudo ./name_of_netbeans_file.sh

This will now install Netbeans on your system.

Note: For windows systems choose the windows option and download and install the ms installer for netbeans.

Wait a while and after the install is finished got to the system menu -> programming -> Netbeans IDE 7.0 This will start the IDE. We will create an empty test project with these commands:

File->New Project ->PHP Application.

In the Name and Location dialogue window place the name of project "HelloWorldPHP" and in the sources folder there must be /var/www/ in from of the HelloWorldPHP, so your location would be /var/www/HelloWorldPHP. In the next steps leave all fields default and click finsih.

That's it you created your first PHP application in the Netbeans IDE.

Before you work on this post see first ubuntu installation

Saturday, July 16, 2011

Installing MongoDB

I use MongoDB on Ubuntu but you can also use it on Windows. I will explain how to install it on Ubuntu.

I installed myselft with oppening terminal and typing:

$ sudo apt-get install mongodb

Wait a moment and it will be installed. There is an option to build it from binary sources but this is much more complex (In other post).

Next, you must create directories for the db so open terminal and type in these commands:

$ sudo mkdir -p /data/db/
$ sudo chown `id -u` /data/db 
 
This creates folder data/db at root level and change owner to root. 
Now you should be able to use MongoDB. Start the server by typing in terminal:
 
$ sudo start mongodb  or this $ service mongodb start. You will get a message 
whether the service is started. If it is started than go to this folder /bin and type  
mongo in terminal i.e
 
$ cd /bin
$ mongo    you will get the ">" char in terminal so it means it works.
For start type in 
 
> use mydb 
> db.testcol.save({json : "this is a json object"});
> db.testcol.find();
You should get something like this as output:
{ "_id" : ObjectId("4c2209f9f3924d31102bd84a"), "json" : "this is a json object" }
 
With these commands we use the database called mydb and than create a collection 
(table) called testcol and save one BSON document (row)  
{json : "this is a json object"}. The find command prints all document in the collection  
testcol. You should visit the SQL to Mongo Mapping page at SQL-Mongo
 
You can notice that we use json notation to create documents (rows) in the database, 
Mongo works its way i.e it constantly converts from json to bson and vice verse. 
 
I will add some examples on how to work with Mongo so make sure you read well 
about json.  
 
 You might wanna visit the downloads page @ downloads
Select you operating system version and download it.  Also visit Quickstart