2011/05/27

Change allowed uploading file size - Ubuntu 11.04

When you import a large table using phpmyadmin, you may see the error of, No data was received to import. Either no file name was submitted, or the file size exceeded the maximum size permitted by your PHP configuration. To increase allowed uploading file size, you can need change two values at php.ini file. At command line, type in, sudo vim /etc/php5/apache2/php.ini And then, change values of post_max_size and upload_max_filesize to whatever you want, the default is 8M and 2M separately. ; Maximum size of POST data that PHP will accept. ; http://php.net/post-max-size post_max_size = 80M ; Maximum allowed size for uploaded files. ; http://php.net/upload-max-filesize upload_max_filesize = 20M

How to insall curl php - Ubuntu 11.04

I need curl all the time. Here is how to install it in Ubuntu 11.04 sudo apt-get install php5-curl And then restart apache, how? sudo /etc/init.d/apache2 restart

How to install phpmyadmin - ubuntu 11.04

After installing LAMP server, phpmyadmin is not installed. phpMyAdmin make life easier at least I like it. Here is how to install it in ubuntu 11.04,
 sudo apt-get install libapache2-mod-auth-mysql phpmyadmin
 It's staightforward, although you need to provide some information, like server type, (Choose Apache), Database root password, phpMyAdmin Root password, etc.
And them restart apache by,
 sudo /etc/init.d/apache2 restart
 And try http://localhost/phpmyadmin/, If it does not work, then try the following,
Copy the content of apache configuration file at /etc/phpmyadmin/apache.conf into /var/apache2/http.conf (http.conf was empty in my case) and then restart the apache. OK, then the link, http://localhost/phpmyadmin/ should work.

How to enable .htaccess - Ubuntu 11.04

After you install LAMP, mode rewrite is not enabled. So in order to use .htaccess, you can do the following,

turn on RewriteEngine module

sudo a2enmod rewrite

allow directory to be overridden

Go to /etc/apache2/sites-available and edited the file "default" Change AllowOverride to All from none in Directory /var/www/.
NameVirtualHost *
<VirtualHost *>
        ServerAdmin admin@site.com

        DocumentRoot /var/www/
        <Directory />
                Options FollowSymLinks
                AllowOverride None
        </Directory>
        <Directory /var/www/>
                Options Indexes FollowSymLinks MultiViews
                AllowOverride All
                Order allow,deny
                allow from all
                # This directive allows us to have apache2's default start page
                # in /apache2-default/, but still have / go to the right place
                # Commented out for Ubuntu
                #RedirectMatch ^/$ /apache2-default/
        </Directory>
Restart Apache by sudo /etc/init.d/apache2 restart You should be all set.

2011/05/26

How to install LAMP + Zend Ubuntu 11.04

It's super easy to install LAMP server in Ubuntu 11.04, just need to run the follow command,
sudo apt-get install lamp-server^
You may be asked to set up root password for mysql during the installation, other than that, everything is automatically.

To restart apache, run the following command,
sudo /etc/init.d/apache2 restart
OK, install Zend is also easy,
sudo apt-get install zend-framework
After that you have to make sure zend library path is included. Go to php.ini (@/etc/php5/apache2/), edit the following line,

; UNIX: "/path1:/path2" 
include_path = ".:/usr/share/php:/usr/share/php/libzend-framework-php" 
I also found, after added include_path in the php.ini, the Zend library is still not found if I run the php script in the command line. Not sure why, but the solution I found is uncomment the line at /etc/php5/conf.d/zend-framework.ini,
[Zend] include_path=${include_path} ":/usr/share/php/libzend-framework-php"
Happy ubuntu!

2011/05/25

How to show desktop - Ubuntu 11.04

<Super> key + d (In most PC keyboard, super key is the key between Ctr and Alt having Windows icon in there)
And you can customize it using Keybindings.

Where is Keybidings? here you go.
You can set this up through CompizConfig Settings Manager. (You can always search Apps by clicking the top-left Ubuntu Icon or hit <Super> key) This option is under General Options -> Keybindings.

2011/05/24

How to mount windows drive - Ubuntu 11.04

If you have both Ubuntu and Windows installed in your computer, you
may want to access Windows Drive from Ubuntu, here is how,

1. create a folder under media,

<code>sudo mkdir -p /media/c</code>

2. sudo fdisk -l
You will see something like the following,

Disk /dev/sda: 80.0 GB, 80026361856 bytes
255 heads, 63 sectors/track, 9729 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x9c879c87

Device Boot Start End Blocks Id System
/dev/sda1 * 1 8421 67641651 7 HPFS/NTFS
/dev/sda2 8423 9728 10490445 7 HPFS/NTFS

3. mount it

sudo mount -t ntfs -o nls=utf8,umask=0222 /dev/sda1 /media/c

Note that /dev/sda1 is my Device, yours may be different!!!

How to keep launcher on the top - Ubuntu 11.04

By default Launcher is auto hide, but my screen is wide enough, so I
like it's open all the time to easy access. I thought there should be
an option for us to do change its behaviors when you right click on
the Launcher, but I was wrong, maybe in next release.

So here is how,
http://askubuntu.com/questions/9865/how-can-i-configure-unitys-launcher-auto-hide-behavior/31418#31418

Happy Ubuntu!

2011/05/18

Multiple Preg replace in PHP

You can do multiple preg replace with one function call, for example,

PHP, using GeSHi 1.0.8.8
  1. $subject = "{hello}";
  2. $patterns = array("/{/", "/}/");
  3. $replaces = array("{ldelim}", "{rdelim}");
  4. echo preg_replace($patterns, $replaces, $subject); 

Guess what your get? you get,

{ldelim{rdelim}hello{rdelim}

The reason you get this is that perg_replace executes multiple patterns one by one, so ‘{‘ is replaced by ‘{ldelim}’, and then ‘{ldelim}’ is replaced by ‘ {ldelim{rdelim}’.

I believe this is not what you wanted to get. You only want one ‘pattern’ is replaced once. So you can do this,

PHP (brief), using GeSHi 1.0.8.8
  1. $title = "{abdcd}";
  2. $patterns = array("/{/", "/}/");
  3. $replaces = array("LC", "RC");
  4. $title = preg_replace($patterns, $replaces, $title);
  5.  
  6. $patterns = array("/LC/", "/RC/");
  7. $replaces = array("{ldelim}", "{rdelim}");
  8. echo preg_replace($patterns, $replaces, $title);

Finally, you get,

{ldelim}hello{rdelim}

Note that in smarty template, to keep brace, you have to change ‘{ ‘or ‘} ‘to ‘{ldelim}’ or ‘{rdelim}’, or add {literal} and {/literal} around the code that you don’t want smarty engine to interpret it.