Wednesday, June 29, 2011

APACHE SERVER AND PHP, POST INSTALLATION PROBLEMS

PHP POST INSTALLATION PROBLEMS

1. Cannot parse PHP files.
I’m still not able to parse PHP files when I attempt to open them in a browser, I get the option to download them instead. I’ve tried several steps and nothing works.

Solution:
Perform the following tasks
sudo apt-get install libapache2-mod-php5
sudo a2enmod php5

Then re-start Apache:
sudo /etc/init.d/apache2 restart

2. No write permission.
I get the “it worked message”. So everything install semi correctly at least. However, when I try to copy or save files in the /var/www/ folder, I can't. Any ideas?

Solution:
Terminal:
sudo chown USERNAME /var/www/

3. Could not connect to MYSQL server. Here is the PHP code

$host = 'localhost';
$user = 'root';
$pass = 'mypassword';
$database = 'mysql';

mysql_connect($host,$user,$pass);
@mysql_select_db($database) or die( "Unable to select database");

Solution:
Change the value of $host variable from 'localhost' to '127.0.0.1'

4. When I am trying to access a php files below the root folder through my localhost and Apache is giving me a 403 error.

Forbidden
You don't have permission to access /distribution/sample-html-simple.php on this server.

Apache/2.2.16 (Ubuntu) Server at localhost Port 80

Solution:
Make sure folder is accessible to www-data, on the terminal type the command:
sudo chown -R www-data "/var/www/distribution"

Tuesday, June 14, 2011

UBUNTU DESKTOP 10.10 WORKS GREAT WITH EPSON STYLUS TX121 (Scanner, Printer, Copier)

Epson Stylus TX121 Multifunction printer is a 3 in 1 device that is capable of scanning images, printing documents and photocopying. I bought this in the market last January of 2011. It's plug and play device prints text and graphics very well in Ubuntu 10.10 desktop. Although the printed output of this printer looks great, it is not fully supported because the scanning feature does not function. In Ubuntu 10.10 there's no driver that matches this model. The OS recommended other driver when you install the device. The recommended package works well for printing only but for scanning does not because the scanning software cannot recognize the source device. After goggling the internet to find out if there's already a driver ready for download. Yes there is and you can download from AVASYS website. Look for the following files from this website and download them.
  1. iscan-data_1.8.1-1_all.deb
  2. iscan_2.26.3-1.ltdl7_i386.deb
  3. epson-inkjet-printer-n10-nx127_1.0.0-1lsb3.2_i386.deb

Follow the order of installation:

Dependencies first
iscan-data_1.8.1-1_all.deb
iscan_2.26.3-1.ltdl7_i386.deb

Core package next
epson-inkjet-printer-n10-nx127_1.0.0-1lsb3.2_i386.deb

This device driver also supports other printer models such as Epson ME 320/330, Epson Stylus NX125/NX127/SX125/TX120/TX123/TX125/TX129

When done TX121 is ready to rock and roll.


Tuesday, May 24, 2011

MYSQL TUTORIAL

This tutorial is intended for Ubuntu Power Users and Programmers

I. Theoritical Background

What is Database?

A database is a separate application that stores a collection of data. Each database has one or more distinct APIs for creating, accessing, managing, searching, and replicating the data it holds.

Other kinds of data stores can be used, such as files on the file system or large hash tables in memory but data fetching and writing would not be so fast and easy with those type of systems.

So now a days we use relational database management systems (RDBMS) to store and manager huge volume of data. This is called relational database because all the data is stored into different tables and relations are established using primary keys or other keys known as foreign keys.

A Relational DataBase Management System (RDBMS) is a software that:

  • Enables you to implement a database with tables, columns, and indexes.

  • Guarantees the Referential Integrity between rows of various tables.

  • Updates the indexes automatically.

  • Interprets an SQL query and combines information from various tables.

RDBMS Terminology:

