码迷,mamicode.com
首页 > 其他好文 > 详细

第一次搭建lamp架构笔记

时间:2016-06-19 18:42:34      阅读:416      评论:0      收藏:0      [点我收藏+]

标签:lamp

感谢MK老师提供技术指导以及资料、视频

特别鸣谢步行街同学一路陪伴,耐心指导

拷贝源码包

[root@duwen112 ~]# scpduwen@10.211.55.2:/Users/duwen/Desktop/LAMP/apr-1.5.2.tar.gz /root
The authenticity of host‘10.211.55.2 (10.211.55.2)‘ can‘t be established.
RSA key fingerprint is d6:3c:6e:2f:5d:46:c0:70:8b:a4:2f:40:d6:d5:3e:36.
Are you sure you want tocontinue connecting (yes/no)? yes
Warning: Permanently added‘10.211.55.2‘ (RSA) to the list of known hosts.
Password:
apr-1.5.2.tar.gz                                                                                      100%1007KB   1.0MB/s   00:00   
[root@duwen112 ~]#  scpduwen@10.211.55.2:/Users/duwen/Desktop/LAMP/apr-util-1.5.4.tar.gz /root
Password:
apr-util-1.5.4.tar.gz                                                                                100%  854KB 853.6KB/s   00:00   
[root@duwen112 ~]#  scpduwen@10.211.55.2:/Users/duwen/Desktop/LAMP/boost_1_60_0.tar.gz /root
Password:
boost_1_60_0.tar.gz                                                                               100%   86MB 86.2MB/s   00:01    
[root@duwen112 ~]#  scpduwen@10.211.55.2:/Users/duwen/Desktop/LAMP/httpd-2.4.18.tar.gz /root
Password:
httpd-2.4.18.tar.gz                                                                                  100% 6887KB   6.7MB/s   00:00   
[root@duwen112 ~]#  scpduwen@10.211.55.2:/Users/duwen/Desktop/LAMP/mysql-5.7.11.tar.gz /root
Password:
mysql-5.7.11.tar.gz                                                                                  100%   47MB  46.9MB/s  00:01    
[root@duwen112 ~]#  scpduwen@10.211.55.2:/Users/duwen/Desktop/LAMP/pcre-8.38.zip /root
Password:
pcre-8.38.zip                                                                                        100% 2235KB   2.2MB/s   00:00   
[root@duwen112 ~]#  scpduwen@10.211.55.2:/Users/duwen/Desktop/LAMP/php-7.0.5.tar.gz /root
Password:
php-7.0.5.tar.gz                                                                                     100%   17MB  17.3MB/s  00:00    
[root@duwen112 ~]#
[root@duwen112 ~]# ls
anaconda-ks.cfg   apr-util-1.5.4.tar.gz  httpd-2.4.18.tar.gz  install.log.syslog   pcre-8.38.zip     公共的  视频  文档  音乐
apr-1.5.2.tar.gz  boost_1_60_0.tar.gz    install.log          mysql-5.7.11.tar.gz  php-7.0.5.tar.gz  模板    图片  下载  桌面
[root@duwen112 ~]#


安装依赖包

[root@duwen112 ~]# tar zxfapr-1.5.2.tar.gz 
[root@duwen112 ~]# cdapr-1.5.2
[root@duwen112 apr-1.5.2]#./configure --prefix=/usr/local/apr
 
[root@duwen112 apr-1.5.2]#make && make install
[root@duwen112apr-util-1.5.4]# ./configure --prefix=/usr/local/apr-util--with-apr=/usr/local/apr
[root@duwen112apr-util-1.5.4]# 
[root@duwen112apr-util-1.5.4]# 
[root@duwen112apr-util-1.5.4]# make && make install
----------------------------------------------------------------------
/usr/bin/install -c -m 644aprutil.exp /usr/local/apr-util/lib
/usr/bin/install -c -m 755apu-config.out /usr/local/apr-util/bin/apu-1-config
[root@duwen112apr-util-1.5.4]# 
 
[root@duwen112apr-util-1.5.4]# cd
[root@duwen112 ~]# unzip -opcre-8.38.zip
[root@duwen112 ~]# cdpcre-8.38
[root@duwen112 pcre-8.38]#./configure --prefix=/usr/local/pcre 
[root@duwen112 pcre-8.38]#make 
[root@duwen112 pcre-8.38]#make install

安装apache

