Linux下 php5 MySQL5 Apache2 安装与配置

来源:互联网 发布:mac上能玩的格斗游戏 编辑:程序博客网 时间:2024/05/07 00:28

 

 

mkdir /downloads

chown -R root:root /downloads

chmod -R 774 /downloads

 

一、安装Apache2

    下载地址:http://www.apache.org/ --> HTTP Server --> from a mirror

 

    1. 获取mysql源码

        shell> cd /downloads

        shell> wget http://apache.etoak.com/httpd/httpd-2.2.11.tar.gz

    2. 想解压缩包,进入该目录    

        shell> tar zxvf httpd-2.2.11.tar.gz

        shell> cd httpd-2.2.11/

    3. 编译安装,自定义安装目录。    

        shell> ./configure --prefix=/usr/local/apache --enable-so --enable-rewrite  ##注:apache 1.3.* 与apache 2.*.* 不同 可以用./configure --help查看

        shell> make && make install

    4. 启动Apache2。

        shell> /usr/local/apache/bin/apachectl start

 

二、安装MySQL5

    下载地址:http://www.mysql.com/ --> downloads --> MySQL Community Server

 

    1. 添加mysql用户和用户组:

        shell> groupadd mysql

        shell> useradd -g mysql mysql

 

    2. 获取mysql源码

        shell> cd /downloads 

        shell> wget http://dev.mysql.com/get/Downloads/MySQL-5.1/mysql-5.1.36.tar.gz/from/http://mysql.stu.edu.tw/ 

 

    3. 想解压缩包,进入该目录

        shell> tar zxvf mysql-5.1.36.tar.gz 

        shell> cd mysql-5.1.36/

 

 

    4. 编译安装,自定义安装目录。

        shell> ./configure --prefix=/usr/local/mysql  ##–with-charset=utf8 –with-collation=utf8_general_ci –with-extra-charsets=utf8

        shell> make

        shell> make install

 

    5. 复制mysql配置文件到 /etc/my.cnf文件,

        shell> cp support-files/my-medium.cnf /etc/my.cnf

 

    6. 进入安装目录。

        shell> cd /usr/local/mysql

 

    7. 安装数据库 

        shell> bin/mysql_install_db --user=mysql

 

    8. 改变mysql目录权限

        shell> chown -R root  .  #将文件的所有属性改为root用户。

 

        shell> chown -R mysql var #将数据目录的所有属性改为mysql用户

 

        shell> chgrp -R mysql . #将组属性改为mysql组。

 

    9. 安装好以后测试启动服务器

        shell> bin/mysqld_safe --user=mysql &

 

    10. 修改root 密码

        shell> bin/mysqladmin -uroot -p password 123456  //1234为新密码

 

三、安装GD库

    GD库地址:

        http://www.libgd.org *版本gd-2.0.35.tar.gz

    FreeType地址:

        http://sourceforge.net/projects/freetype/ *版本freetype-2.3.8.tar.gz

    Libpng地址:

        http://sourceforge.net/projects/libpng/ *版本libpng-1.2.37.tar.gz

    JPEG地址:

        http://www.ijg.org/ *版本jpegsrc.v7.tar.gz

 

    安装步骤:

    先安装freetype,libpng,jpeg,再装GD 如果没有zlib则装之

 

    1.安装libpng

        shell> tar zxvf libpng-1.2.37.tar.gz

        shell> cd libpng-1.2.37

        shell> cp scripts/makefile.std makefile 

        shell> make && make install

        注意,这里的makefile不是用./configure生成,而是直接从scripts/里拷一个

 

    2.安装freetype

        shell> cd /downloads

        shell> tar zxvf freetype-2.3.8.tar.gz

        shell> cd freetype-2.3.8

        shell> ./configure --prefix=/usr/local/freetype

        shell> make && make install

 

    3.安装Jpeg

        shell> cd /downloads

        shell> tar zxvf jpegsrc.v7.tar.gz

        shell> cd jpeg-7/

        shell> ./configure  --prefix=/usr/local/jpeg7 --enable-shared

        shell> make && make install

 

        注意,这里configure一定要带–enable-shared参数,不然,不会生成共享库

 

    4.安装GD

        shell> cd /downloads

        shell> tar zxvf gd-2.0.35.tar.gz

        shell> cd gd-2.0.35

        shell> ./configure --prefix=/usr/local/gd2 --with-jpeg=/usr/local/jpeg7/ --with-png --with-freetype=/usr/local/freetype/ --with-zlib

        shell> make install  

 

