13日wd 发表于 2015-12-17 09:13:55

编译方式搭建LAMP环境httpd-2.2.31+mysql-5.6.27+php-5.6.14

一、安装编译工具和依赖包

# yum -y install gc gcc-c++ pcre-devel ncurses-devel openssl-devel libpng-devel libtool libxslt-devel libxml2-devel libXpm-devel curl-devel


二、安装PHP和MySQL所需要的软件

1、安装cmake

# ./bootstrap
# make && make

2、安装freetype
# ./configure --prefix=/usr/local/freetype
# make

3、安装libmcrypt
# ./configure --prefix=/usr/local/libmcrypt
# make

4、安装libiconv
# ./configure --prefix=/usr/local/libiconv
# make install

5、安装jpeg-6b
# cd jpeg-6b/
# mkdir /usr/local/jpeg6
# mkdir /usr/local/jpeg6/bin
# mkdir /usr/local/jpeg6/lib
# mkdir /usr/local/jpeg6/include
# mkdir /usr/local/jpeg6/man/man1 -p
# cp /usr/share/libtool/config/config.sub .
cp: overwrite `./config.sub'? y
# cp /usr/share/libtool/config/config.guess .
cp: overwrite `./config.guess'? y
# ./configure --prefix=/usr/local/jpeg6 --enable-shared --enable-static
# make

6、安装gd2
# ./configure --prefix=/usr/local/libgd2 --with-zlib --with-jpeg=/usr/local/jpeg6 --with-png --with-freetype=/usr/local/freetype



三、安装mysql
1、创建mysql用户
# groupadd mysql
# useradd -r -g mysql mysql

2、编译安装mysql
# cmake . \
> -DCMAKE_INSTALL_PREFIX=/usr/local/mysql \
> -DMYSQL_DATADIR=/var/lib/mysql \
> -DSYSCONFDIR=/etc \
> -DWITH_INNOBASE_STORAGE_ENGINE=1 \
> -DWITH_MYISAM_STORAGE_ENGINE=1 \
> -DWITH_MEMORY_STORAGE_ENGINE=1 \
> -DWITH_READLINE=1 \
> -DMYSQL_UNIX_ADDR=/var/lib/mysql/mysql.sock \
> -DMYSQL_TCP_PORT=3306 \
> -DENABLED_LOCAL_INFILE=1 \
> -DWITH_PARTITION_STORAGE_ENGINE=1 \
> -DEXTRA_CHARSETS=all \
> -DDEFAULT_CHARSET=utf8 \
> -DDEFAULT_COLLATION=utf8_general_ci

-- Configuring done
-- Generating done
CMake Warning:
Manually-specified variables were not used by the project:

    WITH_MEMORY_STORAGE_ENGINE
    WITH_READLINE


-- Build files have been written to: /usr/local/src/mysql-5.6.27


# gmake
# gmake install

3、修改/usr/local/mysql文件权限

# chown -R mysql:mysql /usr/local/mysql
# ll -d /usr/local/mysql
drwxr-xr-x 13 mysql mysql 4096 Dec 14 12:08 /usr/local/mysql

4、创建数据库存储目录

# mkdir /var/lib/mysql
# chown mysql. /var/lib/mysql

5、安装系统数据库

# ./mysql_install_db --basedir=/usr/local/mysql --datadir=/var/lib/mysql --no-defaults --user=mysql

# ls /var/lib/mysql/
ibdata1ib_logfile0ib_logfile1mysqlperformance_schematest


6、复制配置文件

# cd /usr/local/mysql/support-files/
# ls
binary-configuremagic my-default.cnf mysqld_multi.servermysql-log-rotatemysql.server


# cp my-default.cnf /etc/my.cnf
cp: overwrite `/etc/my.cnf'? y

# vim /etc/my.cnf    //修改配置
basedir = /usr/local/mysql
datadir = /var/lib/mysql
port = 3306
# server_id = .....
socket = /var/lib/mysql/mysql.sock


7、添加启动脚本并设置开机启动

# cp mysql.server /etc/rc.d/init.d/mysqld
# chmod +x /etc/rc.d/init.d/mysqld

# service mysqld start
Starting MySQL.. SUCCESS!
# chkconfig --add mysqld
# chkconfig mysqld on

8、登录mysql

# /usr/local/mysql/bin/mysql
Welcome to the MySQL monitor.Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.6.27 Source distribution

Copyright (c) 2000, 2015, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql>




四、安装apache2
1、安装apr和apr-util

# ./configure --prefix=/usr/local/apr
# ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr

2、编译安装apache2
# ./configure \
--prefix=/usr/local/apache2 \
--sysconfdir=/etc/httpd \
--with-included-apr \
--with-apr=/usr/local/apr \
--with-apr-util=/usr/local/apr-util \
--enable-so \
--enable-deflate=shared \
--enable-expires=shared \
--enable-rewrite=shared \
--with-pcre \
--enable-mem-cache \
--enable-cache \
--enable-static-support \
--with-z



# make

# make install
make: Leaving directory `/usr/local/src/httpd-2.2.31'
# echo $?
0

