Home > php教程 > php手册 > 在Ubuntu中使用源码编译安装Apache+MySQL+PHP+phpMyAdmin

在Ubuntu中使用源码编译安装Apache+MySQL+PHP+phpMyAdmin

WBOY
Release: 2016-06-06 19:57:49
Original
994 people have browsed it

操作系统:ubuntu12.04LTS(64位) 编译安装的步骤如下: 检查安装的编译工具 编译过程中需要C的编译器,C的编译器,make,和编译mysql最新版本时需要的cmake。 检查编译器软件是否安装的命令是: dpkg –l | grep filename 依次检查gcc,g,make,cmake是否

操作系统:ubuntu12.04LTS(64位)

编译安装的步骤如下:

检查安装的编译工具

编译过程中需要C的编译器,C++的编译器,make,和编译mysql最新版本时需要的cmake。

检查编译器软件是否安装的命令是:

dpkg –l | grep filename
Copy after login

依次检查gcc,g++,make,cmake是否安装

检查是否已经有默认安装的软件,并卸载

如果已经安装过Apache,mysql,php需要先停止服务,卸载先前的软件后再工作

卸载软件的命令

apt-get remove –purge softname
dpkg –r xxx.deb
Copy after login

编译安装libxml2

下载地址:libxml2-2.9.0.tar.gz

cd /usr/local/src
tar –zvxf libxml2-2.9.0.tar.gz
cd libxml2-2.9.0
./configure –prefix=/usr/local/libxml2
make
sudo make install
Copy after login

编译安装libmcrypt

下载地址:libmcrypt-2.5.7.tar.gz

cd /usr/local/src
tar –zvxf libmcrypt-2.5.7.tar.gz
cd libmcrypt-2.5.7
./configure --prefix=/usr/local/libmcrypt
make
sudo make install
Copy after login

编译安装zlib

下载地址:zlib-1.2.8.tar.gz

cd /usr/local/src
tar –zvxf zlib-1.2.8.tar.gz
cd zlib-1.2.8
./configure
make
sudo make install
Copy after login

注意安装zlib库的时候不能指定它的安装路径,否则安装后面库的时候会找不到zlib的位置,手动指定路径也无法解决

安装libpng库

下载地址:libpng-1.6.7.tar.gz

cd /usr/local/src
tar –zvxf libpng-1.6.7.tar.gz
cd libpng-1.6.7
./configure --prefix=/usr/local/libpng
make
sudo make install
Copy after login

如果上一步的zlib库指定了特定的安装路径,在这里configure的时候会提示zlib没有安装问题,此时回到zlib的源代码执行

make clean重新编译安装

安装jpeg6

下载地址:jpegsrc.v6b.tar.gz

需要手动创建安装需要的目录,在安装时不能自动创建

mkdir /usr/local/jpeg6
mkdir /usr/local/jpeg6/bin
mkdir /usr/local/jpeg6/lib
mkdir /usr/local/jpeg6/include
mkdir –p /usr/local/jpeg6/man/man1
cd /usr/local/src
tar –zvxf jpegsrc.v6b.tar.gz
cd jpeg-6b
./configure --prefix=/usr/local/jpeg6 –enable-shared –enable-static
make
sudo make install
Copy after login

可能出现的错误:make: ./libtool:命令未找到(解决办法参考这篇文章:Linux 安装 jpeg-6b 出错:./libtool 命令未找到)

安装freetype

下载地址:freetype-2.4.10.tar.gz

cd /usr/local/src
tar –zvxf freetype-2.4.10.tar.gz
cd freetype-2.4.10
./configure --prefix=/usr/local/freetype
make
sudo make install
Copy after login

出错信息及解决办法参考这篇文章:Linux下编译安装freetype出错信息及解决办法以及这篇文章:编译安装 freetype 报错 make: [install] 错误 1 (忽略) 及解决办法

安装autoconf库

下载地址:autoconf-2.68.tar.gz

安装autoconf需要安装m4软件,不然configure不会通过的,而且最好默认安装,不指定prefix,否则后面安装php扩展会比较麻烦。

cd /usr/local/src
tar –zvxf autoconf-2.68.tar.gz
cd autoconf-2.68
./configure
make
sudo make install
Copy after login

安装gd库

下载地址:gd-2.0.35.tar.gz

cd /usr/local/src
tar –zvxf gd-2.0.35.tar.gz
cd gd-2.0.35
./configure --prefix=/usr/local/gd2 --with-jpeg=/usr/local/jpeg6 --with-png=/usr/local/libpng --with-freetype=/usr/local/freetype
make
sudo make install
Copy after login

在安装gd库的时候会出现找不到png库的情况,这时我们需要手动修改gd_png.c文件,找到

#include "png.h"

修改为真正的png库位置

安装Apache服务器

下载地址:httpd-2.2.26.tar.gz

cd /usr/local/src
tar –zvxf httpd-2.2.26.tar.gz
cd httpd-2.2.26
./configure --prefix=/usr/local/apache2 --sysconfdir=/etc/httpd --with-include-apr --disable-userdir --enable-so --enable-deflate=shared --enable-expires=shared --enable-rewrite=shared --enable-static-support
make
sudo make install
Copy after login

