[置顶] DayDayUP_Linux运维学习_LAMP的安装

注意: 系统版本: centos6.5 32 位
httpd-2.4.16
mysql-5.6.27
php-5.6.14

1 准备工作

1.1下载mysql

1.1.1源码版(通用)

# wget http://cdn.mysql.com/Downloads/MySQL-5.6/mysql-5.6.27.tar.gz

1.1.2二进制版(通用)

# wget http://cdn.mysql.com/Downloads/MySQL-5.6/mysql-5.6.27-linux-glibc2.5-i686.tar.gz

1.1.3 其他版本

http://dev.mysql.com/downloads/  //自行下载相应的安装包

1.2 下载appache httpd

# wget http://www.carfab.com/apachesoftware//httpd/httpd-2.4.16.tar.gz

1.3 下载php

# wget http://cn2.php.net/distributions/php-5.6.14.tar.gz

2 安装mysql(源码安装)

2.1新建用户与目录

# groupadd mysql
# useradd -r -g mysql mysql //-r参数表明创建的是系统用户,不会创建家目录
# mkdir -p /usr/local/mysql
# mkdir -p /data/mysql
# chown -R mysql:mysql /data/mysql
# chown -R mysql:mysql /usr/local/mysql

或者

# useradd -s /sbin/nologin -M mysql // -s 不允许登陆,-M不创建家目录
# chown -R mysql:mysql  //mysql到mysql组中去

2.2安装与配置

注:从mysql5.5后以cmake取代了configure

2.2.1安装cmake

下载地址:http://www.cmake.org/

    tar zxvf cmake-2.8.4.tar.gz
    cd cmake-2.8.4
    ./configure
    make
    make install

或者

# yum -y install cmake  //适用于 centos redhat系统

cmake 参数

-DCMAKE_INSTALL_PREFIX= 指向mysql安装目录
-DINSTALL_SBINDIR=sbin 指向可执行文件目录(prefix/sbin)
-DMYSQL_DATADIR=/var/lib/mysql 指向mysql数据文件目录(/var/lib/mysql)
-DSYSCONFDIR=/etc/mysql 指向mysql配置文件目录(/etc/mysql)
-DINSTALL_PLUGINDIR=lib/mysql/plugin 指向插件目录(prefix/lib/mysql/plugin)
-DINSTALL_MANDIR=share/man 指向man文档目录(prefix/share/man)
-DINSTALL_SHAREDIR=share 指向aclocal/mysql.m4安装目录(prefix/share)
-DINSTALL_LIBDIR=lib/mysql 指向对象代码库目录(prefix/lib/mysql)
-DINSTALL_INCLUDEDIR=include/mysql 指向头文件目录(prefix/include/mysql)
-DINSTALL_INFODIR=share/info 指向info文档存放目录(prefix/share/info)


cmake \

-DCMAKE_INSTALL_PREFIX=/usr/local/mysql\

-DMYSQL_UNIX_ADDR=/usr/local/mysql/mysql.sock \

-DDEFAULT_CHARSET=utf8 \

-DDEFAULT_COLLATION=utf8_general_ci \

-DWITH_MYISAM_STORAGE_ENGINE=1 \

-DWITH_INNOBASE_STORAGE_ENGINE=1 \

-DWITH_ARCHIVE_STORAGE_ENGINE=1 \

-DWITH_BLACKHOLE_STORAGE_ENGINE=1 \

-DWITH_MEMORY_STORAGE_ENGINE=1 \

-DWITH_READLINE=1 \

-DENABLED_LOCAL_INFILE=1 \

-DMYSQL_DATADIR=/db/mysql/data\

-DMYSQL_USER=mysql \

-DMYSQL_TCP_PORT=3306

详情请参考:
http://dev.mysql.com/doc/refman/5.6/en/source-configuration-options.html
http://waynerqiu.com/7/153.html

2.3编译安装

# tar -zxvf mysql-5.6.22.tar.gz
# cd mysql-5.6.22/
# cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql

如果报错,需安装相应的库,使用yum安装,重新cmake需执行rm -f CMakeCache.txt
如:
– Could NOT find OpenSSL (missing: OPENSSL_LIBRARIES OPENSSL_INCLUDE_DIR)
– Could NOT find Curses (missing: CURSES_LIBRARY CURSES_INCLUDE_PATH)
CMake Error at cmake/readline.cmake:83 (MESSAGE):
Curses library not found. Please install appropriate package,

remove CMakeCache.txt and rerun cmake.On Debian/Ubuntu, package name is libncurses5-dev, on Redhat and derivates it is ncurses-devel.
Call Stack (most recent call first):
cmake/readline.cmake:118 (FIND_CURSES)
cmake/readline.cmake:214 (MYSQL_USE_BUNDLED_READLINE)
CMakeLists.txt:257 (MYSQL_CHECK_READLINE)

– Configuring incomplete, errors occurred!

则执行

rm -f CMakeCache.txt
yum -y install ncurses-devel


the C compiler identification is unknown
the CXX compiler identification is unknown
-- Could NOT find Threads (missing: Threads_FOUND)
-- Could NOT find Threads (missing: Threads_FOUND)

# yum -y install gcc
# yum -y install gcc-c++
# yum install -y ncurses-devel
# yum -y install bison

或者执行:

# yum -y install gcc gcc-c++ gcc-g77 bison autoconf automake zlib* fiex* libxml* ncurses-devel libmcrypt* libtool-ltdl-devel* make cmake

继续安装

# rm -f CMakeCache.txt 
# cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql
# make 
# make install 

2.4配置

# cd /usr/local/mysql
# cp support-files/my-default.cnf /etc/my.cnf 
# cp support-files/mysql.server /etc/init.d/mysqld
# vim /etc/init.d/mysqld
basedir=/usr/local/mysql
datadir=/data/mysql
# ./scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql --datadir=/data/mysql

2.5启动mysql服务

# /etc/init.d/mysqld start

2.5.1查看是否启动正常

# ps aux |grep mysql //查看是否有mysql进程
# netstat -lnp |grep 3306 //查看是否监听mysql的3306端口

2.5.2添加mysql路径

# vim /etc/profile
export PATH=$PATH:/usr/local/mysql/bin/
# source /etc/profile
# mysql 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 4
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>

如果报错

ERROR 2002 (HY000): Can’t connect to local MySQL server through socket ‘/tmp/mysql.sock’ (2)

执行

# ln -s /var/lib/mysql/mysql.sock /tmp/mysql.sock 

2.6让chkconfig管理mysql服务

# chkconfig --add mysqld
# chkconfig mysqld on //设置自启动,可选
# service mysql start|restart|stop

2.7root添加密码


# mysqladmin -uroot password

再次登录

#mysql -hlocalhost -uroot -p

2.8设置远程登录

-------- Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 3
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> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '123456' WITH GRANT OPTION; 

安装appache

3.1 准备

# mkdir -p /usr/local/apache
# tar -xvf httpd-2.4.16.tar.gz
# cd httpd-2.4.16

3.2 安装

./configure --prefix=/usr/local/apache --with-include-apr --with-pcre --enable-shared=most 

configure: error: APR not found. Please read the documentation.

# wget http://mirror.bit.edu.cn/apache/apr/apr-1.5.2.tar.gz
# tar -xzvf apr-1.5.2.tar.gz 
# cd apr-1.5.2
# ./configure --prefix=/usr/local/apr
# make && make install
# wget http://mirror.bit.edu.cn/apache/apr/apr-util-1.5.4.tar.gz
# tar -xzvf apr-util-1.5.4.tar.gz
# ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr
# make && make install

继续安装

# ./configure --prefix=/usr/local/apache --with-include-apr --with-pcre --enable-shared=most --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util

configure: error: pcre-config for libpcre not found. PCRE is required and available from http://pcre.org/

# wget http://ftp.exim.llorien.org/pcre/pcre-8.36.tar.gz
# tar -xzvf pcre-8.36.tar.gz
# cd pcre-8.36
# ./configure --prefix=/usr/local/pcre
# make && make install

继续编译apache

# ./configure --prefix=/usr/local/apache --with-include-apr --with-pcre --enable-shared=most --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util --with-pcre=/usr/local/pcre
# make
# make install

4 安装php

4.1 编译安装

# tar -xzvf php-5.6.14.tar.gz 
# cd php-5.6.14
# ./configure --prefix=/usr/local/php --with-apxs2=/usr/local/apache/bin/apxs --with-config-file-path=/usr/local/php/etc --with-mysql=/usr/local/mysql --with-libxml-dir --with-gd --with-jpeg-dir --with-png-dir --with-freetype-dir --with-iconv-dir --with-zlib-dir --with-bz2 --with-openssl --with-mcrypt --enable-soap --enable-gd-native-ttf --enable-mbstring --enable-sockets --enable-exif --disable-ipv6


configure: error: Cannot find OpenSSL's <evp.h>

# yum list |grep -i 
# yum -y install openssl-devel.i686

configure: error: Please reinstall the BZip2 distribution

# yum -y install bzip2-devel.i686

configure: error: jpeglib.h not found.

# yum list |grep -i jpeg
# yum -y install libjpeg-turbo-devel.i686 

configure: error: png.h not found.

# yum -y install libpng-devel.i686 

configure: error: freetype-config not found.

# yum -y install freetype-devel.i686

configure: error: mcrypt.h not found.

yum -y install libtomcrypt-devel.i686
# ./configure --prefix=/usr/local/php --with-apxs2=/usr/local/apache/bin/apxs --with-config-file-path=/usr/local/php/etc --with-mysql=/usr/local/mysql --with-libxml-dir --with-gd --with-jpeg-dir --with-png-dir --with-freetype-dir --with-iconv-dir --with-zlib-dir --with-bz2 --with-openssl --with-mcrypt --enable-soap --enable-gd-native-ttf --enable-mbstring --enable-sockets --enable-exif --disable-ipv6
# make 
# echo $?
0
# make install

# cp /usr/local/src/php-5.6.14/php.ini-production /usr/local/php/etc/php.ini //设置php的配置文件 php.ini-production 源码目录拷贝到安装目录

大功告成

5 查看成果

5.1 php是否添加到了Apache

# vim /usr/local/apache/conf/httpd.conf
LoadModule php5_module        modules/libphp5.so //可以看到有这一行
# ls /usr/local/apache/modules/ |grep php
libphp5.so

5.2查看动态库使用了哪些工具和包

# ldd /usr/local/apache/modules/libphp5.so 
    linux-gate.so.1 =>  (0x0093e000)
    libcrypt.so.1 => /lib/libcrypt.so.1 (0x00116000)
    librt.so.1 => /lib/librt.so.1 (0x00146000)
    libmysqlclient.so.18 => /usr/local/mysql/lib/libmysqlclient.so.18 (0x0014f000)
    libmcrypt.so.4 => /usr/lib/libmcrypt.so.4 (0x004ea000)
    libltdl.so.7 => /usr/lib/libltdl.so.7 (0x0051c000)
    libpng12.so.0 => /usr/lib/libpng12.so.0 (0x00526000)
    libz.so.1 => /lib/libz.so.1 (0x0054e000)
    libjpeg.so.62 => /usr/lib/libjpeg.so.62 (0x0072a000)
    libbz2.so.1 => /lib/libbz2.so.1 (0x00792000)
    libm.so.6 => /lib/libm.so.6 (0x008a1000)
    libdl.so.2 => /lib/libdl.so.2 (0x00562000)
    libnsl.so.1 => /lib/libnsl.so.1 (0x00567000)
    libxml2.so.2 => /usr/lib/libxml2.so.2 (0x00582000)
    libssl.so.10 => /usr/lib/libssl.so.10 (0x007a3000)
    libcrypto.so.10 => /usr/lib/libcrypto.so.10 (0x067da000)
    libfreetype.so.6 => /usr/lib/libfreetype.so.6 (0x0093f000)
    libpthread.so.0 => /lib/libpthread.so.0 (0x006cd000)
    libc.so.6 => /lib/libc.so.6 (0x07ca8000)
    libfreebl3.so => /lib/libfreebl3.so (0x0080b000)
    /lib/ld-linux.so.2 (0x009f0000)
    libstdc++.so.6 => /usr/lib/libstdc++.so.6 (0x051c1000)
    libgcc_s.so.1 => /lib/libgcc_s.so.1 (0x006e8000)
    libgssapi_krb5.so.2 => /lib/libgssapi_krb5.so.2 (0x008cb000)
    libkrb5.so.3 => /lib/libkrb5.so.3 (0x027a8000)
    libcom_err.so.2 => /lib/libcom_err.so.2 (0x00706000)
    libk5crypto.so.3 => /lib/libk5crypto.so.3 (0x0086b000)
    libresolv.so.2 => /lib/libresolv.so.2 (0x0070b000)
    libkrb5support.so.0 => /lib/libkrb5support.so.0 (0x00781000)
    libkeyutils.so.1 => /lib/libkeyutils.so.1 (0x00725000)
    libselinux.so.1 => /lib/libselinux.so.1 (0x0090b000)