四、安装php5

    注:在安装PHP之前需要安装其所需插件 如:gd库、curl库、libxml2、libxslt等,其中libxml2是必须的

 

    php下载地址:

        http://www.php.net/ --> downloads --> http://cn2.php.net/get/php-5.2.9.tar.gz/from/cn.php.net/mirror *版本:php-5.2.9.tar.gz

    libxml2地址:

        http://xmlsoft.org/downloads.html *版本:libxml2-2.7.3.tar.gz

    libxslt地址:

        http://xmlsoft.org/XSLT/downloads.html *版本:libxslt-1.1.22.tar.gz

    curl下载地址:

        http://curl.haxx.se/download.html *版本:curl-7.19.5.tar.gz

 

 

    1. 安装libxml2

        shell> cd /downloads

        shell> tar -zxf libxml2-2.7.3.tar.gz

        shell> cd libxml2-2.7.3

        shell> ./configure --prefix=/usr/local/libxml2

        shell> make && make install

 

    2. 安装libxslt

        shell> cd /downloads

        shell> tar -zxf libxslt-1.1.22.tar.gz

        shell> cd libxslt-1.1.22

        shell> ./configure --prefix=/usr/local/libxslt --with-libxml-prefix=/usr/local/libxml2

        shell> make && make install

 

    3. 安装curl

        shell> cd /downloads

        shell> tar -zxf curl-7.19.5.tar.gz

        shell> cd curl-7.19.5

        shell> ./configure --prefix=/usr/local/curl

        shell> make && make install

 

 

    4. 安装php

        shell> cd /downloads 

        shell> wget http://cn2.php.net/get/php-5.2.9.tar.gz/from/cn.php.net/mirror 

        shell> tar zxvf php-5.2.9.tar.gz 

        shell> cd php-5.2.9/

        shell> ./configure  --prefix=/usr/local/php --with-apxs2=/usr/local/apache/bin/apxs --with-mysql=/usr/local/mysql/ --with-curl=/usr/local/curl --with-libxml-dir=/usr/local/libxml2 --enable-soap --with-xsl=/usr/local/libxslt --with-gd=/usr/local/gd2/ --with-jpeg-dir=/usr/local/jpeg7/ --with-zlib-dir=/usr/lib --with-png-dir --with-freetype-dir=/usr/local/freetype --enable-mbstring

        shell> make && make install

 

    5. 复制PHP配置文件

        shell> cp php.ini-dist /usr/local/lib/php.ini

 

五、apache整合PHP

 

    配置 httpd.conf 让apache支持PHP

    # vi /usr/local/apache/conf/httpd.conf

    找到 AddType application/x-gzip .gz .tgz 在其下添加如下内容

    AddType application/x-httpd-php .php

    AddType application/x-httpd-php-source .phps

 

    重启apache

    # /usr/local/apache/bin/apachectl restart

 

    在这里有一个问题,如果你的系统安装了SELinux模块,那么由于安全控制的原因,会出现如下错误:

    Starting httpd: Syntax error on line 191 of /etc/httpd/conf/httpd.conf:

    Cannot load /etc/httpd/modules/libphp5.so into server: libxml2.so.2: failed to map segment from shared object: Permission denied

 

    解决:这样需要我们到指定的库文件的目录下执行如下命令:

    restorecon libxml2.so.2.6.19

    把类似的错误都解决之后,Apache就可以正常启动了。

 

六、mysql、apache设置为开机自动启动

 

    1. mysql设为linux服务

        cp /usr/local/mysql5/share/mysql/mysql.server /etc/init.d/mysqld

        chkconfig --add mysqld

        chkconfig --level 2345 mysqld on

        service mysqld start

 

    2. apache设为linux服务

        cp /usr/local/apache2/bin/apachectl /etc/init.d/httpd

        vi /etc/init.d/httpd

 

        在在#!/bin/sh后面加入下面两行

        #chkconfig:345 85 15

        #description: Start and stops the Apache HTTP Server.

 

        然后

        chmod +x /etc/rc.d/init.d/httpd

        chkconfig --level 2345 mysqld on

        service mysqld start

原创粉丝点击