安装Apache会出现依赖库的问题,需要提前安装apr,apr-util,pcre 安装方法就是正常的编译安装(可参考这篇文章:Ubuntu下使用源代码编译安装apache2.2.26)

启用apache服务

cp /usr/local/apache2/bin/apachectl /sbin/
apachectl start
netstat -tnl | grep 80
vim /etc/rc.loacl
Copy after login

安装mysql数据库

下载地址:mysql-5.5.25a.tar.gz

cd /usr/local/src
tar –zvxf mysql-5.5.25a.tar.gz
cd mysql-5.5.25a
cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_DATADIR=/usr/local/mysql/data -DEXTRA_CHARSETS=all -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DWITH_READLINE=1 -DWITH_SSL=bundled -DWITH_EMBEDDED_SERVER=1 -DENABLED_LOCAL_INFILE=1 -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITHOUT_PARTITION_STORAGE_ENGINE=1 -DWITH_DEBUG=0
make
sudo make install
Copy after login

安装过程会出现的错误及解决办法参考这篇文章:Ubuntu12.04编译安装MySQL 5可能出现的错误及解决办法

创建mysql 用户

groupadd mysql
useradd -r -g mysql mysql
Copy after login

权限设置及授权表的安装

cd /usr/local/mysql
chown -R mysql .
chgrp -R mysql .
scripts/mysql_install_db --user=mysql
chown -R root .
chown -R mysql data
Copy after login

创建配置文件

cp support-files/my-medium.cnf /etc/my.cnf
Copy after login

启动mysql服务

bin/mysql_safe --user=mysql&
netstat -tnl | grep 3306
Copy after login

配置mysql服务

cp support-files/mysql.server /etc/init.d/mysql
sudo update-rc.d mysql defaults
chkconfig --add mysql
chkconfig mysql on
Copy after login

用户账户控制

bin/mysql -uroot
mysql> DELETE mysql.user WHERE Host='localhost'AND User='';
mysql>SET PASSWORD FOR 'root'@'localhost'=PASSWORD('123456');
Copy after login

启动报错:无法启动Couldn't find MySQL server (/usr/bin/mysqld_safe)”

sudo rm /etc/mysql/my.cnf
Copy after login

即可。

安装PHP5.3

下载地址:php-5.3.28.tar.gz

cd /usr/local/src
tar –zvxf php-5.3.28.tar.gz
cd php-5.3.28
./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --with-apxs2=/usr/local/apache2/bin/apxs --with-pdo-mysql=/usr/local/mysql --with-libxml-dir=/usr/local/libxml2 --with-png-dir=/usr/local/libpng --with-jpeg-dir=/usr/local/jpeg6 --with-freetype-dir=/usr/local/freetype --with-gd=/usr/local/gd2 --with-mcrypt=/usr/local/libmcrypt --enable-soap --enable-mbstring=all --enable-sockets
make
sudo make install
Copy after login

在PHP5.4 make会出现一个问题

我们需要修改gd库目录下的include/gd_io.h

vi <gd_dir>/include/gd_io.h</gd_dir>
Copy after login

gdIOCtx结构中增加void *data;

格式如下:

typedef struct gdIOCtx
{
    int (*getC) (struct gdIOCtx *);
    int (*getBuf) (struct gdIOCtx *, void *, int);
    void (*putC) (struct gdIOCtx *, int);
    int (*putBuf) (struct gdIOCtx *, const void *, int);
    /* seek must return 1 on SUCCESS, 0 on FAILURE. Unlike fseek! */
    int (*seek) (struct gdIOCtx *, const int);
    long (*tell) (struct gdIOCtx *);
    void (*gd_free) (struct gdIOCtx *);
    void (*data);
}
gdIOCtx;
Copy after login

创建PHP配置文件

cp php.ini-development /usr/local/php/etc/php.ini
Copy after login

添加apache对PHP的支持

vi /etc/httpd/httpd.conf
Addtype application/x-httpd-php .php .phtml
sudo apachectl stop
sudo apachectl start
Copy after login

在Apache的web根目录下创建phpinfo.php

<?php phpinfo();
?>
Copy after login

测试环境是否安装成功

基本上就装完了。

安装配置phpMyAdmin:

下载地址:phpMyAdmin-4.1.1-all-languages.zip

unzip phpMyAdmin-4.1.1-all-languages.zip
mv phpMyAdmin-4.1.1-all-languages.zip phpmyadmin
mv phpmyadmin /var/www/(假设/var/www为web根目录)
cd /var/www/phpmyadmin
cp config.sample.inc.php config.inc.php
vi config.inc.php
Copy after login

将其中的

$cfg['Servers'][$i]['extension'] = 'mysqli';
Copy after login

修改为:

$cfg['Servers'][$i]['extension'] = 'mysql';
Copy after login

保存退出,然后在浏览器中就可以通过http://localhost/phpmyadmin来访问phpMyAdmin了。


Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template