Ubuntu reset mysql password

  • Stop the mysql demon process using this command :
    •    sudo /etc/init.d/mysql stop
  • Start the mysqld demon process using the –skip-grant-tables option with this command
    • sudo /usr/sbin/mysqld --skip-grant-tables 
      --skip-networking &

Because you are not checking user privs at this point, it’s safest to disable networking. In Dapper, /usr/bin/mysgld… did not work. However, mysqld --skip-grant-tables did.

  • start the mysql client process using this command
    •    mysql -u root
  • from the mysql prompt execute this command to be able to change any password
    •    FLUSH PRIVILEGES;
  • Then reset/update your password
    •    SET PASSWORD FOR root@'localhost' = PASSWORD('password');
  • If you have a mysql root account that can connect from everywhere, you should also do:
    • UPDATE mysql.user SET Password=PASSWORD('newpwd') 
      WHERE User='root';
  • Alternate Method:
    •    USE mysql
         UPDATE user SET Password = PASSWORD('newpwd')
         WHERE Host = 'localhost' AND User = 'root';
  • And if you have a root account that can access from everywhere:
    •    USE mysql
         UPDATE user SET Password = PASSWORD('newpwd')
         WHERE Host = '%' AND User = 'root';

Ubuntu Advanced file permissions in 10 minutes

At a Glance

 

→In Ubuntu / Linux 9 bit file/directory permissions are used as follows:

4 = Read, 2 = Write, 1 = Execute

When we create a new file or directory the default permissions is determined by Linux from a variable umask. You can find the current umask value by : $ umask

and add new umask as : umask 022

The new file or directory created by the user will get ( 777 – umask permission) REGARDLESS of parent directory permissions. So a umask of 022 will allow for permission of 755 which is most common.

→The three most important commands dealing with files and directory permissions are chmod, chgrp and chown.

→The most strange permission is for directory because it needs x permission always with both a read and write permissions enabled. A common sense says write permission on directory means you can write in that director but it won’t unless you grant the x permission as well. So in short on a directory with permissions:

w : cannot do anything

r: cannot do anything

rx: can read the contents of directory means can list (ls ) files.

wx: can add new files but cannot list them.

rwx: can add and list files.

→ You cannot cd to a path if you have no read permission to any of the sub-directory. (Contrary to MS Windows )

A Scenario

→Lets say we want to make a directory called ‘base’ and want several users (the world) on the system to be able to (1) add their own contents to this directory. (2)They can READ contents of others but (3) must not DELETE them.

$ mkdir base                (by root)

$chmod 777 base        (this enables every one to read and write to this dir, but its parent directory must have 755 permission so that the users would not be able to delete this ‘base’ directory altogether.)

Problem: Now since everyone has read, write permissions user1 is able to delete user2 file.

Solution: We need to sit the sticky bit on the base folder. The sticky bit will prevent users to delete the files not owned by them even if they have full permissions on base directory.

$chmod 1777 base

 

Sticky bit: If a user has write permission on a directory he can rename and remove files on that directory even if those files not belong to him. How can we prevent this? The owner of a directory can set the directory’s “sticky bit”, octal value 1000, which will give the rename and remove permissions of any file in that directory to the file owner, the directory owner, and the superuser (in this order).

SETUID: The bits with octal value 4000 are the setuid  bits. When you are executing a program with the setuid bit set you are granted with the owners permissions to this program until you are finished with it. $chmod 4755 or chmod u+s

SETGID: The bits with octal value 2000 are the setgid  bits. When you are executing a program with the setgid bit set you are granted with the groups permissions to this program until you finish executing the program. $chmod 2755 or chmod g+s. When you set the setguid on a directory, any file created by any user inside this directory will inherit the group from the directory.

Change VSFTPD uploaded file permissions

When you upload files to a webserver (eg) and the username of the ftp client is different than webserver (apache) username the upload files are by default owned by the uploaded user of the ftp. Therefore apache may not be able to read the files.

It is difficult and time consuming to reset the permission manually by issuing a command like:
sudo chmod 755 -Rf images/

