LAMP环境搭建 apache2.4 mysql 5.7 php 5.6

回复 收藏

导读:什么是LAMP?

LAMP指的Linux(操作系统)、ApacheHTTP 服务器,MySQL(有时也指MariaDB,数据库软件) 和PHP(有时也是指Perl或Python) 的第一个字母,一般用来建立web应用平台。


本案环境与说明:

环境

  1. [root@bright ~]# cat /etc/centos-release && uname -r
  2. CentOS release 6.6 (Final)
  3. 2.6.32-504.el6.x86_64
软件版本:
  1. mysql-5.7.6-m16-linux-glibc2.5-x86_64.tar.gz
  2. httpd-2.4.10.tar.gz
  3. apr-1.5.1.tar.gz
  4. apr-util-1.5.4.tar.gz  
  5. libmcrypt-2.5.6.tar.gz  
  6. php-5.6.6.tar.gz
文中所用软件下载地址:

http://mirrors.sohu.com/

http://mirrors.cnnic.cn/apache/

ftp://mcrypt.hellug.gr/pub/crypto/mcrypt/libmcrypt


一、安装MySQL

wgethttp://mirrors.sohu.com/mysql/My ... bc2.5-x86_64.tar.gz

  1. [root@bright ~]# useradd -s /sbin/nologin mysql
  2. [root@bright ~]# tar zxvf mysql-5.7.6-m16-linux-glibc2.5-x86_64.tar.gz
  3. [root@bright ~]# cd /usr/local/
  4. [root@bright local]# mv /root/mysql-5.7.6-m16-linux-glibc2.5-x86_64 .
  5. [root@bright local]# ln -s mysql-5.7.6-m16-linux-glibc2.5-x86_64 mysql
  6. [root@bright local]# cd mysql
  7. [root@bright mysql]# mkdir /data/mysql
  8. [root@bright mysql]# chown -R root .
  9. [root@bright mysql]# chown -R mysql /data/mysql
  10. [root@bright mysql]# chgrp -R mysql .
  11. [root@bright mysql]# bin/mysql_install_db --user=mysql --datadir=/data/mysql
  12. [root@bright mysql]# cp support-files/my-default.cnf /etc/my.cnf
  13. cp:是否覆盖"/etc/my.cnf"? y
  14. [root@bright mysql]# cp support-files/mysql.server /etc/init.d/mysqld
  15. [root@bright mysql]# chmod 755 /etc/init.d/mysqld
  16. [root@bright mysql]# vim /etc/init.d/mysqld   
  17. basedir=/usr/local/mysql      #mysql的安装路径
  18. datadir=/data/mysql/         #mysql数据存放路径
  19. [root@bright mysql]# chkconfig --add mysqld
  20. [root@bright mysql]# service mysqld start
  21. Starting MySQL. SUCCESS!




安装MySQL时创建mysql账户基于Linux安全的考虑。此账户名可以自定义,后续步骤注意更改。

二、安装Apache

Centos6 yum安装的apr版本已经不适用httpd-2.4版本了。所以,需要源码编译apr以及apr-util

wget http://mirrors.cnnic.cn/apache/apr/apr-util-1.5.4.tar.gz

wget http://mirrors.cnnic.cn/apache/apr/apr-1.5.2.tar.gz

2.1    安装apr

  1. [root@bright ~]# tar zxvf apr-1.5.2.tar.gz
  2. [root@bright ~]# cd apr-1.5.2
  3. [root@bright apr-1.5.1]# ./configure --prefix=/usr/local/apr
  4. [root@bright apr-1.5.1]# make && make install

2.2    安装apr-util

  1. <span style="line-height:16.7999992370605px;">[root@bright ~]# tar zxvf </span>apr-util-1.5.4.tar.gz

2.3    安装Apache

检查开发环境,没有的直接yum

  1. [root@bright ~]# rpm -q gcc cmake pcre-devel
  2. gcc-4.4.7-11.el6.x86_64
  3. cmake-2.8.12.2-4.el6.x86_64
  4. package pcre-devel is not installed
  5. [root@bright ~]# yum install pcre-devel