Before we proceed to explain MySQL database system, lets revise few definitions related to database.

  • Database: A database is a collection of tables, with related data.

  • Table: A table is a matrix with data. A table in a database looks like a simple spreadsheet.

  • Column: One column (data element) contains data of one and the same kind, for example the column postcode.

  • Row: A row (= tuple, entry or record) is a group of related data, for example the data of one subscription.

  • Redundancy: Storing data twice, redundantly to make the system faster.

  • Primary Key: A primary key is unique. A key value can not occur twice in one table. With a key you can find at most one row.

  • Foreign Key: A foreign key is the linking pin between two tables.

  • Compound Key: A compound key (composite key) is a key that consists of multiple columns, because one column is not sufficiently unique.

  • Index: An index in a database resembles an index at the back of a book.

  • Referential Integrity: Referential Integrity makes sure that a foreign key value always points to an existing row.

MySQL Database:

MySQL is a fast, lightweight, easy-to-use RDBMS being used by many small and big businesses. MySQL is developed, marketed, and supported by MySQL AB, which is a Swedish company. MySQL is so popular because of many good reasons.

  • MySQL is released under an open-source license and it's free so you have nothing to pay to use it.

  • MySQL is a very powerful program in its own right. It handles a large subset of the functionality of the most expensive and powerful database packages.

  • MySQL uses a standard form of the well-known SQL data language.

  • MySQL works well on many operating systems and with many languages including PHP, PERL, C, C++, JAVA, Microsoft .NET languages, etc.

  • MySQL works very quickly and works well even with large data sets.

  • MySQL is very friendly to PHP, the most appreciated language for web development.

  • MySQL supports large databases, up to 50 million rows or more in a table. The default file size limit for a table is 4GB, but you can increase this (if your operating system can handle it) to a theoretical limit of 8 million terabytes (TB).

  • MySQL is customizable. The open source GPL license allows programmers to modify the MySQL software to fit their own specific environments.

MySQL Packages:
  • MySQL - The MySQL database server, which manages databases and tables, controls user access, and processes SQL queries.

  • MySQL-client - MySQL client programs, which makes it possible to connect to, and interact with, the server.

  • MySQL-devel - Libraries and header files that come in handy when compiling other programs that use MySQL.

  • MySQL-shared - Shared libraries for the MySQL client

  • MySQL-bench - Benchmark and performance testing tools for the MySQL database server.


II. The Tutorial

Installation Steps : MySQL server and client packages: 

The first thing to do is install the server and client packages. Open the terminal and type the following line.

sudo apt-get install mysql-server mysql-client

When you're done, you have a MySQL database ready to use. However, there’s more to do. Now, you probably don’t want just the MySQL Server. Most likely you have Apache and PHP already installed, and want MySQL to go with that. You need to install support library to make MySQL available to PHP:

sudo apt-get install php5-mysql

Or for Ruby:

sudo apt-get install libmysql-ruby

Post-Installation Steps:

MySQL ships with a blank password for the root MySQL user. You need to set a root password, for starters. MySQL has it’s own user accounts, which are not related to the user accounts on your Linux machine. By default, the root account of the MySQL Server is empty. You need to set it. Please replace ‘mypassword’ with your actual password and myhostname with your actual hostname.

sudo mysqladmin -u root -h localhost password 'mypassword'
sudo mysqladmin -u root -h myhostname password 'mypassword'

Connecting to a MYSQL server using the mysql command

To connect to the MySQL server on the local system, issue the following command:

mysql -u username -p
Enter password:

Where username is the name of a user authorized to use the database (see Create a MySQL user account). The -p option will prompt for the user’s password as shown below the command.

If the MySQL server resides on a remote host, the mysql command, if present on the local system, can be used to connect to the MySQL server accross the network. To connect to a MySQL server on a host named ‘elephant’ use the following command:

mysql -h elephant -u username -p

