ALIBOBO'S BLOG

No Pain No Gain

ALL ABOUT UBUNTU

, ,

For web dev

For web dev
- lampp installation:
How to obtain the latest version of LAMP on Ubuntu:
(Apache 2.2 + MySQL 5.1 + PHP 5.2 + PERL 5.10 +PEAR + SQLite + ProFTPD + phpMyAdmin + Webalizer + phpSQLiteAdmin + XAMPP Control Panel)
http://www.ubuntuforums.org/223410
http://www.apachefriends.org/f/viewtopic.php?t=21531#108517

The commands in this HOWTO must be entered in the terminal:
Applications -> Accessories -> Terminal

Download XAMPP to your desktop and extract the files:
http://apachefriends.org/xampp-linux
cd ~/Desktop
wget http://www.apachefriends.org/download.php?xampp-linux-1.7.1.tar.gz
sudo tar xvfz xampp-linux*.tar.gz -C /opt

Create a XAMPP start menu entry:
cd ~/.local/share/applications
gedit xampp-control-panel.desktop

Paste the following into the open file:
[Desktop Entry]
Comment=Start/Stop XAMPP
Name=XAMPP Control Panel
Exec=gksudo "python /opt/lampp/share/xampp-control-panel/xampp-control-panel.py"
Icon[en_CA]=/usr/share/icons/Tango/scalable/devices/network-wired.svg
Encoding=UTF-8
Terminal=false
Name[en_CA]=XAMPP Control Panel
Comment[en_CA]=Start/Stop XAMPP
Type=Application
Icon=/usr/share/icons/Tango/scalable/devices/network-wired.svg

[Desktop Entry]
Comment=Start/Stop XAMPP
Name=XAMPP Control Panel
Exec=gksudo /opt/lampp/share/xampp-control-panel/xampp-control-panel
Icon[en_CA]=/opt/lampp/htdocs/xampp/img/logo-small.gif
Encoding=UTF-8
Terminal=false
Name[en_CA]=XAMPP Control Panel
Comment[en_CA]=Start/Stop XAMPP
Type=Application
Icon=/opt/lampp/htdocs/xampp/img/logo-small.gif

Save and close the file.

Publish:
XAMPP uses /opt/lampp/htdocs as the root web directory, but you can publish pages in your home directory this way.
cd ~
mkdir public_html
sudo ln -s ~/public_html /opt/lampp/htdocs/$USER

Now any files and folders you place in ~/public_html will be
published to your personal webserver.

Start XAMPP via the terminal:
cd /opt/lampp
sudo ./lampp start

Stop XAMPP (if necessary):
cd /opt/lampp
sudo ./lampp stop

Via the XAMPP Control Panel:
Applications -> Other -> XAMPP Control Panel

If Apache2 or MySQL is already running, then XAMPP will not start. You must stop these applications, if you want to use XAMPP:
sudo /etc/init.d/apache2 stop
sudo /etc/init.d/mysql stop

PHP5 is the default, but you can switch between PHP4 and PHP5, if you like:
cd /opt/lampp
sudo ./lampp php4
sudo ./lampp php5

Open your new webpages at:

http://localhost/username/

Security:
http://apachefriends.org/xampp-linux/381

1. The MySQL root user has a blank password.
2. MySQL is accessible via your local network.
3. ProFTPD has user “nobody” with password “lampp”.
4. PhpMyAdmin is accessible via the local network.
5. Examples are accessible via the local network.
6. MySQL and Apache running under the same user “nobody”.

To configure some of the security features of xampp:
cd /opt/lampp
sudo ./lampp security

A happy September dayAUDIO BOOK: Hiểu về trái tim

Comments

Nguyễn Văn ChươngAlibobo Thursday, September 23, 2010 8:30:50 AM

Install Apache

To start off we will install Apache.

1. Open up the Terminal (Applications > Accessories > Terminal).
2. Copy/Paste the following line of code into Terminal and then press enter:

sudo apt-get install apache2

3. The Terminal will then ask you for you're password, type it and then press enter.

Testing Apache

To make sure everything installed correctly we will now test Apache to ensure it is working properly.

1. Open up any web browser and then enter the following into the web address: http://localhost/

You should see a folder entitled apache2-default/. Open it and you will see a message saying "It works!" , congrats to you!

Install PHP

In this part we will install PHP 5.

Step 1. Again open up the Terminal (Applications > Accessories > Terminal).
Step 2. Copy/Paste the following line into Terminal and press enter:

sudo apt-get install php5 libapache2-mod-php5

Step 3. In order for PHP to work and be compatible with Apache we must restart it. Type the following code in Terminal to do this:

