龙岩易富通网络科技有限公司

龙岩小程序开发,龙岩分销系统

Debian+Apache2+MySQL5+PHP5+GD安装

2015.09.10 | 1009阅读 | 0条评论 | linux


Debian+Apache2+MySQL5+PHP5+GD


所有资源来源于网络.本文可以任意修改,转载,复制...

虽然是在Debian下配置的,由于是源码包安装的,所以应该也适用于其他Linux发行版.


首先,准备好软件包:

  最新的Apache,MySQL和PHP可以去相对的官方网站去下载,下载到/tmp/src/目录下: 

MySQL5:      http://dev.mysql.com/get/Downloa ... 27.tar.gz/from/pick

  PHP5.2.0:      http://cn2.php.net/get/php-5.2.0.tar.bz2/from/cn.php.net/mirror

  Apache2.0.59:   http://httpd.apache.org/download.cgi

  GD Library:    https://github.com/libgd/libgd/archive/gd-2.2.4.tar.gz

  Zlib:               http://www.zlib.net/zlib-1.2.11.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.com/bbs/view ... &extra=page%3D1


所有操作都是以root用户来进行的.

        解压:

        对于*.tar.gz的文件使用命令tar zxvf *.tar.gz来解压;

        对于*.tar.bz2的文件使用命令tar jxvf *.tar.bz2来解压.

        将mysql,php,apache以及gd安装到/usr/local/目录下,便于管理.

        编译安装MySQL:

        进入到解压后的mysql目录,在终端输入下面的命令:


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


--prefix=/usr/local/mysql 把mysql-4.0.16指定安装到/usr/local/mysql目录中;

--with-extra-charsets=all 对多语言的支持;

--with-unix-socket-path=/usr/local/mysql/var/mysql.sock 这个是指定mysql服务器启动后,联机套接字文件所处的位置和文件名,也就是说,如果mysql服务器成功启动后,就能在/usr/local/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 /usr/local/mysql/share/mysql/my-medium.cnf /etc/my.cnf

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

运行

/usr/local/mysql/bin/mysql_install_db

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

        chmod 755 /usr/local/mysql/var     //设置/usr/local/mysql/var的目录权限为755

        chown -R username:username /usr/local/mysql/var  //如果希望使用username这个用户来启动mysql的话

        /usr/local/mysql/share/mysql/mysql.server start      //启动mysql服务

        chown -R username:username /usr/local/mysql/      //把/usr/local/mysql目录归属到username这个用户下

        /usr/local/mysql/bin/mysqladmin -u root password 123456  //设置root用户的密码为123456


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


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


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


--prefix=/usr/local/apache 指定把apahce安装到/usr/local/apache目录中;

--enable-cgi 支持CGI;

--with-config-file-path=/usr/local/apache/conf 指定把apache的配制文件放在/usr/local/apache/conf中;比如httpd.conf配制文件就在这个目录中;

--enable-track-vars 为启动cookie的get/post等追踪功能编译安装:

make

make install 


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


/usr/local/apache/bin/apachectl start 


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

配制apache


配制文件是/usr/local/apache/conf/httpd.conf

编译安装的apache默认存放主页的位置应该是/usr/local/apache/htdocs

这个目录。

在httpd.conf中比较重要的几项:


ServerRoot "/usr/local/apache"


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


Listen 80


apache 默认端口80


ServerAdmin root@localhost


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


#ServerName new.host.name:80 


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


DocumentRoot "/usr/local/apache/htdocs" 


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


<directory "="" 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.

#

<!--more-->

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


</directory>



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


/usr/local/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=/usr/local/php --with-apxs2=/usr/local/apache2/bin/apxs \  
--with-gd --enable-gd --enable-gd-native-ttf --with-jpeg-dir --with-png \
--with-ttf--with-zlib --with-freetype-dir=/usr/local/freetype --enable-magic-quotes \
--with-mysql=/usr/local/mysql --with-mysqli=/usr/local/mysql/bin/mysql_config --with-mbstring \
--enable-mbstring --with-mcrypt --with-openssl --with-config-file-path=/usr/local/lib \
--with-pdo-mysql --enable-pdo-mysql --with-curl

make

make install 


复制php.ini-dist为php.ini,并存放到/usr/local/php/etc/目录下.

编辑/usr/local/php/etc/php.ini文件,找到如下的一行


;default_charset = "iso-8859-1"


在这行下面加一行


default_charset = "gb2312"


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



<?php 

phpinfo();

?>


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


赞 (

发表评论