2010年10月14日 星期四

mysql 安裝與ajax with php測試

[root@localhost ajax-poll]# yum install mysql mysql-server -y

[root@localhost ajax-poll]# service mysqld start
[root@localhost ajax-poll]# chkconfig mysqld on
[root@localhost ajax-poll]# mysqladmin -u root password 'rootpass'
[root@localhost ajax-poll]# mysql -u root -p

Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 5.0.77 Source distribution

Type 'help;' or '\h' for help. Type '\c' to clear the buffer.
mysql> create database syspage;
mysql> show databases;
+--------------------+
Database
+--------------------+
information_schema
mysql
syspage
test
+--------------------+
4 rows in set (0.00 sec)

mysql> GRANT ALL PRIVILEGES ON syspage.* to sean@local IDENTIFIED BY 'syspass';
mysql> GRANT ALL PRIVILEGES ON syspage.* to sean@localhost IDENTIFIED BY 'syspass';
mysql> GRANT ALL PRIVILEGES ON syspage.* to sean@172.16.43.98 IDENTIFIED BY 'syspass';
mysql> GRANT ALL PRIVILEGES ON syspage.* to sean@172.16.43.99 IDENTIFIED BY 'syspass';
mysql> GRANT ALL PRIVILEGES ON syspage.* to sean@172.16.43.144 IDENTIFIED BY 'syspass';
mysql> SHOW GRANTS FOR 'sean'@'localhost';
+------------------------------------------------------------------------------------+
Grants for sean@localhost
+------------------------------------------------------------------------------------+
GRANT USAGE ON *.* TO 'sean'@'localhost' IDENTIFIED BY PASSWORD '02be59854f8541f8'
GRANT ALL PRIVILEGES ON `syspage`.* TO 'sean'@'localhost'
+------------------------------------------------------------------------------------+
2 rows in set (0.00 sec)

[root@localhost ajax-poll]# cd ajax-poll
[root@localhost ajax-poll]# mysql -u root --password='rootpass' syspage < polls.sql
mysql> use syspage ;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
mysql> show tables;
+-------------------+
Tables_in_syspage
+-------------------+
options
questions
votes
+-------------------+
3 rows in set (0.00 sec)


[root@localhost ajax-poll]# yum install php php-devel php-mysql -y
[root@localhost html]# cp -r ~/Desktop/ajax-poll /var/www/html/.

[root@localhost ajax-poll]# cd /var/www/html/ajax-poll/

[root@localhost ajax-poll]# vi poll.php

$conn=mysql_connect('localhost', 'root', 'sikhadmin') or die("Can't connect to mysql host");
mysql_select_db('polls') or die("Can't connect to DB");


$conn=mysql_connect('localhost', 'root', 'rootpass') or die("Can't connect to mysql host");
mysql_select_db('syspage') or die("Can't connect to DB");





apache與php tarball版安裝

PHP版本:5.2.6

1.安裝相關的相依性套件

# yum -y install mysqlclient14 mysqlclient14-devel freeradius-mysql

mysql-server mysql-devel pcre-devel libc-client-devel cyrus-imapd-devel

gd-devel openldap-devel freetype-devel

##備註:安裝過程有缺檔案快速查詢方式,到別台已經裝好的電腦上利用 locate 找出

該檔案絕對路徑和使用 rpm -qf 做反查套件。


2.把 php 解壓縮到 root 家目錄

# tar -jxvf php-5.2.6.tar.bz2 -C /root/

3.編譯前先啟動 mysql,並在 runlevel 3 和 5 自動啟用

# service mysqld start && chkconfig --level 35 mysqld on

4. 開始配置 php

# cd php-5.2.6

# ./configure --prefix=/usr/local/php5 --with-mysql --with-apxs2

=/usr/local/apache2/bin/apxs ( 這裡由於apahce2也是自己編譯的,使用

系統預設 apache 的人要注意路徑 ) --with-regex=php --enable-shared

--with-gd=/usr --enable-gd-native-ttf -with-zlib --with-freetype-dir=/usr

--with-ldap=/usr

5. 編譯並安裝

# make && make install

6. 檢查自己的 apache modules 資料夾下有無 libphp5.so 並檢查 httpd.conf

是否已經載入模組。 沒有的自行加入下一行

LoadModule php5_module modules/libphp5.so

要注意 modules資料夾位置 , 寫法是相對於 ServerRoot 的位置 ,

我的 apache ServerRoot 是在 /usr/local/apache2, 實際上 libphp5.so

絕對位置在 /usr/local/apache2/modules/libphp5.so )

如有修改 httpd.conf 的話要做 apachectl restart

(使用rpm安裝的 apache 可用 service httpd restart )

##備註:我測試 2.2.9 和 2.2.11 版的 apachectl 工具上偶而會出現

restart 無效的情況,可嘗試 apachectl stop 後再 apachectl start