Typical output screen when succesfully connected:

genes@genesServer:~$ mysql -u genes -p

Enter password:

Welcome to the MySQL monitor. Commands end with ; or \g.

Your MySQL connection id is 37

Server version: 5.1.49-1ubuntu8.1 (Ubuntu)

Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved.

This software comes with ABSOLUTELY NO WARRANTY. This is free software,

and you are welcome to modify and redistribute it under the GPL v2 license

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.


It should be rewarded with a mysql> prompt. Now you are connected to the MySQL server and you can execute all the SQL command at mysql> prompt as follows.

mysql> SHOW DATABASES;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
+--------------------+
2 rows in set (0.00 sec)

Create Database using mysqladmin:

You would need special privilege to create or to delete a MySQL database. So assuming you have access to root user, you can create any database using mysql mysqladmin binary.

Example:

Here is a simple example to create database called PAYROLL:

genes@genesServer:~$ mysqladmin -u root -p create PAYROLL
Enter password:

This will create a MySQL database PAYROLL.

Once you get connection with MySQL server, it is required to select a particular database to work with. This is because there may be more than one database available with MySQL Server.

Setting Up a MySQL User Accounts:

For adding a new user to MySQL you just need to add a new entry to user table in database mysql.

Below is an example of adding new user genesacenassr with SELECT, INSERT and UPDATE privileges with the password dragonfly the SQL query is :

genes@genesServer:~$ mysql -u root -p
Enter password:
mysql> use mysql;
Database changed

mysql> INSERT INTO user
(host, user, password,
select_priv, insert_priv, update_priv)
VALUES ('localhost', 'genesacenassr',
PASSWORD('dragonfly'), 'Y', 'Y', 'Y');
Query OK, 1 row affected (0.20 sec)

mysql> FLUSH PRIVILEGES;
Query OK, 1 row affected (0.01 sec)

mysql> SELECT host, user, password FROM user WHERE user = 'genesacenassr';
+-----------+--------------+------------------+
| host | user | password |
+-----------+--------------+------------------+
| localhost | genesacenassr| 6f8c114b58f2ce9e |
+-----------+--------------+------------------+
1 row in set (0.00 sec)
   

When adding a new user remember to encrypt the new password using PASSWORD() function provided by MySQL. As you can see in the above example the password mypass is encrypted to 6f8c114b58f2ce9e.

Notice the FLUSH PRIVILEGES statement. This tells the server to reload the grant tables. If you don't use it then you won't be able to connect to mysql using the new user account at least until the server is rebooted.

You can also specify other privileges to a new user by setting the values of following columns in user table to 'Y' when executing the INSERT query or you can update them later using UPDATE query.

  • Select_priv

  • Insert_priv

  • Update_priv

  • Delete_priv

  • Create_priv

  • Drop_priv

  • Reload_priv

  • Shutdown_priv

  • Process_priv

  • File_priv

  • Grant_priv

  • References_priv

  • Index_priv

  • Alter_priv

Another way of adding user account is by using GRANT SQL command; Following example will add user genesacenassr with password dragonfly for a particular database called PAYROLL.

genes@genesServer:~$ mysql -u root -p
Enter password:
mysql> use mysql;
Database changed

mysql> GRANT SELECT,INSERT,UPDATE,DELETE,CREATE,DROP
-> ON PAYROLL.*
-> TO 'genesacenassr'@'localhost'
-> IDENTIFIED BY 'dragonfly';

This will also create an entry in mysql database table called user.

NOTE: MySQL does not terminate a command until you give a semi colon (;) at the end of SQL command.

Selecting MySQL Database from Command Prompt:

This is very simple to select a particular database from mysql> prompt. You can use SQL command use to select a particular database.

Example:

Here is an example to select database called PAYROLL:

genes@genesServer:~$ mysql -u root -p
Enter password:
mysql> use PAYROLL;
Database changed
mysql>

