Skip to content


Linux+Apache2+MySQL5+PHP5+GD

转自http://www.phpchina.com/bbs/viewthread.php?tid=1381&extra=page%3D1&sid=8Fc8aV

所有资源来源于网络.本文可以任意修改,转载,复制…
虽然是在Debian下配置的,由于是源码包安装的,所以应该也适用于其他Linux发行版.

首先,准备好软件包:
最新的Apache,MySQL和PHP可以去相对的官方网站去下载,也可以去http://www.phpchina.cn/bbs/forumdisplay.php?fid=24下载,下载到/tmp/src/目录下:
MySQL5: http://dev.mysql.com/get/Downloa … vmmatrix.net/mysql/
PHP5.1.1: http://cn2.php.net/get/php-5.1.1.tar.bz2/from/cn.php.net/mirror
Apache2.0.55: http://mirror.vmmatrix.net/apache/httpd/httpd-2.0.55.tar.gz
GD Library: http://www.boutell.com/gd/http/gd-2.0.33.tar.gz
Zlib: http://www.zlib.net/zlib-1.2.3.tar.gz
libpng : http://prdownloads.sourceforge.n … fig.tar.gz?download
Jpeg v6b: http://www.ijg.org/files/jpegsrc.v6b.tar.gz 链接似乎失效了,我把文件作为附件上传上来了
FreeType2: http://jaist.dl.sourceforge.net/ … etype-2.1.10.tar.gz
如果连Debian都没有的话,可以去这里下载:http://www.phpchina.cn/bbs/viewt … &extra=page%3D1

所有操作都是以root用户来进行的.
解压:
对于*.tar.gz的文件使用命令tar zxvf *.tar.gz来解压;
对于*.tar.bz2的文件使用命令tar jxvf *.tar.bz2来解压.
将mysql,php,apache以及gd安装到/opt/目录下,便于管理.
编译安装MySQL:
进入到解压后的mysql目录,在终端输入下面的命令:

./configure –prefix=/opt/mysql –with-mysqld-user=beinan –with-extra-charsets=all –with-unix-socket-path=/opt/mysql/var/mysql.sock

–prefix=/opt/mysql 把mysql-4.0.16指定安装到/opt/mysql目录中;
–with-extra-charsets=all 对多语言的支持;
–with-unix-socket-path=/opt/mysql/var/mysql.sock 这个是指定mysql服务器启动后,联机套接字文件所处的位置和文件名,也就是说,如果mysql服务器成功启动后,就能在/opt/mysql/var目录中看到mysql.sock文件。如果看不到,肯定是mysql启动不了。
–with-mysqld-user=username 这个是让mysql服务器也能让系统中普通用户username也能启动mysql服务器。用普通用户来启动mysql的好处是:mysql的进程会自己死掉自动退出。当然root用户也可以,不过有时mysql有些进程死了,但不会自动退出,root自己也杀不掉。所以用普通用户就有这样的好处,大多不会出现mysql进程已死,但不会退出的情况;

make
make install

现在MySQL已经安装完毕了.剩下的就是配置了.
配置MySQL:(以下操作都是以root执行)
输入命令:

cp /opt/mysql/share/mysql/my-medium.cnf /etc/my.cnf

是将配置文件拷贝到/etc目录下成为my.cnf,大家可以根据自己的需要选择配置文件(配置文件在/opt/mysql/share/mysql/目录下,有my-huge.cnf my-medium.cnf my-large.cnf my-small.cnf这些).
运行

/opt/mysql/bin/mysql_install_db

这个命令是创建MySQL的授权表.

chmod 755 /opt/mysql/var //设置/opt/mysql/var的目录权限为755
chown -R username:username /opt/mysql/var //如果希望使用username这个用户来启动mysql的话
/opt/mysql/share/mysql/mysql.server start //启动mysql服务
chown -R username:username /opt/mysql/ //把/opt/mysql目录归属到username这个用户下
/opt/mysql/bin/mysqladmin -u root password 123456 //设置root用户的密码为123456

编译安装Apache
进入解压后的apache文件夹.在终端输入:

./configure –prefix=/opt/apache –enable-track-vars –enable-cgi –with-config-file-path=/opt/apache/conf

我大多是采用默认的配制.

–prefix=/opt/apache 指定把apahce安装到/opt/apache目录中;
–enable-cgi 支持CGI;
–with-config-file-path=/opt/apache/conf 指定把apache的配制文件放在/opt/apache/conf中;比如httpd.conf配制文件就在这个目录中;
–enable-track-vars 为启动cookie的get/post等追踪功能

编译安装:

make
make install

安装完成后,会在/opt/目录下生成/opt/apache
启动apache守护进程:

/opt/apache/bin/apachectl start

打开浏览器,输入 http://localhost 就能看到一个apache的欢迎页面了,这表示我们已经成功解决了apache的安装。

配制apache

配制文件是/opt/apache/conf/httpd.conf
编译安装的apache默认存放主页的位置应该是/opt/apache/htdocs
这个目录。
在httpd.conf中比较重要的几项:

ServerRoot "/opt/apache"

这是ServerRoot指定apache程序所在的的目录,比如日志文件、配制文件等目录.

Listen 80

apache 默认端口80

ServerAdmin root@localhost

在这里,把管理员的信箱放上去

#ServerName new.host.name:80

前面有#号就是注销掉了,设置主机名.

DocumentRoot "/opt/apache/htdocs"

这个是存放网页的目录,也就是说,我们应该把网页的目录指定到哪里,这样当访问网址时,就调用这个目录的文件.

这句应该和DocumentRoot 的目录保持一致。

#
# Possible values for the Options directive are "None", "All",
# or any combination of:
# Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews
#
# Note that "MultiViews" must be named *explicitly* — "Options All"
# doesn’t give it to you.
#
# The Options directive is both complicated and important. Please see
# http://httpd.apache.org/docs-2.0/mod/core.html#options
# for more information.
#
Options Indexes FollowSymLinks

#
# AllowOverride controls what directives may be placed in .htaccess files.
# It can be "All", "None", or any combination of the keywords:
# Options FileInfo AuthConfig Limit
#
AllowOverride None

#
# Controls who can get stuff from this server.
#
Order allow,deny
Allow from all

AddDefaultCharset ISO-8859-1

这句是指定网页的默认语言的,如果网页出乱中文乱码,应该改AddDefaultCharset 后面的值为GB2312。也就是改成下面这样的。

找到下面的一行在后面加上index.php ,让网站的默认页是index.php也行;

DirectoryIndex index.html index.html.var index.php

找到

#AddType application/x-tar .tgz

这行,在下面加一行。前面不要加#号。

AddType application/x-httpd-php .php

配制好后,我们就重启apache后,对那个存放网页的目录执行:

chmod 755 目录名
chmod -R 755 目录名

然后就重启apache的守护进程httpd

/opt/apache/bin/apachectl restart

在浏览器的地址栏中输入localhost或者127.0.0.1,这样应该能看到页面了吧。

如果是通过root用户,或者其它用户把相应的网站文件复制到网站存放的目录下的,要改变网站存放目录中所有文件的权限,就是上面所说的chmod -R 755 目录名.

编译安装PHP:
zlib:
进入解压后的zlib目录.在终端执行以下命令:

./configure
make
make install

freetype:
进入解压后的freetype目录,在终端执行以下命令:

./configure –prefix=/usr/local/freetype
make
make install

libpng:
进入解压后的libpng目录,在终端执行以下命令:

./configure
make
make test
make install

jpeg-6b:
进入解压后的jpeg-6b目录,在终端执行以下命令:

mkdir /usr/local/jpeg
mkdir /usr/local/jpeg/bin
mkdir /usr/local/jpeg/lib
mkdir /usr/local/jpeg/include
mkdir /usr/local/jpeg/man
mkdir /usr/local/jpeg/man/man1
./configure –prefix=/usr/local/jpeg –enable-shared –enable-static
make
make install

GD Library:
进入解压后的gd目录,在终端执行以下命令:(注意不要空行)

./configure –prefix=/usr/local/gd –with-jpeg=/usr/local/jpeg –with-freetype=/usr/local/freetype –with-png –with-zlib
make
make install

PHP:
进入解压后的gd目录,在终端执行以下命令:(不要空行)

./configure –prefix=/opt/php –with-apxs2=/opt/apache/bin/apxs –with-gd=/usr/local/gd –enable-gd –enable-gd-native-ttf –with-jpeg-dir=/usr/local/jpeg –with-png –with-ttf –with-zlib –with-freetype-dir=/usr/local/freetype –enable-magic-quotes –with-mysql=/opt/mysql –with-mysql-sock=/opt/mysql/var/mysql.sock –with-iconv –with-mbstring –enable-mbstring –enable-track-vars –enable-force-cgi-redirect –enable-ftp –with-config-file-path=/opt/php/etc –with-pear=/server/php/pear
make
make install

复制php.ini-dist为php.ini,并存放到/opt/php/etc/目录下.
编辑/opt/php/etc/php.ini文件,找到如下的一行

;default_charset = "iso-8859-1"

在这行下面加一行

default_charset = "gb2312"

ok,现在在httpd.conf指定的网页目录下新建index.php,输入

保存,在浏览其中输入localhost,应该能正常显示了吧.

==============================
mysql5.0.27: http://dev.mysql.com/get/Downloads/MySQL-5.0/mysql-5.0.27.tar.gz/from/pick
php5.1.6: http://cn2.php.net/get/php-5.1.6.tar.gz/from/a/mirror
apache 2.0.59: http://mirror.vmmatrix.net/apache/httpd/httpd-2.0.59.tar.gz
GD Library:http://www.boutell.com/gd/http/gd-2.0.33.tar.gz
Zlib: http://www.zlib.net/zlib-1.2.3.tar.gz
libpng: http://prdownloads.sourceforge.net/libpng/libpng-1.2.8-config.tar.gz?download
Jpeg v6b:http://www.ijg.org/files/jpegsrc.v6b.tar.gz
FreeType2:http://jaist.dl.sourceforge.net/sourceforge/freetype/freetype-2.1.10.tar.gz

checking for nl_langinfo and CODESET… yes
checking for tgetent in -lncurses… no
checking for tgetent in -lcurses… no
checking for tgetent in -ltermcap… no
checking for tgetent in -ltinfo… no
checking for termcap functions library… configure: error: No curses/termcap library found
装mysql时出错,需装上ncurses-devel

checking for flex… lex
checking for yywrap in -ll… no
checking lex output file root… ./configure: line 3246: lex: command not found
configure: error: cannot find output from lex; giving up

checking whether to enable LIBXML support… yes
checking libxml2 install dir… no
checking for xml2-config path…
configure: error: xml2-config not found. Please check your libxml2 installation.

装php时出错,需装上lex,libxml2

以上在suse10.0安装通过

Posted in Apache, 技术.

Tagged with , , .


dreamhost子域一度无法添加

demo.c1gstudio.com由于被我加了又删,结果加不上了.

提示”Can’t add domain: already in our DNS system.”

回馈给客服,马上有了回应

—————————————————
Hello,

I’ve gone ahead and manually deleted the subdomain. You should now
be able to readd it!

If there is anything else I can help you with please let me know!

Thanks!
Michael P
————————————————-
这下可以加域名了,但出现”bad_httpd_conf”
————————————————-
客服回复
I just went ahead and restarted Apache for the subdomain and forced a
reset of the DNS settings for it as well. The changes might require a
little timeto take effect, but it should come back up in a few hours,
max.

If you need more help with anything or have any questions, please feel
free to let me know!

Thanks!
Christian
————————————————-
今天早上总算可以访问了,dreamhost的服务还不错。

Posted in 其它.


dreamhost体验

昨天从bluehost迁至dreamhost

又要做设置搬数据,烦。

一。将域名dns解析至dreamhost

ns1.dreamhost.com

ns2.dreamhost.com

二。绑定域名:

1.左边Manage Domains
2.下面add new domain/sub-domain-
3.Domain to host:填入域名(www.c1gstudio.com)
4.PHP Version:
5.1.2 4.4.2 它可以给每一个域名(子域)绑定不同的版本
5.新建一个ftp用户
6.目录名Web Directory: /home/username//
7.提交

等个几分钟他就自动把目录建好
你可使用(系统分配主机名).dreamhost.com/username/password来上传
域名半小时左右就可以访问,要看人品啦。

评价:子域和php版本都比bh方便,bh的域名包括子域都混在一个目录,很乱。
bh也支持php5(默认php4)但需要写信给support,让他们手工迁移,当然也不支持每个域名一个php版本了。
域名解析速度基本一样。

三。添加子域

和上面的一样
记得选Remove "www." if somebody goes to http://www.domain.com/

ps:删除一个子域再加时需要等很长一段时间。
每次加域名的ip可能不同。

四。ftp上传时有些问题

系统不支持"续传",有时上传的文件只能上去一半(Transfer aborted. Link to file server lost.),不能覆盖,删掉重传也一样。
很郁闷。
上传和下载20KB/s左右。
评价:ftp比bh烂一点,但速度要快。

五。shell

在users->manage users中建立

你也可将ftp账号增加shell功能,这样ftp传上zip包再解压就方便了(unzip xxx.zip)。

评价:bh需写信开通,dh方便多了。

六。关于默认的列表

建一.htacess文件包含

Options -Indexes

好像panel里也可以设,没他细看。

评价:和bh一样默认也会显示列表

Posted in LINUX, 技术.


suse的使用记录

一些快捷键
Ctrl+Alt+D
快速返回桌面

ctrl+alt+left/right
前一个桌面/后一个桌面

scim输入法
ctrl+space 关闭打开输入法
shift中英切换
ctrl+.(句号)中英文标点切换
alt(长按)+shift 多输入法切换

firefox
ctrl+t new tab
ctrl+n new window
ctrl+w close tab
alt+left/right 前进/后退
ctrl+tab,ctrl+shieft+tab,alt+(1,2,3…) tab切换

Posted in LINUX, 技术.


dom操作select,增加选项


document.all(“authorid”).options.remove(0);
document.all(“authorid”).options.add(new Option(name,value));

下面的例子给出了一个完整的演示。由于看例子比我解说更容易理解,所以我就废话少说,把代码贴出,希望对大家需要的网友有一点帮助。




First Sample:
All items will change After you Selected!

Second Sample:
You selected Item in Main Select will change the Sub select Content!

Main Select:

Sub Select:

Posted in JavaScript/DOM/XML, 技术.


MySQL 表的别名的真正用法

转自http://www.coolcode.cn/?p=51

用 MySQL 很久了,一直被 MySQL 中没有嵌套查询所困扰,虽然 MySQL 4.1 中支持这个特性,但是我的 PHP 的程序都使用的 MySQL 函数库,而不是 MySQLi 函数库,所以 4.1 的特性用不上。

以前遇到需要嵌套查询的地方,一般转化为两个表的连接查询来解决。可是最近做的一个程序里面,发现需要嵌套查询的地方是对同一个表进行的两次查询,所以没法直接转化为两个表的连接查询。要转化为用 PHP 代替 MySQL 做这种事实在是太麻烦了(以前就干过这种傻事),于是一直想找个简单的替代法。也许是灵感突发,也许是最近天天再翻 MySQL 手册对 MySQL 的查询有了更深入的理解,今天忽然想到可以用表的别名来解决这个问题。

以前一直以为表的别名只是为了能够让 SQL 语句能够简短一些,没有其他用处,今天经过实验才发现,原来给表起不同的别名可以让一个表当多个表用。举个我程序中的例子来说明一下:

我的程序中有一个分类表,为了实现无限多级分类,我在分类表中有一个 parent_id 字段,这个字段保存的是这条记录所代表的分类的父分类 id 号,如果这个字段为 null,则表示顶级分类。现在我需要删除一个分类,这个分类可能有子分类,因此,删除这个分类以后,它的子分类的 parent_id 号就需要改变一下,而不能继续指向这个不存在的分类,因此我希望删除这个分类以后,它的子分类的父分类变为它的父分类。遇到这种情况,以前我就不知道该怎么办好,现在好了,用下面的语句就可以了:

  1. lock tables `categories` write, `categories` as `c1` write, `categories` as `c2` write;
  2. update `categories` as `c1`, `categories` as `c2` set `c1`.`parent_id` = `c2`.`parent_id` where `c1`.`parent_id` = `c2`.`cat_id` and `c2`.`cat_id` = $cat_id;
  3. delete from `categories` where `cat_id` = $cat_id;
  4. unlock tables;

这里需要注意的一点是,锁定表的时候,一定要把要操作的表和表的别名都锁定,否则下面的语句会出错。

当我兴奋的把这个发现告诉 Legend 时,他说他早就这么用了。早知道了也不告诉我,鄙视一下。顺便跟大家共享一下这个“发现”。如果你也早知道了,不要鄙视我!

Posted in Mysql, 技术.


关于cookie中的数据读出时带斜杠

当magic_quotes_gpc=on。
所有从GET/POST/Cookie来的变量的单引号(‘)、双引号(“)、反斜杠backslash()以及空字元NUL
(the null byte)都会被加上反斜杠

在文本框中输入一个单引号,显示会变成三个斜杠一个单引号

当你接收$_POSTt数据时自动加一个斜杠,然后取$_COOKIE又会加一次斜杠所以变成三个斜杠一个单引号.

你需要在存和取时根据magic_quotes_gpc各去一次斜杠就可以显示原文本内容。

Posted in PHP, 技术.


auto_prepend_file 文件

A apache中设置,但他会覆盖php.ini中的设置

……………………………..

php_admin_value include_path ".:/usr/lib/php/php:/var/www/html/sso/include"

php_value auto_prepend_file "josso-lib/josso.php"

B php.ini中设置

auto_prepend_file 不支持多个文件

可以预加载中include

Posted in PHP, 技术.


查看端口占用程序

xampp有时启动时端口会被svchost占用。
netstat -nao得到pid

任务管理器,查看->选择列,显示pid

kill~~

或者
ntsd -c q -p 进程id

Posted in 其它.


如何在linux下共享windows的文件

台机无法启动至win2k.备份的ghost居然也坏了,只能重装。

准备使用购bb时送的备份盘重装。

1.bb xp下共享文件夹

2.台机 linux下
linux:/ # smbclient //192.168.1.101/t43 -U administrator
Password:
Domain=[ANDY] OS=[Windows 5.1] Server=[Windows 2000 LAN Manager]
smb: > ls
Software DR 0 Fri Jul 1 17:46:40 2005
XP.GHO R 2147453030 Mon May 23 14:54:14 2005
XP000001.GHS R 263446022 Mon May 23 14:54:14 2005
dostools DR 0 Fri Jul 1 13:14:25 2005
ghost.exe R 1394212 Thu Jan 1 00:00:00 2004

63404 blocks of size 65536. 0 blocks available

你也可以使用mount,使用更方便

smb: > exit
linux:/ # smbmount //192.168.1.101/t43 /t43 -o username=administrator
Password:
linux:/ # cd /t43
linux:/t43 # ls
. .. Software XP.GHO XP000001.GHS dostools ghost.exe
linux:/t43 #

3.将ghost文件copy至原win2k的d:

4.重启,dos,ghost

Posted in LINUX, 技术.