sudo /etc/init.d/apache2 restart

Test PHP

To ensure there are no issues with PHP let's give it a quick test run.

Step 1. In the terminal copy/paste the following line:

sudo gedit /var/www/testphp.php

This will open up a file called phptest.php.

Step 2. Copy/Paste this line into the phptest file:

<?php phpinfo(); ?>

Step 3. Save and close the file.

Step 4. Now open you're web browser and type the following into the web address:

http://localhost/testphp.php

The page should look like this:

Test PHP Page

Congrats you have now installed both Apache and PHP!

Install MySQL

To finish this guide up we will install MySQL. (Note - Out of Apache and PHP, MySQL is the most difficult to set up. I will provide some great resources for anyone having trouble at the end of this guide.)

Step 1. Once again open up the amazing Terminal and then copy/paste this line:

sudo apt-get install mysql-server

Step 2 (optional). In order for other computers on your network to view the server you have created, you must first edit the "Bind Address". Begin by opening up Terminal to edit the my.cnf file.

gksudo gedit /etc/mysql/my.cnf

Change the line

bind-address = 127.0.0.1

And change the 127.0.0.1 to your IP address.

Step 3. This is where things may start to get tricky. Begin by typing the following into Terminal:

mysql -u root

Following that copy/paste this line:

mysql> SET PASSWORD FOR 'root'@'localhost' = PASSWORD('yourpassword');

(Make sure to change yourpassword to a password of your choice.)

Step 4. We are now going to install a program called phpMyAdmin which is an easy tool to edit your databases. Copy/paste the following line into Terminal:

sudo apt-get install libapache2-mod-auth-mysql php5-mysql phpmyadmin

After that is installed our next task is to get PHP to work with MySQL. To do this we will need to open a file entitled php.ini. To open it type the following:
gksudo gedit /etc/php5/apache2/php.ini