安装:

  1. [root@bright ~]# tar -zxvf httpd-2.4.10.tar.gz
  2. [root@bright ~]# cd httpd-2.4.10
  3. [root@bright httpd-2.4.10]# ./configure --prefix=/usr/local/apache2 --with-apr=/usr/local/apr/ --with-apr-util=/usr/local/apr-util/ --with-pcre --enable-mods-shared=most
  4. [root@bright httpd-2.4.10]# make &amp;&amp; make install
  5. [root@bright ~]# cp /usr/local/apache2/bin/apachectl /etc/rc.d/init.d/httpd
  6. [root@bright ~]# ln -s /etc/rc.d/init.d/httpd /etc/rc.d/rc3.d/S61httpd
  7. [root@bright ~]# vi /etc/rc.d/init.d/httpd
  8. [root@bright ~]# chkconfig --add httpd
三、安装PHP

wget http://mirrors.sohu.com/php/php-5.6.6.tar.gz

wget ftp://mcrypt.hellug.gr/pub/crypto/mcrypt/libmcrypt/libmcrypt-2.5.6.tar.gz

3.1    检查开发环境,没有的直接yum

(如有*.so,*.h文件无法找到,用yum provides "*/*.h"去查找)

  1. [root@bright ~]# rpm -q libxml2-devel libjpeg-turbo libpng-devel freetype-devel gd-devel libmcrypt-devel openssl-devel
  2. libxml2-devel-2.7.6-14.el6_5.2.x86_64
  3. libjpeg-turbo-1.2.1-3.el6_5.x86_64
  4. libpng-devel-1.2.49-1.el6_2.x86_64
  5. freetype-devel-2.3.11-14.el6_3.1.x86_64
  6. package gd-devel is not installed
  7. package libmcrypt-devel is not installed
  8. openssl-devel-1.0.1e-30.el6.x86_64
  9. [root@bright ~]# yum install gd-devel
3.2    Centos6 默认的yum源没有libmcrypt-devel 这个包,只能借助第三方yum源,本案tar包安装
  1. [root@bright ~]# tar zxvf libmcrypt-2.5.6.tar.gz
  2. [root@bright ~]# cd libmcrypt-2.5.6
  3. [root@bright libmcrypt-2.5.6]# ./configure --prefix=/usr/local/libmcrypt
  4. [root@bright libmcrypt-2.5.6]# make &amp;&amp; make install

3.3    安装php

  1. [root@bright ~]# tar zxvf php-5.6.6.tar.gz
  2. [root@bright ~]# cd php-5.6.6
  3. [root@bright php-5.6.6]# ./configure   --prefix=/usr/local/php   --with-apxs2=/usr/local/apache2/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=/usr/local/libmcrypt   --enable-soap   --enable-gd-native-ttf   --enable-mbstring   --enable-sockets   --enable-exif   --disable-ipv6
  4. [root@bright php-5.6.6]# make &amp;&amp; make install
  5. [root@bright php-5.6.6]# echo $?
  6. 0
四、配置apache和php与测试

1.修改AddType参数

  1. [root@bright ~]# vi /usr/local/apache2/conf/httpd.conf   
  2. [root@bright ~]# cat /usr/local/apache2/conf/httpd.conf | grep AddType | grep -v ^$ | grep -v ^#
  3.     # AddType allows you to add to or override the MIME configuration
  4.     #AddType application/x-gzip .tgz
  5.     AddType application/x-compress .Z
  6.     AddType application/x-gzip .gz .tgz             #在本行下面新增下行
  7.     AddType application/x-httpd-php .php            #增加的内容
  8.     #AddType text/html .shtml



http://s3.51cto.com/wyfs02/M00/5B/E3/wKioL1UVh8DC4ucVAABczNLC9rw534.jpg

2.修改DirectoryIndex 参数

  1. [root@bright ~]# cat /usr/local/apache2/conf/httpd.conf | grep index.html | grep -v ^$
  2. #    DirectoryIndex index.html
  3.     DirectoryIndex index.html index.htm index.php   #修改后的内容

http://s3.51cto.com/wyfs02/M00/5B/E8/wKiom1UVhp-QWvW2AACMYeCK1H0762.jpg