# ldd /usr/local/php/bin/php 
    linux-gate.so.1 =>  (0x00ae6000)
    libcrypt.so.1 => /lib/libcrypt.so.1 (0x0075c000)
    librt.so.1 => /lib/librt.so.1 (0x00bd3000)
    libmysqlclient.so.18 => /usr/local/mysql/lib/libmysqlclient.so.18 (0x001b1000)
    libmcrypt.so.4 => /usr/lib/libmcrypt.so.4 (0x0092d000)
    libltdl.so.7 => /usr/lib/libltdl.so.7 (0x0694c000)
    libpng12.so.0 => /usr/lib/libpng12.so.0 (0x0054c000)
    libz.so.1 => /lib/libz.so.1 (0x00bde000)
    libjpeg.so.62 => /usr/lib/libjpeg.so.62 (0x00574000)
    libbz2.so.1 => /lib/libbz2.so.1 (0x06cb8000)
    libm.so.6 => /lib/libm.so.6 (0x00bf4000)
    libdl.so.2 => /lib/libdl.so.2 (0x00bcc000)
    libnsl.so.1 => /lib/libnsl.so.1 (0x065d8000)
    libxml2.so.2 => /usr/lib/libxml2.so.2 (0x0648b000)
    libssl.so.10 => /usr/lib/libssl.so.10 (0x005cb000)
    libcrypto.so.10 => /usr/lib/libcrypto.so.10 (0x00d92000)
    libfreetype.so.6 => /usr/lib/libfreetype.so.6 (0x00797000)
    libpthread.so.0 => /lib/libpthread.so.0 (0x00baf000)
    libc.so.6 => /lib/libc.so.6 (0x00f5a000)
    libresolv.so.2 => /lib/libresolv.so.2 (0x00d60000)
    libfreebl3.so => /lib/libfreebl3.so (0x006fa000)
    /lib/ld-linux.so.2 (0x009f0000)
    libstdc++.so.6 => /usr/lib/libstdc++.so.6 (0x00830000)
    libgcc_s.so.1 => /lib/libgcc_s.so.1 (0x00964000)
    libgssapi_krb5.so.2 => /lib/libgssapi_krb5.so.2 (0x00633000)
    libkrb5.so.3 => /lib/libkrb5.so.3 (0x00c1e000)
    libcom_err.so.2 => /lib/libcom_err.so.2 (0x00673000)
    libk5crypto.so.3 => /lib/libk5crypto.so.3 (0x00678000)
    libkrb5support.so.0 => /lib/libkrb5support.so.0 (0x006a3000)
    libkeyutils.so.1 => /lib/libkeyutils.so.1 (0x006af000)
    libselinux.so.1 => /lib/libselinux.so.1 (0x006b3000)

上诉两个文件一模一样

5.3 查看安装时所用的选项

mysql 选项

# cat /usr/local/mysql/bin/mysqlbug 

apache 安装选项

# cat /usr/local/apache/build/config.nice 

php的安装信息

# /usr/local/php/bin/php -i 
查看php的信息,查看php的版本,系统版本,build的时间,编译选项,configuration FILS(配置文件)

查看加载的模块

# /usr/local/php/bin/php -m //php加载模块
# /usr/local/apache/bin/apachectl -M || /usr/local/apache/bin/httpd -M  //apache加载模块

5.4 测试

# /usr/local/apache/bin/apachectl start


AH00557: httpd: apr_sockaddr_info_get() failed for www
AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using 127.0.0.1. Set the 'ServerName' directive globally to suppress this message

# cd/usr/local/apache
# vim conf/httpd.conf
找到:
#ServerName www.example.com:80
修改为:
ServerName localhost:80
# /usr/local/apache/bin/apachectl -t //测试配置文件是否正常
Syntax OK
# /usr/local/apache/bin/apachectl start

# ps aux |grep httpd
# netstat -lnp |grep ':80 '

浏览器输入ip即可访问,如果无法访问,请关闭防火墙

iptables -F

测试PHP

# vim conf/httpd.conf
找到
 AddType application/x-compress .Z
 AddType application/x-gzip .gz .tgz
下面加入下面这一行
 AddType application/x-httpd-php .php
# /usr/local/apache/bin/apachectl -t
# /usr/local/apache/bin/apachectl graceful //重新加载配置文件

综上
apache常用命令

# /usr/local/apache/bin/apachectl -t //#检查配置文件基本语法
# /usr/local/apache/bin/apachectl -M //检查加载的模块
# /usr/local/apache/bin/apachectl -l // 查看编译在apache中的一些mo dules,可看出运行模式
# /usr/local/apache/bin/apachectl start(启动)|stop(停止)|restart(重启)|graceful(重新加载配置文件)

你可能感兴趣的:(apache,mysql,PHP,centos,lamp)