[root@duwen112 ~]# tar zxfhttpd-2.4.18.tar.gz -C /usr/local/src/
[root@duwen112 ~]# cd/usr/local/src/httpd-2.4.18/
[root@duwen112 httpd-2.4.18]#./configure --prefix=/usr/local/apache2 --enable-so --enable-rewrite--enable-ssl --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util/--with-pcre=/usr/local/pcre/

 

[root@duwen112 httpd-2.4.18]#make -j 4
[root@duwen112 httpd-2.4.18]#make install

 

配置文件

[root@duwen112 httpd-2.4.18]#ls /usr/local/apache2/conf/httpd.conf
/usr/local/apache2/conf/httpd.conf

存放网站的根目录

[root@duwen112 httpd-2.4.18]#ls /usr/local/apache2/htdocs/
index.html
[root@duwen112 httpd-2.4.18]#

 

生成启动脚本

[root@duwen112 httpd-2.4.18]#cp /usr/local/apache2/bin/apachectl /etc/init.d/

//先停止服务,

[root@duwen112 httpd-2.4.18]#/etc/init.d/httpd stop
停止 httpd:                                              [失败]
[root@duwen112 httpd-2.4.18]#chkconfig httpd off
[root@duwen112 httpd-2.4.18]#

//让apache 开机启动,还要再在apachectl 文件的头部的注释中加两条命令。

[root@duwen112 httpd-2.4.18]#vim /etc/init.d/apachectl
[root@duwen112 httpd-2.4.18]#head -5 !$
head -5 /etc/init.d/apachectl
#!/bin/sh
#
#chkconfig:2345 64 36
#description:Activates/Deactivatesall network interfaces configured to # Licensed to the ApacheSoftware Foundation (ASF) under one or more
[root@duwen112 httpd-2.4.18]#

 

设置开机启动

[root@duwen112 httpd-2.4.18]#cd

[root@duwen112 ~]# chkconfig--add apachectl

[root@duwen112 ~]# chkconfig--list apachectl

apachectl                   0:关闭      1:关闭      2:启用      3:启用      4:启用      5:启用      6:关闭

[root@duwen112 ~]#

启动阿帕奇

[root@duwen112 ~]#/etc/init.d/apachectl start

AH00557: httpd:apr_sockaddr_info_get() failed for duwen112

AH00558: httpd: Could notreliably determine the server‘s fully qualified domain name, using 127.0.0.1.Set the ‘ServerName‘ directive globally to suppress this message

[root@duwen112 ~]#

测试一下

 技术分享

源码apache运行身份是daemon  rpm安装的httpd运行身份是apache

[root@duwen112~]# ps -aux |grep apach
Warning:bad syntax, perhaps a bogus ‘-‘? See /usr/share/doc/procps-3.2.8/FAQ
root      3396 0.0  0.2  74872 2248 ?        Ss   15:06  0:00 /usr/local/apache2/bin/httpd -k start
daemon    3397 0.0  0.4 484668  4704 ?       Sl   15:06   0:01 /usr/local/apache2/bin/httpd -k start
daemon    3398 0.0  0.4 484668  4704 ?       Sl   15:06   0:01 /usr/local/apache2/bin/httpd -k start
daemon    3399 0.0  0.4 419132  4208 ?       Sl   15:06   0:01 /usr/local/apache2/bin/httpd -k start
root      9670 0.0  0.0 103260   844 pts/1   S+   15:38   0:00 grep apach
[root@duwen112~]# id daemon
uid=2(daemon)gid=2(daemon) 组=2(daemon),1(bin),4(adm),7(lp)
[root@duwen112~]#

安装MySQL

创建mysql用户

[root@duwen112~]# useradd mysql
[root@duwen112~]# vim /etc/passwd
[root@duwen112~]# tail -1 !$
tail -1/etc/passwd
mysql:x:500:500::/home/mysql:/sbin/nolongin
[root@duwen112~]#

解压

[root@duwen112~]# tar zxf mysql-5.7.11.tar.gz -C /usr/local/src/
[root@duwen112~]# cd /usr/local/src/mysql-5.7.11/
[root@duwen112mysql-5.7.11]#

安装cmake

//一般是会带的,检查下吧,

[root@duwen112mysql-5.7.11]# yum install -y cmake
Loadedplugins: product-id, refresh-packagekit, security, subscription-manager
Thissystem is not registered to Red Hat Subscription Management. You can usesubscription-manager to register.
Settingup Install Process
Nopackage cmake available.
Error:Nothing to do
[root@duwen112mysql-5.7.11]#
[root@duwen112mysql-5.7.11]# rpm -ivh /mnt/Packages/cmake-2.6.4-5.el6.x86_64.rpm
warning: /mnt/Packages/cmake-2.6.4-5.el6.x86_64.rpm:Header V3 RSA/SHA256 Signature, key ID fd431d51: NOKEY
Preparing...               ########################################### [100%]
   1:cmake                 ########################################### [100%]