A quick way is to add the umask in /etc/vsftpd.conf as:
local_umask= 022 or 000

Another way around is to use the same username for both apache and ftp client.

How to save Swedish Characters in MySQL using PHP and display it on Web Page

How to save Swedish Characters in MySQL using PHP and display it on Web Page

It was a headache and wastage of time when I came across the situation when I saw strange Swedish characters on one of my clients web page and its MySQL database. After googling I found several suggestions but no one was clearer unless I experience my self and rectified the problem.

Basically there are three places that need to be handled to display Swedish characters correcly on a site that uses PHP and MySQL.

1. HTML Side 2. PHP Side 3. MySQL table structure

Lets talk about each of the above one by one.

1. HTML Side

You have to make sure that html encoding is set to UTF-8. In other words simply add the following to the head section of your html document. Please also make sure to save the webpage in utf-8 format by using notepad++ for example. To do it in notepad++ open the webpage in notepad++ and click menu Encoding-> Convert to utf-8 ( to troubleshoot just create a new document in notepad++ and copy your webpage to it and now click Encoding-> Convert to utf-8).

<meta http-equiv=”content-type” content=”text/html; charset=utf-8″ />

2. PHP Side

To save data to MySQL use PHP function utf8_encode. This mean if you want to save some data to MySQL say ‘åöä’ , you should assign it to a variable like this:

$tmp = utf8_encode(‘åöä’);

and now you can use $tmp in your update or insert MySQL Query.

3. MySQL table structure

The last step that you must do is to goto the table where you are supposed to save data that contains Swedish characters. Click structure of that table (in phpmyadmin) and click ‘change’ in front of the field that will save data with Swedish characters. Simple change the collation to utf8_swedish_ci

 

You are done.

PHP Frame Works

There are several frameworks in PHP. Recently I have the chance to work with Code Igniter and Symfony and therefore I searched the web to find some expert view and facts about these.

I found a nice comparison here:

 

 

 

Here is another nice overview about which framework to use:

 

How to save Swedish Characters in MySQL using PHP and display it on Web Page

It was a headache and wastage of time when I came across the situation when I saw strange Swedish characters on one of my clients web page and its MySQL database. After googling I found several suggestions but no one was clearer unless I experience my self and rectified the problem.

Basically there are three places that need to be handled to display Swedish characters correcly on a site that uses PHP and MySQL.

1. HTML Side 2. PHP Side 3. MySQL table structure

Lets talk about each of the above one by one.

1. HTML Side

You have to make sure that html encoding is set to UTF-8. In other words simply add the following to the head section of your html document. Please also make sure to save the webpage in utf-8 format by using notepad++ for example. To do it in notepad++ open the webpage in notepad++ and click menu Encoding-> Convert to utf-8 ( to troubleshoot just create a new document in notepad++ and copy your webpage to it and now click Encoding-> Convert to utf-8).

<meta http-equiv=”content-type” content=”text/html; charset=utf-8″ />

2. PHP Side

To save data to MySQL use PHP function utf8_encode. This mean if you want to save some data to MySQL say ‘åöä’ , you should assign it to a variable like this:

$tmp = utf8_encode(‘åöä’);

and now you can use $tmp in your update or insert MySQL Query.

3. MySQL table structure

The last step that you must do is to goto the table where you are supposed to save data that contains Swedish characters. Click structure of that table (in phpmyadmin) and click ‘change’ in front of the field that will save data with Swedish characters. Simple change the collation to utf8_swedish_ci

 

You are done.

How to provide per user configuration in vsftpd – ubuntu

user_config_dir
This powerful option allows the override of any config option
specified in the manual page, on a per-user basis. Usage is
simple, and is best illustrated with an example. If you set
user_config_dir to be /etc/vsftpd_user_conf and then log on as
the user “chris”, then vsftpd will apply the settings in the
file /etc/vsftpd_user_conf/chris for the duration of the
session. The format of this file is as detailed in this manual
page! PLEASE NOTE that not all settings are effective on a per-
user basis. For example, many settings only prior to the user’s
session being started. Examples of settings which will not
affect any behviour on a per-user basis include listen_address,
banner_file, max_per_ip, max_clients, xferlog_file, etc.

Default: (none)

How to restrict user to home directory with VSFTPD

There are options in /etc/vsftpd.conf to help make vsftpd more secure. For example users can be limited to their home directories by uncommenting:

chroot_local_user=YES

You can also limit a specific list of users to just their home directories:

chroot_list_enable=YES
chroot_list_file=/etc/vsftpd.chroot_list

After uncommenting the above options, create a /etc/vsftpd.chroot_list containing a list of users one per line. Then restart vsftpd:

sudo /etc/init.d/vsftpd restart

How to Enable CURL in WAMP?

How to Enable CURL in WAMP?

CURL is not enabled by default in WAMP. Every php programmer have to use CURL to make remote connection.

The steps are as follows :

1) Close WAMP (if running)
2) Navigate to WAMPbinphp(your version of php)
3) edit php.ini
4) Search for curl, uncomment extension=php_curl.dll
5) Navigate to WAMPbinApache(your version of apache)bin
6) edit php.ini
7) Search for curl, uncomment extension=php_curl.dll
8 ) Save both
9) Restart WAMP
10) Click the wamp icon in the system tray and goto php > php extensions and check php curl.

Install and configure Sphinx search on Ubuntu

Sphinx Installation and Configuration

A:- Install
1- Extract the tar ball (download from www.sphinxsearch.com)
2- ./configure –prefix /usr/local/sphinx
3- make
4- make install

B:- Configure
1- The initial sphinx.conf in etc in the above dir is ok, just change the db connection.

2- To remove the commented lines from the above conf file use ubuntu command grep as:
cat sphinx.conf | grep -v “[#]” > sphinx.conf.min
the v is used to inverse the match.

2.5 Import the sample DB by
mysql -uroot -proot test < /path_extracted_tar/example.sql

3- Install the service as:
searchd  –config sphinx.conf

4- Check status as
searchd –status

5- Start indexer
indexer –rotate –all

6- test by using search in bin/
search test

7- Test using SphinxQL
mysql –host=127.0.0.1 –port=9306
select * from test1 where match(‘test’);

8- Test with php API ( in extracted tar dir/api)

php test.php test

Difference between GET and POST

One important difference between GET and POST requests is that GET will enable you refresh the page without prompting the resend dialog box whereas the POST will show prompt each time you refresh the page to which you have previously posted some data.;)

Magento Login with Facebook

Step 1:

Get the extension key from http://www.magentocommerce.com/magento-connect/facebookfreebelvg-4448.html

Now in Magento admin goto Configuration->Magento Connect -> Magento connect manager to install the extension.

 

Step 2:

Get the facebook API id and secret the proceed as follows.

Once you obtain two keys navigate to Magento Administration, copy/paste them to appropriate fields under Configuration->Customer->Facebook Connect, set Enabled to Yes and you’re good to go. If you’re updating from previous releases, you also need to Enable it to work.

Default template files (frontend/default/default/template/facebook/*) and layout (layout/facebook.xml) makes Facebook Connect work out of the box with default theme, but we tried to make customizations as easy as possible so all you need to do is add button or link with “facebook-connect” rel attribute set anywhere in the theme, static block or cms page, for example:

<button rel=”facebook-connect” class=”form-button” type=”submit”><span>Connect with Facebook</span></button>
<a rel=”facebook-connect”>Connect with Facebook</a>

Manually Adding Meta Tags in Magento

If you want to add a custom meta tag to your Magento store, you need to edit the head.phtml file of your template. The location of the file is inside your Magento Installation directory.

app/design/frontend//default/template/page/html/head.phtml

You should replace in the path above with the actual folder for your template.

Then you need to edit the file and add your custom meta tag to it.

Finally,  you should flush the Magento cache and reload your website in your browser. You can check the source code of the page (Ctrl + U for most browsers) to make sure your meta tag is included properly.