7. 設定 mysql 資料庫

# mysqladmin -u root password '123456' //設定root密碼123456

# mysqladamin -u -h localhost password '123456' -p

# mysql -p

8. 拷貝php.ini 到 /usr/local/php5下 ,並確認 register_globals 關閉

# cd /root/php-5.2.6/ ; cp php.ini-dist /usr/local/php5/lib/php.ini

# vi /usr/local/php5/lib/php.ini

register_globals=off

9. 到 apache 的 DocumentRoot 資料夾下建立一個 test.php的

測試頁面,內容如下



10. 瀏覽器測試

http://打入你的ip/test.php

成功的話就會看到 php 的頁面


===========================================================================================


Tarball Apache2 & PHP5
一月 1st, 2008 · shian · Linux No comments - Tags: centos, Linux
Share

安裝apach和php有很多方法,像是利用rpm檔來裝,或是使用yum安裝,本篇介紹使用tarball 方式來安裝apache和php, 使用tarball安裝的方式比較麻煩一點,建議初學者可以使用yum的方式安裝


Apache 安裝
安裝:
./configure –prefix=/usr/local/apache –enable-so –enable-ssl –enable-rewrite
make
make install
註:
–prefix=/usr/local/apache/ : 安裝apache的位置
–enable-so : 啟用模組
–enable-ssl : 啟用ssl
–enable-rewrite : 啟用rewrite

PHP 安裝
安裝:
./configure –prefix=/usr/local/php/ –with-apxs2=/usr/local/apache/bin/apxs –with-mysql=/usr/local/mysql/ –with-gd –with-jpeg-dir=/usr/lib –with-zlib-dir=/usr/lib –with-libxml-dir=/usr/lib –enable-ftp –enable-socket –enable-magic-quotes –enable-libgcc –enable-ftp –enable-mbstring –enable-debug –enable-fastcgi –enable-module=so
make
make install
註:
–prefix=/usr/local/php/ : 安裝php的位置
–with-apxs2=/usr/local/apache/bin/apxs : apache2的目錄位置
–with-mysql=/usr/local/mysql/ : mysql的目錄位置(如果是用rpm安裝的Mysql,那就不要指定路徑了,直接--with-mysql即可)
–with-gd : 安裝gd模組
–with-jpeg-dir=/usr/lib
–with-zlib-dir=/usr/lib
–with-libxml-dir=/usr/lib
–enable-ftp :啟用ftp
–enable-socket :啟用socket
–enable-magic-quotes
–enable-libgcc
–enable-mbstring
–enable-debug
–enable-fastcgi
–enable-module=so

設定 Apache
設定檔 : /usr/local/apache/conf/httpd.conf

檢查是否有下面這段
LoadModule php5_module modules/libphp5.so

更改 ServerName
ServerName 192.168.1.102:80

更改 DirectoryIndex
找到DirectoryIndex,設定首頁名稱加上 index.php index.phtml index.php3

增加AddType項目,找到並增加以下三行:(用tarball安裝後,如果沒有設定下列3行,.php的網頁還是會變文字檔顯示)
AddType application/x-httpd-php .php
AddType application/x-httpd-php .php3
AddType application/x-httpd-php .phtml

設定User home directories
找到 Include conf/extra/httpd-userdir.conf 並將前面的 # 去掉

設定PHP
設定檔 : /usr/local/php/lib
複製php.ini-dist 到 /usr/local/php/lib/php.ini
cp php.ini-dist /usr/local/php/lib/php.ini

設定extensions
extension_dir = "/usr/local/php/lib/php/extensions"
找到 extensions_dir , 並設定extensions的目錄

操作&啟動
啟動: /usr/local/apache/bin/apachectl start
重啟: /usr/local/apache/bin/apachectl restart
停止: /usr/local/apache/bin/apachectl stop

開機啟動APACHE
設定檔: /etc/rc.d/rc.local
加入這一段 /usr/local/apache/bin/apachectl start

2010年10月1日 星期五

C,C++ redirect and pipeline


[root@localhost ~]# cat t3.c | ./t3
start...
#include
int main(int argc , char * argv[])
{
char in[1024];
int rlen = 0;
printf("start...\n");
do
{
rlen = fread(in , 1,sizeof(in),stdin);
if(rlen> 0)
{
printf("%s\n",in);
}
}while(rlen > 0);
printf("end...\n");
return 0;
}

end...
[root@localhost ~]# ./t3 < `echo t3.c`
start...
#include
int main(int argc , char * argv[])
{
char in[1024];
int rlen = 0;
printf("start...\n");
do
{
rlen = fread(in , 1,sizeof(in),stdin);
if(rlen> 0)
{
printf("%s\n",in);
}
}while(rlen > 0);
printf("end...\n");
return 0;
}

end...
[root@localhost ~]# gcc -o t3 t3.c

文章分類