Now we are going to have to uncomment the following line by taking out the semicolon (wink.

Change this line:

;extension=mysql.so

To look like this:

extension=mysql.so

Now just restart Apache and you are all set!

sudo /etc/init.d/apache2 restart

Nguyễn Văn ChươngAlibobo Wednesday, November 3, 2010 7:32:14 AM

Rename multiple files with Linux

rename

Syntax

rename [ -v ] [ -n ] [ -f ] perlexpr [ files ]

-v
Verbose: print names of files successfully renamed.
-n
No Action: show what files would have been renamed.
-f
Force: overwrite existing files.
perlexpr
Perl Expression

Regular Expressions

^
matches the beginning of the line
$
matches the end of the line
.
Matches any single character
(character)*
match arbitrarily many occurences of (character)
(character)?
Match 0 or 1 instance of (character)
[abcdef]
Match any character enclosed in [] (in this instance, a b c d e or f)
ranges of characters such as [a-z] are permitted. The behaviour
of this deserves more description. See the page on grep
for more details about the syntax of lists.
[^abcdef]
Match any character NOT enclosed in [] (in this instance, any character other than a b c d e or f)
(character)\{m,n\}
Match m-n repetitions of (character)
(character)\{m,\}
Match m or more repetitions of (character)
(character)\{,n\}
Match n or less (possibly 0) repetitions of (character)
(character)\{n\}
Match exactly n repetitions of (character)
\(expression\)
Group operator.
\n
Backreference - matches nth group
expression1\|expression2
Matches expression1 or expression 2. Works with GNU sed, but this feature might not work with other forms of sed.
\w
matches any single character classified as a “word” character (alphanumeric or “_”)
\W
matches any non-“word” character
\s
matches any whitespace character (space, tab, newline)
\S
matches any non-whitespace character
\d
matches any digit character, equiv. to [0-9]
\D
matches any non-digit character

As rename is a perl script you will need perl to run it, and here are some examples about how to use it.

$ rename -v 's/\.htm$/\.html/' *.htm

This is going to change htm to html in every file ending with .htm in its name.

If you want to change the name of something like this:

-rw-r--r-- 1 chuongnv chuongnv 0 2010-10-30 19:33 1.txt
-rw-r--r-- 1 chuongnv chuongnv 0 2010-10-30 19:33 2.txt
-rw-r--r-- 1 chuongnv chuongnv 0 2010-10-30 19:34 3.txt
-rw-r--r-- 1 chuongnv chuongnv 0 2007-12-28 20:35 b.txt
-rw-r--r-- 1 chuongnv chuongnv 0 2007-12-28 20:35 c.txt
-rw-r--r-- 1 chuongnv chuongnv 0 2007-12-28 20:35 d.txt
-rw-r--r-- 1 chuongnv chuongnv 0 2007-12-28 20:35 e.txt

That is the output of ls -l, and are files created with touch by me for this examples.

Now lets say I want to add a more descriptive string to the name of these files like Thesis, so here we go.

rename -n 's/(\w{1})\.txt$/$1_thesis\.txt/' *.txt

Note: I am using -n to make only a test and see if the result is what I want

1.txt renamed as 1_thesis.txt
2.txt renamed as 2_thesis.txt
3.txt renamed as 3_thesis.txt
b.txt renamed as b_thesis.txt
c.txt renamed as c_thesis.txt
d.txt renamed as d_thesis.txt
e.txt renamed as e_thesis.txt

As you see that is what I wanted, now lets suppose I only want to change the name to files with a number in the name and with a letter in it.

rename -n 's/(\d{1})\.txt$/$1_thesis\.txt/' *.txt

1.txt renamed as 1_thesis.txt
2.txt renamed as 2_thesis.txt
3.txt renamed as 3_thesis.txt

You can also match only the ones with non-digit names

rename -n 's/(\D{1})\.txt$/$1_thesis\.txt/' *.txt

And the output will be:

b.txt renamed as b_thesis.txt
c.txt renamed as c_thesis.txt
d.txt renamed as d_thesis.txt
e.txt renamed as e_thesis.txt

As you may see, it is just a "using the right regexp" thing.

In case you do not have rename on your system (I think non-Debian does not have) you can use mv
Using mv

Introduction

Here we will first need to learn something about bash string operators

Match and substitute, there are two basic forms for this, substitute from the right of the match and from the left of the match.

substitution from the right

${var%t*string}

Now if we want to erase the word thesis from the previous example just enter:

for i in *.txt; do mv "$i" "${i%t*.txt}.txt"; done

Before:

-rw-r--r-- 1 chuongnv chuongnv 0 2010-10-30 20:24 1_thesis.txt
-rw-r--r-- 1 chuongnv chuongnv 0 2010-10-30 20:24 2_thesis.txt
-rw-r--r-- 1 chuongnv chuongnv 0 2010-10-30 20:24 3_thesis.txt
-rw-r--r-- 1 chuongnv chuongnv 0 2010-10-30 20:24 b_thesis.txt
-rw-r--r-- 1 chuongnv chuongnv 0 2010-10-30 20:24 c_thesis.txt
-rw-r--r-- 1 chuongnv chuongnv 0 2010-10-30 20:24 d_thesis.txt
-rw-r--r-- 1 chuongnv chuongnv 0 2010-10-30 20:24 e_thesis.txt

After:

-rw-r--r-- 1 chuongnv chuongnv 0 2010-10-30 20:24 1_.txt
-rw-r--r-- 1 chuongnv chuongnv 0 2010-10-30 20:24 2_.txt
-rw-r--r-- 1 chuongnv chuongnv 0 2010-10-30 20:24 3_.txt
-rw-r--r-- 1 chuongnv chuongnv 0 2010-10-30 20:24 b_.txt
-rw-r--r-- 1 chuongnv chuongnv 0 2010-10-30 20:24 c_.txt
-rw-r--r-- 1 chuongnv chuongnv 0 2010-10-30 20:24 d_.txt
-rw-r--r-- 1 chuongnv chuongnv 0 2010-10-30 20:24 e_.txt

substitution from the left

${var#string}

And if we want to replace .txt for .txt.bak just enter:

Now lets suppose we have this:

-rw-r--r-- 1 chuongnv chuongnv 0 2010-10-30 20:28 thesis-1_.txt
-rw-r--r-- 1 chuongnv chuongnv 0 2010-10-30 20:28 thesis-2_.txt
-rw-r--r-- 1 chuongnv chuongnv 0 2010-10-30 20:28 thesis-3_.txt
-rw-r--r-- 1 chuongnv chuongnv 0 2010-10-30 20:28 thesis-b_.txt
-rw-r--r-- 1 chuongnv chuongnv 0 2010-10-30 20:28 thesis-c_.txt
-rw-r--r-- 1 chuongnv chuongnv 0 2010-10-30 20:28 thesis-e_.txt

And we want to erase the word thesis

Just enter this:

for f in thesis*; do mv "$f" "${f#thesis-}"; done

And the output of ls -l will now be:

-rw-r--r-- 1 chuongnv chuongnv 0 2010-10-30 20:28 1_.txt
-rw-r--r-- 1 chuongnv chuongnv 0 2010-10-30 20:28 2_.txt
-rw-r--r-- 1 chuongnv chuongnv 0 2010-10-30 20:28 3_.txt
-rw-r--r-- 1 chuongnv chuongnv 0 2010-10-30 20:28 b_.txt
-rw-r--r-- 1 chuongnv chuongnv 0 2010-10-30 20:28 c_.txt
-rw-r--r-- 1 chuongnv chuongnv 0 2010-10-30 20:28 e_.txt

Nguyễn Văn ChươngAlibobo Wednesday, November 17, 2010 6:42:26 AM

50 câu lệnh Linux phải nhớ

1. clear: làm sạch cửa sổ dòng lệnh
2. ls tenthumuc: Liệt kê nội dung bên trong một thư mục
3. cat tentaptin: Hiển thị nội dung của một tập tin lên cửa sổ dòng lệnh
4. rm tentaptin: Xóa một tập tin
5. cp taptinnguon taptindich: Sao chép một tập tin
6. passwd: Đổi mật khẩu
7. motd: Thông điệp của ngày
8. finger tentruycap: Chương trình tìm kiếm thông tin người dùng
9. startx: Khởi động X Window System server
10. less tentaptin hoặcr more tentaptin: Hiển thị nội dung một tập tin trong cửa sổ dòng lệnh một trang mỗi lần
11. info: Hiển thị thông tin và tài liệu trên shell, các tiện ích và chương trình.
12. lpr tentaptin: Gửi tập tin tới máy tin
13. grep chuoi tentaptin: tìm kiếm chuỗi trong tập tin
14. head tentaptin: Hiển thị 10 dòng đầu tiên của tập tin
15. tail tentaptin: Hiển thị 10 dòng cuối cùng của tập tin
16. mv tentaptincu tentaptinmoi: Di chuyển hoặc đổi tên tập tin
17. file tentaptin: Hiển thị thông tin về nội dung của tập tin
18. echo chuoi: Sao chép chuỗi tới màn hình dòng lệnh
19. date: Hiển thị ngày và giờ hiện tại
20. cal: Hiển thị lịch
21. gzip tentaptin: Nén một tập tin
22. gunzip tentaptin: Giải nén một tập tin
23. which lenh: Hiển thị đường dẫn tới lệnh
24. whereis lenh: Hiển thị đường tới nơi chứa lệnh
25. who: Hiển thị các người dùng đã đang nhập
26. finger tentruycap@maychu: Thu thập thông tin chi tiết về người dùng hiện đang dùng hệ thống
27. w: Hiễn thị người dùng đã đăng nhập với các tiến trình sử dụng
28. mesg y/n: Đặt tùy chọn để các người dùng khác viết thông điệp cho bạn
29. write nguoidung: Gửi tin nhắn cho người dùng khác
30. talk nguoidung: Cho phép 2 người chat với nhau
31. chmod quyen tentaptin: Thay đổi quyền truy cập tập tin
32. mkdir tenthumuc: Tạo một thư mục
33. rmdir tenthumuc: Xóa một thư mục rỗng
34. ln existingfile new-link: Tạo một đường dẫn tới một tập tin (liên kết cứng)
35. df: Hiển thị tất cả các mount của hệ thộng
36. top: Hiển thị danh sách các tiến trình đang chạy
37. tty: Hiển thị tên của cửa sổ dòng lệnh mà trên đó lệnh được dùng
38. kill PID hoặc số %job: Ngừng một tiến trình bằng số PID (Process Identification Number) hoặc số công việc
39. jobs: Hiển thị một danh sách các công việc hiện tại
40. netstat: Hiển thị các kết nối mạng
41. traceroute maychu: In gói định tuyến tới máy chủ
42. nslookup: Truy vấn máy chủ tên miền
43. hostname: Hiển thị tên định danh của hệ thống
44. rlogin maychu: Tiện ích để kết nối với một hệ thống ở xa
45. telnet maychu: Tiện ích để kết nối tới một hệ thống ở xa (tương tự như rlogin nhưng tương tác tốt hơn)
46. rcp taptin maytuxa: Được dùng để sao chép từ một máy tính ở xa
47. ftp: Tiện ích để truyền tập tin giữa các hệ thống trên một mạng
48. rsh lenh: Tiện ích để chạy một lệnh trên một hệ thống ở xa mà không cần đăng nhập
49. ping maychu: Tiện ích để kiểm tra kết nối tới một hệ thống ở xa
50. lcd duongdanthumuc: Thay đổi thư mục máy cục bộ khi đã đăng nhập ở trên máy ở xa

Write a comment

New comments have been disabled for this post.

May 2012
S M T W T F S
April 2012June 2012
1 2 3 4 5
6 7 8 9 10 11 12
13 14 15 16 17 18 19
20 21 22 23 24 25 26
27 28 29 30 31