[root@duwen112mysql-5.7.11]#

 

开始编译

[root@duwen112mysql-5.7.11]# mkdir /server/
[root@duwen112mysql-5.7.11]# cd /usr/local//src/mysql-5.7.11/
[root@duwen112mysql-5.7.11]#
[root@duwen112mysql-5.7.11]# cmake -DCMAKE_INSTALL_PREFIX=/server/mysql-5.7 -DMYSQL_UNIX_ADDR=/tmp/mysql.sock-DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci-DWITH_EXTRA_CHARSETS=all -DWITH_MYISAM_STORAGE_ENGINE=1-DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_MEMORY_STORAGE_ENGINE=1-DWITH_READLINE=1 -DENABLED_LOCAL_INFILE=1 -DMYSQL_DATADIR=/server/mysql/data-DMYSQL_USER=mysql
CMakeError at CMakeLists.txt:21 (CMAKE_MINIMUM_REQUIRED):
  CMake 2.8.2 or higher is required.  You are running version 2.6.4
--Configuring incomplete, errors occurred!

//不知不觉就出错了,我以为是cmake的问题呢!一直弄cmake

[root@duwen112mysql-5.7.11]# scpduwen@10.211.55.2:/Users/duwen/Downloads/cmake-3.3.2-1mgc30.x86_64.rpm /root
Password:
cmake-3.3.2-1mgc30.x86_64.rpm                                                                        100% 7723KB   7.5MB/s   00:00   
[root@duwen112mysql-5.7.11]# rpm -ivh /root/cmake-3.3.2-1mgc30.x86_64.rpm
error:Failed dependencies:
            emacs-filesystem >= 24.3 isneeded by cmake-3.3.2-1mgc30.x86_64
            libarchive.so.13()(64bit) is neededby cmake-3.3.2-1mgc30.x86_64
            libc.so.6(GLIBC_2.14)(64bit) isneeded by cmake-3.3.2-1mgc30.x86_64
            libc.so.6(GLIBC_2.15)(64bit) isneeded by cmake-3.3.2-1mgc30.x86_64
            libform.so.6()(64bit) is needed bycmake-3.3.2-1mgc30.x86_64
            libjsoncpp.so.0()(64bit) is neededby cmake-3.3.2-1mgc30.x86_64
            libncurses.so.6()(64bit) is neededby cmake-3.3.2-1mgc30.x86_64
            libstdc++.so.6(CXXABI_1.3.5)(64bit)is needed by cmake-3.3.2-1mgc30.x86_64
            libstdc++.so.6(GLIBCXX_3.4.15)(64bit)is needed by cmake-3.3.2-1mgc30.x86_64
            libstdc++.so.6(GLIBCXX_3.4.18)(64bit)is needed by cmake-3.3.2-1mgc30.x86_64
            libtinfo.so.6()(64bit) is needed bycmake-3.3.2-1mgc30.x86_64
            libz.so.1(ZLIB_1.2.3.3)(64bit) isneeded by cmake-3.3.2-1mgc30.x86_64
[root@duwen112mysql-5.7.11]# rpm -e cmake
[root@duwen112mysql-5.7.11]#

//高版本好像安装不了额,我还是卸载cmake从新安装吧,安装过程就不写了,上面有rpm安装的,就是2.6的
//然后,我觉得可能是包解压不完整、包传输过程丢失数据、包不兼容等等问题,换了mk老师使用的mysql安装包,事实上好像就是包不兼容哈

[root@duwen112~]#
[root@duwen112~]# scp duwen@10.211.55.2:/Users/duwen/Desktop/mysql-5.5.30.tar.gz /root
Password:
mysql-5.5.30.tar.gz                                                                                  100%   23MB  23.4MB/s  00:00   
[root@duwen112~]# tar zxf mysql
mysql-5.5.30.tar.gz  mysql-5.7.11.tar.gz  mysql.txt           
[root@duwen112~]# tar zxf mysql-5.5.30.tar.gz -C /usr/local/src/
[root@duwen112~]# cd /usr/local/src/mysql-5.5.30/
[root@duwen112mysql-5.5.30]# cmake -DCMAKE_INSTALL_PREFIX=/server/mysql-5.7 -DMYSQL_UNIX_ADDR=/tmp/mysql.sock-DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci-DWITH_EXTRA_CHARSETS=all -DWITH_MYISAM_STORAGE_ENGINE=1-DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_MEMORY_STORAGE_ENGINE=1-DWITH_READLINE=1 -DENABLED_LOCAL_INFILE=1 -DMYSQL_DATADIR=/server/mysql/data-DMYSQL_USER=mysql

没有报错了

cmake编译选项的含义:

-DCMAKE_INSTALL_PREFIX=/server/mysql-5.5
#指定 mysql 安装的根目录,只要/server 目录存在就可以了,mysql-5.5在安装时,会自动创建。这个 值可以在服务器启动时,通过--basedir 来设置。
-DMYSQL_UNIX_ADDR=/tmp/mysql.sock
#mysql 服务器用于监听的套接字,这个必需是一个绝对路径,默认是/tmp/mysql.sock。在服务器启动时,可通过--socket 来改变。
-DDEFAULT_CHARSET=utf8
设置 mysql 默认使用 utf8 字符集,不指定,默认使用 latin1 西欧字符集。
-DDEFAULT_COLLATION=utf8_general_ci #默认字符校对。 db.opt
-DWITH_EXTRA_CHARSETS=all
#指定 mysql 扩展字符集支持所有的字符集。默认 mysql 支持所有字符集
-DWITH_MYISAM_STORAGE_ENGINE=1
-DWITH_INNOBASE_STORAGE_ENGINE=1
-DWITH_MEMORY_STORAGE_ENGINE=1
#静态编译 Myisam、Innobase、Memory 存储引擎到mysql 服务器。这样 mysql 服务器就支持这三 种存储引擎了。
-DWITH_READLINE=1 #支持readline 库 。
-DENABLED_LOCAL_INFILE=1 #允许从本地导入数据 ,启用加载本地数据
-DMYSQL_DATADIR=/server/mysql/data#mysql 数据库存放数据的目录
-DMYSQL_USER=mysql #指定运行mysql 服务的用户
注:具体编译参数参考:http://dev.mysql.com/doc/refman/5.5/en/source-configuration-options.html

make,放个图证明我没有报错

技术分享

make install

配置mysql运行环境,这个是安装目录

技术分享

[root@duwen112mysql-5.5.30]# chown -R mysql:mysql /server/mysql-5.7/
[root@duwen112mysql-5.5.30]#
##修改mysql安装目录的权限,允许mysql用户对mysql数据库文件夹读写

复制mysql配置文件

[root@duwen112etc]# ll my.cnf
-rw-r--r--.1 root root 251 8月  9 2013 my.cnf
[root@duwen112etc]# mv ./my.cnf ./my.cnf.back
[root@duwen112etc]# cd
[root@duwen112~]# cp /usr/local/src/mysql-5.5.30/support-files/my-large.cnf /etc/my.cnf
[root@duwen112~]#

设置 mysqld5.5 服务开机启动

 [root@duwen112 ~]#
[root@duwen112 ~]# cp/usr/local/src/mysql-5.5.30/support-files/mysql.server /etc/init.d/mysqld5.5
[root@duwen112 ~]# chmod +x /etc/init.d/mysqld5.5 
[root@duwen112 ~]# vim /etc/init.d/mysqld5.5 
[root@duwen112 ~]# head -70 /etc/init.d/mysqld5.5 | tail-5
 basedir=/server/mysql-5.7
 bindir=/server/mysql-5.7/bin
  if test -z"$datadir"
  then
    datadir=/server/mysql-5.7/data
[root@duwen112 ~]#

加入开机启动项

[root@duwen112~]# chkconfig mysqld5.5 on
[root@duwen112~]# chkconfig --list mysqld5.5
mysqld5.5              0:关闭   1:关闭   2:启用   3:启用   4:启用   5:启用   6:关闭
[root@duwen112~]#

初始化mysql

[root@duwen112~]# cd /usr/local/src/mysql-5.5.30/scripts/
[root@duwen112scripts]# chmod +x mysql_install_db
[root@duwen112scripts]# ./mysql_install_db --defaults-file=/etc/my.cnf--basedir=/server/mysql-5.7 --datadir=/server/mysql-5.7/data --user=mysql

技术分享

开启mysql并测试登录

技术分享

设置mysql的root账户密码

技术分享

安装php

这里用mk安装过的包