Now you have selected PAYROLL database and all the subsequent operations will be performed on PAYROLL database.Create MySQL Tables

The table creation command requires:

  • Name of the table

  • Names of fields

  • Definitions for each field

Syntax:

Here is generic SQL syntax to create a MySQL table:

CREATE TABLE table_name (column_name column_type);

Now we will create following table in PAYROLL database.

employee_tbl(
empid INT NOT NULL AUTO_INCREMENT,
empname VARCHAR(100) NOT NULL,
empaddress VARCHAR(100) NOT NULL,
employment_date DATE,
PRIMARY KEY ( empid )
);

Here few items need explanation:

  • Field Attribute NOT NULL is being used because we do not want this field to be NULL. SO if user will try to create a record with NULL value then MySQL will raise an error.

  • Field Attribute AUTO_INCREMENT tells to MySQL to go ahead and add the next available number to the id field.

  • Keyword PRIMARY KEY is used to define a column as primary key. You can use multiple columns separated by comma to define a primary key.

Creating Tables from Command Prompt:

This is easy to create a MySQL table from mysql> prompt. You will use SQL command CREATE TABLE to create a table.

Example:

Here is an example which creates employee_tbl:

genes@genesServer:~$ mysql -u root -p
Enter password:
mysql> use PAYROLL;
Database changed
mysql> CREATE TABLE employee_tbl(
-> empid INT NOT NULL AUTO_INCREMENT,
-> empname VARCHAR(100) NOT NULL,
-> empaddress VARCHAR(100) NOT NULL,
-> employment_date DATE,
-> PRIMARY KEY ( empid )
-> );
Query OK, 0 rows affected (0.16 sec)
mysql>



Sunday, March 9, 2008

Burn video cd out of your favorite Youtube videos

Many of my clients were asking if it's possible to burn a vcd out of their favorite movie clips from Youtube. The answer is yes but there is no direct method of doing that. As far as I know in order to burn Youtube video it must be downloaded first into your local hard drive for it is stored somewhere in the internet. With regards to formats, videos are formatted in different ways, Youtube videos are encoded as FLV, you should convert it first to a video format that is acceptable before burning. Different tools are used to download video off the internet, one of them is DownloadHelper, a Firefox media download extension.

DownloadHelper is a tool for web content extraction. Its purpose is to capture video and image files from many sites. Just surf the Web as you are used to, when DownloadHelper detects it can do something for you, the icon gets animated and a menu allows you to download files by simply clicking an item.

If this extension is not currently installed in your browser you can download and install it by clicking on tools, addon, extensions, Get Extensions.

Next is convert the downloaded video into a videocd format prior to burning. Linux is very rich in multimedia applications contrary to the belief that it is limited in this area. I use ffmpeg, an open source command line audio/video editing tool, released under GPL license. If you are familiar with command line statements in Linux to let the computer to do a task, that's fine. Here's how you can convert flv file into mpg format.

ffmpeg -i mymovie.flv -target ntsc-vcd -sameq mymovie.mpg

Next is burn your favorite video to cd using burner available in Linux. I used K3b a cd/dvd burner




Saturday, March 8, 2008

EPSON LX300+ printer works well with the Generic-IBM-Compatible_Dot_Matrix_Printer driver in your Kubuntu Desktop.

One of the most troublesome activities I encountered in fine tuning my Linux Desktop is finding the correct driver for my printer. My printer is Epson LX300+ and it is not currently fully supported by Ubuntu or Kubuntu. In short there is no entry for driver for this model in the printer database. I tried several other drivers for my dot matrix printer that are available in my Linux box. But the result was not very impressive and quite frustrating. I did not lost hope and keep on googling the net for weeks until I found one that closely matches my printer. I share this success of mine because I know there are people out there who are still struggling with the same problem I've met before. Sharing ideas with the open source community members in solving different problems that we've met I think is what makes Linux very interesting. Download this driver Generic-IBM-Compatible_Dot_Matrix_Printer-ibmpro.ppd from the internet by simply clicking this link www.linuxprinting.

Once the webpage is completely loaded in your browser follow the instructions for downloading the printer driver:
1. Click Drivers
2. Click ibmpro
3. Select Generic IBM-Compatible Dot Matrix Printer from the combo box
4. Select download radio button
5. Click Generate PPD file
6. Click Save File to save driver to your desktop

In installing the printer driver in your Linux box, just follow the instructions found in your distribution. For me I'm using Kubuntu 7.10, and it's quite easy and no hazzles. Here is the steps.
1. Click System Settings
2. Click Add Printer/Class
3. Click Next
4. Click Local printer, if you are connecting the printer in your local printer port.
5. Click Next
6. Click Other to select the saved ppd file from your hard drive.
7. Keep on navigating until the computer will ask for the name of your printer.
8. Then name the newly added printer, give its short description by typing in their assigned text boxes, then click Next, and click Finish button.

Genes M. Acenas Sr
Software Developer
Bato, Leyte
Philippines

Friday, March 7, 2008

I switched from Microsoft Windows to GNU Linux/FOSS not because it's free but because of "Freedom" around it.

I did several accounting software projects in our area using a pirated copy of Microsoft Visual Basic IDE. The last project I had was a database system (Student Records Management, Enrollment and Billing System) of the Bato Institute of Science and Technology (BIST) of Bato Leyte Philippines. I really felt it was an awesome and a successful project and I am very proud of it because until today the system is still in used by the company and the management of that company did not make any contact with me anymore asking favors for maintenance and upgrades. I am very happy to tell my friends for such a great job but truly inside me is a feeling of emptiness because I did it with the use of illegally acquired software. I really love Microsoft Visual Basic and Microsoft Office family of softwares because of their nice, user-friendly and easy to use capabilities and in fact Microsoft Visual Basic was my number one tool in developing customized applications and it's also my number subject when I used to teach computer programming in colleges and universities. But the world of computing in me using Windows has changed and came to an end by the time I received a letter from the office of NBI, CIDG, OMB Manila in compliance with the Republic Act 8293 (Intellectual Property Code in the Philippines) sometime in November 2007. I heard of GNU Linux long before but I did not pay too much attention to it because I thought Microsoft line of software products were the world's best and all the people in our community know nothing except Windows, until I received a compaign letter regarding software piracy from the authorities of the Philippine government. That happening, I consider it as an eye-opener experience for me because I never had a plan to use Linux then. Software piracy is very rampant in our area and it's against my conscience to continue to use illegally copied softwares. I searched in the internet regarding the open source technology and its implications and viability in business and I found a lot of good feedbacks and success stories from the communities who supported and keep the spirit and ideals of open source burning. So I never hesitated to gave Linux a chance. At first I tried Ubuntu, Mandriva, Linux Mint, Fedora 7 and many other distros and finally settled for Kubuntu Gutsy Gibon. And right now all PCs on my internet cafe are powered and run by 100% open source softwares. I used Kubuntu 7.10 for my desktops, OpenOffice for documents processing, Kino for video editing, K3b and Amarok for cd audio/video ripping and burning, Gimp and Inkspace for graphics editing and Audacity for my audio manipulation. With software development I use Netbeans, Gambas, KDevelop and Eclipse. I wish to expand my internet cafe business in the years to come with Edubuntu. Because of security features, flexibility, lower total cost of ownership and maintenance and most of all the "Freedom" that I've found and experienced within GNU Linux environment, I would encourage everybody to consider using this alternative platform. By now I can have a sound sleep at night and more productive in my business operation. At least today the day has come that everyone can exercise his freedom to express, use, modify, distribute, and participate in the developments for the benefits of mankind.

Genes M. Acenas Sr.
Software Developer
Bato, Leyte
Philippines