Showing posts with label PHP. Show all posts
Showing posts with label PHP. Show all posts

Send Mail Using SSMTP on Ubuntu

Send Mail Using SSMTP. Just another log of one of my activities :D

Currently, I set up my desktop computer to be able to send email. Not from browser, but from the system. 

So, I am using ssmtp with a guide from a quite-old-post from Tom Dryer in tombuntu.com. I've set up my laptop before with it, and works. And after a while, I need to set up my desktop, and I forgot, and I got back to Tom's post :D

How To

Well, we need to install SSMTP first
sudo apt-get install ssmtp

then, we need to change the configuration, located in /etc/ssmtp/ssmtp.conf. My configuration is like this :

Regex.. is a must

Regex, yang merupakan 'nickname'-nya regular expressions, merupakan suatu hal yang 'sesuatu' banget. Hari ini (lirik tanggal di pojok kanan atas komputer), Rabu (16/1), saya bertemu lagi dengan dia (regex --red.) dalam rangka konversi antara (lagi-lagi) 'LOAD DATA INFILE' ke mysqlimport, masih nyambung dengan tulisan yang kemaren. Sebenarnya tidak harus sih, mysqlimport menggunakan regex, cuman dalam kasus saya, saya musti menyesuaikan isi file, yang itu akan lebih efektif dan efisien kalau dikerjakan menggunakan regex. 

Bagi yang belum tahu regex, bisa main main ke tempat ini : http://www.regular-expressions.info/. Kalau berbasis hasil pencarian google menyoal regex, kemungkinan besar dia yang nongol paling atas. Sedikit mengulas 'apa dan bagaimana', jika kita pernah melakukan pencarian file menggunakan format *.txt (atau sejenis), itulah regex dalam formasi sederhana yang sudah kita kenal.

Flash-back
Ada komunikasi satu arah antara 2 software 'serupa namun tak sama' dari software versi desktop ke aplikasi versi web dengan menggunakan text file. Dulunya menggunakan 'LOAD DATA INFILE' sudah cukup menyelesaikan masalah. Tetapi, berhubung sejak Ubuntu 12.04 mulai menyertakan Mysql dengan 'LOAD DATA INFILE' yang di-disable, maka musti memikirkan cara lain. Ketika masalah upload file ke database sudah ditangani, ada kasus lagi bahwa boolean antara yang desktop dengan yang web berbeda, sehingga perlu konversi.

MYSQLIMPORT di windows

Setelah menggunakan mysqlimport di linux (baca : Ubuntu), akhirnya berkesempatan juga (terpaksa) menjajal mysqlimport versi Windows. Lho? Adakah yang berbeda? Pada awalnya saya pikir hanya dengan menggunakan full-path ke file mysqlimport.exe-nya sudah menyelesaikan masalah. Namun ternyata, setelah dicoba, eng-ing-eng.. Gagal. Duh!

Dengan syntax yang sama :
$ mysqlimport --user=root --password=password --delete
--fields-optionally-enclosed-by='"'--fields-terminated-by=';'
--fields-escaped-by='' --lines-terminated-by='\n' --local
database table.txt 
ternyata tidak bekerja dengan baik.

Saya menggunakan WAMPSERVER sebagai web server-nya. Karena 'musti' fullpath (bisa juga sih, setting global environment atau apapun dulu itu namanya; cuma karena terlalu ribet, jadinya yang simple aja, make full path), script saya otomatis jadi seperti ini :
shell_exec("D:\wamp\bin\mysql\mysql5.5.8\bin\mysqlimport.exe
--user=root --password= --fields-optionally-enclosed-by='\"'
--fields-terminated-by=';' --fields-escaped-by=''
--lines-terminated-by='\n' --local --delete
database
path/to/file");
Script di atas akan menghasilkan output yang sama seperti kalau hanya mengakses
D:\wamp\bin\mysql\mysql5.5.8\bin\mysqlimport.exe 
Bahkan dengan mengaksesnya langsung di command prompt sekalipun. Tentu, dengan menyesuaikan scriptnya, menghilangkan '\' yang tidak perlu.

[HOW-TO]
Setelah berpusing ria beberapa jam,  ketemulah solusinya. Seperti biasa, solusi yang sangat menjengkelkan dan sebenarnya sangat simple : me-replace semua ' (apostrophe) menjadi " (double-quote)

Meskipun pengen teriak sekeras-kerasnya, tetapi ada satu kepuasan tersendiri bisa solving masalah dengan usaha sendiri :D

Extend phpMyAdmin time out

[How To]
Here you are :
  1. Go find phpmyadmin's config.inc.php
    Ubuntu version (from repo/ not lampp)
    $ sudo gedit /etc/phpmyadmin/config.inc.php
  2. Add these lines to the bottom of the file
    $cfg['LoginCookieValidity'] = 60*60*24;
    ini_set('session.gc_maxlifetime', $cfg['LoginCookieValidity']); 
  3. Restart apache
    $ sudo service apache2 restart
  4. Done and continue your work :D

Note : if with above trick, still doesn't work, try to edit /etc/phpmyadmin/config.inc.php file, then search for
$cfg['Servers'][$i]['auth_type'] = 'cookie';
 then edit / add the following
$cfg['Servers'][$i]['auth_type'] = 'config';
$cfg['Servers'][$i]['user'] = 'your_mysql_username';
$cfg['Servers'][$i]['password'] = 'your_mysql_password'; 


Accessing Session Variables in Model

This early morning (right now based on Indonesia time GMT+7, it's 8.18 AM), I've been preparing my to-do-list to be done later in my office associated with my countdown-project. It's all about to log every query executed by user action (create/ add, edit and delete) to database by using cakePHP. I've been spending a lot of time on searching the snippet or at least what-kind-of-function-I-must-used-to, and not find my need yet.

Yesterday, since I've found the how-to, based on the link I've found on Stackoverflow and edited it to be like what I want (read : need), I still have to do a lil bit experiment.

It's like this title's post. Accessing session variables in Model. Is that possible? Come on,, it's just PHP. Anything possible.


Change upload_max_filesize PHP

Here is the case. I dumped my localhost database and got 7.2M file size. What? Yeah. It's true. Whereas, my phpmyadmin said if the max upload is just 2M. What the.. Using bigdump seems useless, since they are a whole databases in my localhost.

So, I thought, it should be a way to change it. And here it is (I found the way) :

Install and setting up local webserver

Here is how to install and setting up webserver in Ubuntu (or its derivatives ie. Mint, Sabily, Blankon and so on):