[root@duwen112~]# ls
anaconda-ks.cfg   apr-util-1.5.4.tar.gz          install.log          mysql.txt         公共的  文档
apr-1.5.2         boost_1_60_0.tar.gz            install.log.syslog   pcre-8.38         模板    下载
apr-1.5.2.tar.gz  cmake-3.3.2-1mgc30.x86_64.rpm  mysql-5.5.30.tar.gz  pcre-8.38.zip     视频    音乐
apr-util-1.5.4    httpd-2.4.18.tar.gz            mysql-5.7.11.tar.gz  php-7.0.5.tar.gz  图片    桌面
[root@duwen112~]# scp duwen@10.211.55.2:/Users/duwen/Desktop/php-5.4.14.tar.bz2 /root
Password:
php-5.4.14.tar.bz2                                                                                   100%   11MB  11.4MB/s  00:00   
[root@duwen112~]#

解压并进入路径

[root@duwen112 ~]# tar -jxfphp-5.4.14.tar.bz2 -C /usr/local/src/
[root@duwen112 ~]# cd/usr/local/src/
[root@duwen112 src]# ls
httpd-2.4.18  mysql-5.5.30  mysql-5.7.11  php-5.4.14
[root@duwen112 src]# cd php-5.4.14/

配置

[root@duwen112php-5.4.14]# ./configure --prefix=/server/php-5.4--with-mysql=/server/mysql-5.7 --with-apxs2=/usr/local/apache2/bin/apxs--with-config-file-path=/server/php-5.4

配置是成功的,有图有真相

技术分享

[root@duwen112php-5.4.14]# make -j 4

技术分享

//这里有个make test  ,这个是个坑运行时间长的不要不要的,mk说是执行echo $?,返回0

[root@duwen112php-5.4.14]# make install


生成php配置文档

[root@duwen112php-5.4.14]# cd
[root@duwen112~]# cp /usr/local/src/php-5.4.14/php.ini-production /server/php-5.4/php.ini
[root@duwen112~]#

查看服务器原先参数

[root@duwen112~]# /server/php-5.4/bin/php -i | grep configure
PHPWarning:  Unknown: It is not safe to relyon the system‘s timezone settings. You are *required* to use the date.timezonesetting or the date_default_timezone_set() function. In case you used any ofthose methods and you are still getting this warning, you most likelymisspelled the timezone identifier. We selected the timezone ‘UTC‘ for now, butplease set date.timezone to select your timezone. in Unknown on line 0
ConfigureCommand =>  ‘./configure‘  ‘--prefix=/server/php-5.4‘‘--with-mysql=/server/mysql-5.7‘ ‘--with-apxs2=/usr/local/apache2/bin/apxs‘‘--with-config-file-path=/server/php-5.4‘
[root@duwen112~]#

如果一切顺利,会成功一个模块,如图

技术分享

让阿帕奇支持php

[root@duwen112~]# vim /usr/local/apache2/conf/httpd.conf
[root@duwen112~]#

技术分享

还有这个

AddTypeapplication/x-httpd-php .php 

位置如图

技术分享

这里是重启Apache,但是出错了

[root@duwen112 ~]# vim/usr/local/apache2/conf/httpd.conf

[root@duwen112 ~]#/etc/init.d/apachectl stop

AH00526: Syntax error on line 312 of/usr/local/apache2/conf/httpd.conf:

AddType requires at least twoarguments, a mime type followed by one or more file extensions

[root@duwen112 ~]# vim/usr/local/apache2/conf/httpd.conf

[root@duwen112 ~]#/etc/init.d/apachectl stop

AH00526: Syntax error on line 312 of/usr/local/apache2/conf/httpd.conf:

AddType requires at least twoarguments, a mime type followed by one or more file extensions

[root@duwen112 ~]# vim /usr/local/apache2/conf/httpd.conf

[root@duwen112 ~]#/etc/init.d/apachectl stop

AH00557: httpd:apr_sockaddr_info_get() failed for duwen112

AH00558: httpd: Could not reliablydetermine the server‘s fully qualified domain name, using 127.0.0.1. Set the ‘ServerName‘directive globally to suppress this message

[root@duwen112 ~]#

//就上面这个问题百度了好久,看视频查资料NNNN

最后

  /usr/local/apache2/conf/httpd.conf中ServerName(或/etc/httpd/conf/httpd.conf)前面的“#”拿掉就好了

技术分享

重启服务

[root@duwen112htdocs]# /etc/init.d/apachectl stop

httpd (nopid file) not running

[root@duwen112htdocs]# /etc/init.d/apachectl start

[root@duwen112htdocs]#

给php加个东西,等下回来修改,这里先占个位置

测试下

技术分享






本文出自 “duwers” 博客,请务必保留此出处http://duwers.blog.51cto.com/7376225/1790735

第一次搭建lamp架构笔记

标签:lamp

原文地址:http://duwers.blog.51cto.com/7376225/1790735

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!