# ls /usr/local/apache2/
binbuildcgi-binerrorhtdocsiconsincludeliblogsmanmanualmodules

# /usr/local/apache2/bin/apachectl start
(98)Address already in use: make_sock: could not bind to address [::]:80
(98)Address already in use: make_sock: could not bind to address 0.0.0.0:80
no listening sockets available, shutting down
Unable to open logs

# netstat -tnlp | grep 80
tcp      0      0 :::80                     :::*                        LISTEN      2112/httpd

# rm -rf /usr/local/apache2
# rm -rf httpd-2.2.31
# rm -rf /etc/httpd

reboot

# netstat -tnlp | grep 80

# ./configure --prefix=/usr/local/apache2 --sysconfdir=/etc/httpd --with-included-apr --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util --enable-so --enable-deflate=shared --enable-expires=shared --enable-rewrite=shared --with-pcre --enable-mem-cache --enable-cache --enable-static-support --with-z


# /usr/local/apache2/bin/apachectl start
# netstat -tnlp | grep 80
tcp      0      0 :::80                     :::*                        LISTEN      50223/httpd

# /usr/local/apache2/bin/apachectl -t
Syntax OK

3、创建启动脚本

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



五、安装PHP
1、编译安装php
# ./configure \
> --prefix=/usr/local/php \
> --with-config-file-path=/usr/local/php/etc \
> --with-apxs2=/usr/local/apache2/bin/apxs \
> --with-mysql=/usr/local/mysql \
> --with-gd=/usr/local/libgd2 \
> --with-jpeg-dir=/usr/local/jpeg6 \
> --with-freetype-dir=/usr/local/freetype \
> --with-mcrypt=/usr/local/libmcrypt \
> --with-mysqli=/usr/local/mysql/bin/mysql_config \
> --with-libxml-dir \
> --with-zlib-dir \
> --with-png-dir \
> --with-iconv-dir=/usr/local/libiconv \
> --with-openssl \
> --with-curl \
> --enable-soap \
> --enable-gd-native-ttf \
> --enable-mbstring \
> --enable-sockets \
> --enable-exif \
> --disable-ipv6 \
> --enable-ftp \
> --with-mhash \
> --with-pcre-dir=/usr/bin/pcre-config \
> --enable-zip \
> --with-bz2


报错:

configure: error: Please reinstall the BZip2 distribution
# yum install -y bzip2 bzip2-devel


Wrote PEAR system config file at: /usr/local/php/etc/pear.conf
You may want to add: /usr/local/php/lib/php to your php.ini include_path
/usr/local/src/php-5.6.14/build/shtool install -c ext/phar/phar.phar /usr/local/php/bin
ln -s -f phar.phar /usr/local/php/bin/phar
Installing PDO headers:          /usr/local/php/include/php/ext/pdo/

# echo $?
0
# ls /usr/local/php/
binetcincludelibphp



2、测试php

# ls /usr/local/apache2/htdocs/index.html
/usr/local/apache2/htdocs/index.html
# cat !$
cat /usr/local/apache2/htdocs/index.html
<html><body><h1>It works!</h1></body></html>#


# vim /etc/httpd/httpd.conf//修改配置


<IfModule dir_module>
    DirectoryIndex index.html index.php
</IfModule>


    AddType application/x-compress .Z
    AddType application/x-gzip .gz .tgz
    AddType application/x-httpd-php .php .phtml


创建测试页面

# vim /usr/local/apache2/htdocs/index.php

<?php
phpinfo();
?>



# cp php.ini-production /usr/local/php/etc/php.ini

重新加载php配置:
# /usr/local/apache2/bin/apachectl graceful
页: [1]
查看完整版本: 编译方式搭建LAMP环境httpd-2.2.31+mysql-5.6.27+php-5.6.14