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 , , .


No Responses (yet)

Stay in touch with the conversation, subscribe to the RSS feed for comments on this post.



Some HTML is OK

or, reply to this post via trackback.