3.修改ServerName参数

  1. [root@bright ~]# cat /usr/local/apache2/conf/httpd.conf | grep ServerName| grep -v ^$
  2. # ServerName gives the name and port that the server uses to identify itself.
  3. #ServerName www.example.com:80
  4. ServerName localhost:80                             #修改后的内容

4. 测试解析php

在/usr/local/apache2/htdocs/中创建一个文件,内容如下。

  1. [root@bright ~]# cat /usr/local/apache2/htdocs/index.php
  2. &lt;?php
  3.     echo "php解析正常\n";
  4. ?&gt;
  5. [root@bright ~]# service httpd restart
  6. [root@bright ~]# curl localhost/index.php
  7. php解析正常

我的博客-LAMP环境搭建




2015-03-28 01:17 举报
已邀请:
0

175009666

赞同来自:

顶一下
0

gjc159357

赞同来自:

蛮详细,版本都好高了
0

疾风

赞同来自:

07.mkdir /data/mysql  :没有这个文件或目录
11. bin/mysql_install_db --user=mysql --datadir=/data/mysql:
[WARNING] mysql_install_db is deprecated. Please consider switching to mysqld --initialize
[WARNING] The bootstrap log isn't empty:
[WARNING] mysqld: [Warning] --bootstrap is deprecated. Please consider using --initialize instead

OpenSSL 1.0.1e-fips 11 Feb 2013
server-cert.pem: OK
client-cert.pem: OK

13.cp support-files/my-default.cnf /etc/my.cnf
cp:是否覆盖"/etc/my.cnf"? y没有出现该提示

14.cp support-files/mysql.server /etc/init.d/mysqld
cp:是否覆盖"/etc/init.d/mysqld"?
0

疾风

赞同来自:

从第7步就有错
07 、mkdir -p /data/msyql   ;默认没有/data/mysql

11、 [WARNING] mysql_install_db is deprecated. Please consider switching to mysqld --initialize
[WARNING] The bootstrap log isn't empty:
[WARNING] mysqld: [Warning] --bootstrap is deprecated. Please consider using --initialize instead
OpenSSL 1.0.1e-fips 11 Feb 2013
server-cert.pem: OK
client-cert.pem: OK

13、没出现提示
14、出现提示“是否覆盖”
16、vim /etc/init.d/mysqld :要修改什么?

0

九月微寒

赞同来自:

本帖最后由 九月微寒 于 2015-3-31 22:46 编辑
疾风 发表于 2015-3-31 11:22
从第7步就有错
07 、mkdir -p /data/msyql   ;默认没有/data/mysql

14 提示覆盖? 是不是系统已经安装了mysql?
16  我只修改了datadir ,老师的加上了basedir
basedir=
datadir=/data/mysql/
0

模范棒棒糖

赞同来自:

晟哥3月份就搞的LAMP哇。
0

九月微寒

赞同来自:

模范棒棒糖 发表于 2015-7-6 17:27
晟哥3月份就搞的LAMP哇。

嗯, 练手
0

Linux小虫

赞同来自:

看了ORACLE 官方文档
To install and use a MySQL binary distribution, the command sequence looks like this:

shell> groupadd mysql
shell> useradd -r -g mysql mysql
shell> cd /usr/local
shell> tar zxvf /path/to/mysql-VERSION-OS.tar.gz
shell> ln -s full-path-to-mysql-VERSION-OS mysql
shell> cd mysql
shell> mkdir mysql-files
shell> chmod 770 mysql-files
shell> chown -R mysql .
shell> chgrp -R mysql .
shell> bin/mysql_install_db --user=mysql    # Before MySQL 5.7.6
shell> bin/mysqld --initialize --user=mysql # MySQL 5.7.6 and up
shell> bin/mysql_ssl_rsa_setup              # MySQL 5.7.6 and up
shell> chown -R root .
shell> chown -R mysql data mysql-files
shell> bin/mysqld_safe --user=mysql &
# Next command is optional
shell> cp support-files/mysql.server /etc/init.d/mysql.server

官方是说5.7.6之后
shell> bin/mysqld --initialize --user=mysql # MySQL 5.7.6 and up

回复帖子,请先登录注册

退出全屏模式 全屏模式 回复
评分
可选评分理由: