设为首页 收藏本站
查看: 804|回复: 0

linux运维之LAMP(apache+mariadb+php)搭建

[复制链接]
累计签到:1 天
连续签到:1 天
发表于 2015-9-24 08:35:46 | 显示全部楼层 |阅读模式
linux运维之LAMP(apache+mariadb+php)搭建
         LAMP 是Linux Apache MySQL(mariadb) PHP的简写,其实就是把Apache, MySQL以及PHP安装在Linux系统上,组成一个环境来运行php的脚本语言,其中mariadb为mysql的一个分支。
搭建环境:
          系统: CentOS6.6-x86_64
          httpd: httpd-2.4.9
          mariadb: mariadb-5.5.43
          php: php-5.4.26
注: 安装顺序为 httpd-->mairadb-->php,安装编译前先安装开发环境组件:
       "Develoment Tools"和 "Server Platform Development"
1
[iyunv@localhost ~]# yum groupinstall "Development Tools" "Server Platform Development" -y




---------------------------------------------------------------------------------------------------------
1.apache(httpd)
apache:Web服务器,主要提供网上信息浏览服务,使用应用层http协议

编译安装:
         依赖包:
                   httpd-2.4.12.tar.bz2
                   pcre-deve
                   apr-1.5.0.tar.bz2:apr(Apache Portable Runtime)
                   apr-util-1.5.3.tar.bz2
     注: CentOS6.6系统默认安装httpd2.2版本,如果以防和2.4冲突,可以自行移除2.2版本后再编译安装2.4,这里不做移除。

移除命令为:
1
[iyunv@localhost ~]# yum remove httpd




     首先安装pcre-deve包:
1
[iyunv@localhost ~]# yum install pcre-devel -y



      编译安装apr包:
1
2
3
4
5
6
7
[iyunv@localhost ~]# ls #下载源码包到服务器
anaconda-ks.cfg         httpd-2.4.10.tar.bz2                   Public
apr-1.5.0.tar.bz2       install.log                            Templates
apr-util-1.5.3.tar.bz2  install.log.syslog                     Videos
Desktop                 Music                                  wordpress-4.3.1-zh_CN.zip
Documents               phpMyAdmin-4.4.14.1-all-languages.zip
Downloads               Pictures



1
2
3
4
5
6
7
8
9
10
11
12
13
14
[iyunv@localhost ~]# tar xf apr-1.5.0.tar.bz2 #解压
[iyunv@localhost ~]# cd apr-1.5.0
[iyunv@localhost apr-1.5.0]# ls #查看源码包内容
apr-config.in  buildconf         dso         libapr.rc     NOTICE         support
apr.dep        build.conf        emacs-mode  LICENSE       NWGNUmakefile  tables
apr.dsp        build-outputs.mk  encoding    locks         passwd         test
apr.dsw        CHANGES           file_io     Makefile.in   poll           threadproc
apr.mak        CMakeLists.txt    helpers     Makefile.win  random         time
apr.pc.in      config.layout     include     memory        README         tools
apr.spec       configure         libapr.dep  misc          README.cmake   user
atomic         configure.in      libapr.dsp  mmap          shmem
build          docs              libapr.mak  network_io    strings
[iyunv@localhost apr-1.5.0]# ./configure --prefix=/usr/local/apr #编译并指定一个安装路径
[iyunv@localhost apr-1.5.0]# make && make install #编译安装



      完成后编译安装apr-util
1
2
3
4
5
6
7
8
9
10
11
12
13
14
[iyunv@localhost ~]# tar -xf apr-util-1.5.3.tar.bz2 #解压
[iyunv@localhost ~]# cd apr-util-1.5.3
[iyunv@localhost apr-util-1.5.3]# ls #查看源码包内容
aprutil.dep     buildconf         dbd                libaprutil.dsp  NWGNUmakefile
aprutil.dsp     build.conf        dbm                libaprutil.mak  README
aprutil.dsw     build-outputs.mk  docs               libaprutil.rc   README.cmake
aprutil.mak     CHANGES           encoding           LICENSE         renames_pending
apr-util.pc.in  CMakeLists.txt    export_vars.sh.in  Makefile.in     strmatch
apr-util.spec   config.layout     hooks              Makefile.win    test
apu-config.in   configure         include            memcache        uri
buckets         configure.in      ldap               misc            xlate
build           crypto            libaprutil.dep     NOTICE          xml
[iyunv@localhost apr-util-1.5.3]# ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr #编译指定路径并针对apr的路径
[iyunv@localhost apr-1.5.0]# make && make install #编译安装



      完成后编译安装httpd包:
1
2
3
4
5
6
7
8
9
10
11
[iyunv@localhost ~]# tar -xf httpd-2.4.10.tar.bz2
[iyunv@localhost ~]# cd httpd-2.4.10
[iyunv@localhost httpd-2.4.10]# ls
ABOUT_APACHE     BuildBin.dsp    emacs-style     LICENSE        README.cmake
acinclude.m4     buildconf       httpd.dsp       Makefile.in    README.platforms
Apache-apr2.dsw  CHANGES         httpd.spec      Makefile.win   ROADMAP
Apache.dsw       CMakeLists.txt  include         modules        server
apache_probes.d  config.layout   INSTALL         NOTICE         srclib
ap.d             configure       InstallBin.dsp  NWGNUmakefile  support
build            configure.in    LAYOUT          os             test
BuildAll.dsp     docs            libhttpd.dsp    README         VERSIONING



1
2
[iyunv@localhost ~]#./configure --prefix=/usr/local/apache --sysconfdir=/etc/httpd24 --enable-so --enable-ssl --enable-cgi --enable-rewrite --with-zlib --with-pcre --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util --enable-modules=most --enable-mpms-shared=all --with-mpm=event #指定安装目录,配置文件目录,模块等等
[iyunv@localhost httpd-2.4.10]# make && make install#编译安装




注: 指定配置文件目录为/etc/httpd24,其中24是为了不与自带httpd2.2冲突而设置。
安装完成后看一下安装目录内容:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
[iyunv@localhost ~]# tree -d /usr/local/apache/
/usr/local/apache/
├── bin    #启动和关闭脚本
├── build   
├── cgi-bin  #cgi程序文件存放目录
├── error   #服务器端错误时返回给客户端的错误页面
│   └── include
├── htdocs   #web页面所在的目录
├── icons   #httpd图标文件
│   └── small
├── include     #头文件
├── logs    #日志文件
├── man   #man手册
│   ├── man1
│   └── man8
├── manual     #配置手册
│   ├── developer
│   ├── faq
│   ├── howto
│   ├── images
│   ├── misc
│   ├── mod
│   ├── platform
│   ├── programs
│   ├── rewrite
│   ├── ssl
│   ├── style
│   │   ├── css
│   │   ├── lang
│   │   ├── latex
│   │   ├── scripts
│   │   └── xsl
│   │       └── util
│   └── vhosts  #虚拟主机
└── modules     #httpd模块



1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
[iyunv@localhost ~]# tree /etc/httpd24/
/etc/httpd24/
├── extra                         #以下为扩展的配置文件
│?? ├── httpd-autoindex.conf      
│?? ├── httpd-dav.conf
│?? ├── httpd-default.conf     
│?? ├── httpd-info.conf
│?? ├── httpd-languages.conf
│?? ├── httpd-manual.conf
│?? ├── httpd-mpm.conf
│?? ├── httpd-multilang-errordoc.conf
│?? ├── httpd-ssl.conf
│?? ├── httpd-userdir.conf
│?? ├── httpd-vhosts.conf
│?? └── proxy-html.conf
├── httpd.conf        #主配置文件,包括添加模
├── magic
├── mime.types
└── original
    ├── extra
    │?? ├── httpd-autoindex.conf
    │?? ├── httpd-dav.conf
    │?? ├── httpd-default.conf
    │?? ├── httpd-info.conf
    │?? ├── httpd-languages.conf
    │?? ├── httpd-manual.conf
    │?? ├── httpd-mpm.conf
    │?? ├── httpd-multilang-errordoc.conf
    │?? ├── httpd-ssl.conf
    │?? ├── httpd-userdir.conf
    │?? ├── httpd-vhosts.conf
    │?? └── proxy-html.conf
    └── httpd.conf



     编写服务脚本,由于编译安装不会自动生成服务脚本,这里我们拷贝httpd目录到httpd24编辑:
1
2
3
[iyunv@localhost httpd-2.4.10]# cd /etc/rc.d/init.d/
[iyunv@localhost init.d]# cp httpd httpd24
[iyunv@localhost init.d]# vim httpd24



wKiom1YCcFOQNtcKAANZxRGFZW0354.jpg
     添加到开机启动表并开机自启动:
1
2
3
4
[iyunv@localhost init.d]# chkconfig --add httpd24 #
[iyunv@localhost init.d]# chkconfig httpd24 on  
[iyunv@localhost init.d]# chkconfig --list httpd24
httpd24         0:off 1:off 2:on 3:on 4:on 5:on 6:off



     接下来添加PATH变量脚本,不然启动时为httpd2.2版本
1
[iyunv@localhost ~]# vim /etc/profile.d/httpd.sh #添加脚本



#内容为:
export PATH=/usr/local/apache/bin:$PATH  #添加apache执行变量
1
[iyunv@localhost ~]# . /etc/profile.d/httpd.sh #重新载入



重启服务,80端口处于监听状态
1
2
3
4
5
6
7
8
9
10
11
12
13
[iyunv@localhost ~]# ss -tnl
State      Recv-Q Send-Q             Local Address:Port               Peer Address:Port
LISTEN     0      128                           :::22                           :::*     
LISTEN     0      128                            *:22                            *:*     
LISTEN     0      128                    127.0.0.1:631                           *:*     
LISTEN     0      128                          ::1:631                          :::*     
LISTEN     0      100                          ::1:25                           :::*     
LISTEN     0      100                    127.0.0.1:25                            *:*     
LISTEN     0      128                           :::40538                        :::*     
LISTEN     0      128                            *:57219                         *:*     
LISTEN     0      128                           :::111                          :::*     
LISTEN     0      128                            *:111                           *:*     
LISTEN     0      128                           :::80  #已经监听                      :::



1
[iyunv@localhost ~]# httpd -M #查看是否为event模式,event是否已经启动



wKioL1YCcqCTWbp-AAKB3x9bSR0888.jpg
大家看到这里默认启动的模块不是很多,可以根据自己需要自行添加模块位于:
1
2
3
4
[iyunv@localhost ~]# cd /etc/httpd24/
[iyunv@localhost httpd24]# ls
extra  httpd.conf  magic  mime.types  original
[iyunv@localhost httpd24]# vim httpd.conf  #里边模块基本保持默认即可



wKioL1YCczCCAYqHAAPqaa4sycY537.jpg 这样httpd2.4就搭建完成

    2.编译安装maraidb-5.5.43
         (1)首先解压缩到指定目录并创建数据目录,设定权限
         (2)设置配置文件
         (3)设置服务脚本文件
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
[iyunv@localhost ~]# tar xf mariadb-5.5.43-linux-x86_64.tar.gz -C /usr/local/
  #解压到/usr/local/目录
[iyunv@localhost ~]# mkdir -pv /mydata/data  #创建一个数据存放目录
mkdir: created directory `/mydata'
mkdir: created directory `/mydata/data'
[iyunv@localhost ~]# useradd -r mysql       #添加一个管理用户mysql
[iyunv@localhost ~]# chown -R mysql.mysql /mydata/data/  #指定目录权限
[iyunv@localhost local]# ln -sv mariadb-5.5.43-linux-x86_64 mysql #创建软连接指向mariadb数据目录
`mysql' -> `mariadb-5.5.43-linux-x86_64'
[iyunv@localhost local]# cd mysql/   #通过软链接mysql可以看到mariadb的数据文件
[iyunv@localhost mysql]# ls
bin      COPYING.LESSER  EXCEPTIONS-CLIENT  INSTALL-BINARY  man         README   share      support-files
COPYING  data            include            lib             mysql-test  scripts  sql-bench
[iyunv@localhost mysql]# chown -R root.mysql ./*   #修改目录mysql里所有文件权限
[iyunv@localhost mysql]# ll
total 220
drwxr-xr-x.  2 root mysql   4096 Sep 22 08:03 bin
-rw-r--r--.  1 root mysql  17987 Apr 29 14:55 COPYING
-rw-r--r--.  1 root mysql  26545 Apr 29 14:55 COPYING.LESSER
drwxr-xr-x.  3 root mysql   4096 Sep 22 08:03 data
-rw-r--r--.  1 root mysql   8245 Apr 29 14:55 EXCEPTIONS-CLIENT
drwxr-xr-x.  3 root mysql   4096 Sep 22 08:03 include
-rw-r--r--.  1 root mysql   8694 Apr 29 14:55 INSTALL-BINARY
drwxr-xr-x.  3 root mysql   4096 Sep 22 08:03 lib
drwxr-xr-x.  4 root mysql   4096 Sep 22 08:03 man
drwxr-xr-x. 11 root mysql   4096 Sep 22 08:03 mysql-test
-rw-r--r--.  1 root mysql 108813 Apr 29 14:55 README
drwxr-xr-x.  2 root mysql   4096 Sep 22 08:03 scripts
drwxr-xr-x. 27 root mysql   4096 Sep 22 08:03 share
drwxr-xr-x.  4 root mysql   4096 Sep 22 08:03 sql-bench
drwxr-xr-x.  3 root mysql   4096 Sep 22 08:03 support-files



接着初始化数据库:
1
[iyunv@localhost mysql]# scripts/mysql_install_db --datadir=/mydata/data/ --user=mysql



wKioL1YCdKqwwAM4AAM_-39KJkw927.jpg
接下来把mysql里的配置文件拷贝到/etc/mysql/my.cnf(创建)里并编辑:
1
2
3
[iyunv@localhost mysql]# mkdir /etc/mysql
[iyunv@localhost mysql]# cp support-files/my-large.cnf /etc/mysql/my.cnf
[iyunv@localhost mysql]# vim /etc/mysql/my.cnf



wKiom1YCdg2CCttwAAJjgyur8kA651.jpg 配置文件设置完成
    接下来设置服务脚本:
1
[iyunv@localhost mysql]# cp support-files/mysql.server /etc/rc.d/init.d/mysqld #拷贝服务脚本到init.d目录下名为mysqld



      为了使用mysql的安装符合系统规范,并将其开发组件导出给系统使用,这里还需要进行如下步骤:
     输出mysql的man手册至man命令的查找路径:编辑/etc/man.config,添加下行:
            MANPATH /usr/local/mysql/man
     输出msyql的头文件至系统头文件路径/usr/include,通过软链接实现:

1
2
[iyunv@localhost ~]# ln -sv /usr/local/mysql/include/ /usr/include/mysql
`/usr/include/mysql' -> `/usr/local/mysql/include/'



     输出mysql的库文件给系统查找路径:

1
[iyunv@localhost ~]# echo '/usr/local/mysql/lib/' > /etc/ld.so.conf.d/mysql.conf



配置好后让系统重新载入系统库

1
2
3
4
[iyunv@localhost ~]# ldconfig
[iyunv@localhost mysql]# chkconfig --add mysqld  #加入开机启动表中
[iyunv@localhost mysql]# service mysqld start    #启动服务
Starting MySQL..                                           [  OK  ]



1
2
3
4
5
6
7
8
9
10
11
12
13
14
[iyunv@localhost mysql]# ss -tnl  #查看到3306端口以及监听
State       Recv-Q Send-Q                           Local Address:Port                             Peer Address:Port
LISTEN      0      128                                         :::22                                         :::*     
LISTEN      0      128                                          *:22                                          *:*     
LISTEN      0      128                                  127.0.0.1:631                                         *:*     
LISTEN      0      128                                        ::1:631                                        :::*     
LISTEN      0      100                                        ::1:25                                         :::*     
LISTEN      0      100                                  127.0.0.1:25                                          *:*     
LISTEN      0      128                                         :::40538                                      :::*     
LISTEN      0      128                                          *:57219                                       *:*     
LISTEN      0      50                                           *:3306  #端口以及监听                                      *:*     
LISTEN      0      128                                         :::111                                        :::*     
LISTEN      0      128                                          *:111                                         *:*     
LISTEN      0      128                                         :::80                                         :::*



接着我们连接数据库:
wKioL1YCdyaSZrIbAAFISmbT2Ys116.jpg
能连接到数据库说明数据库正常

    3.编译安装php-5.4.26
             依赖安装包:
                     bzip2-devel   libmcrypt-devel(epel源,本地光盘没有)   libxml2-devel
    首先下载源码包到本地目录:
1
2
3
4
5
6
7
8
[iyunv@localhost ~]# ls  #下载好源码包
anaconda-ks.cfg         Downloads                           php-5.4.26.tar.bz2 #php包
apr-1.5.0               httpd-2.4.10                        phpMyAdmin-4.4.14.1-all-languages.zip
apr-1.5.0.tar.bz2       httpd-2.4.10.tar.bz2                Pictures
apr-util-1.5.3          install.log                         Public
apr-util-1.5.3.tar.bz2  install.log.syslog                  Templates
Desktop                 mariadb-5.5.43-linux-x86_64.tar.gz  Videos
Documents               Music                               wordpress-4.3.1-zh_CN.zip



    解压并编译:
1
2
3
[iyunv@localhost ~]# tar xf php-5.4.26.tar.bz2
[iyunv@localhost ~]# cd php-5.4.26
[iyunv@localhost ~]#./configure --prefix=/usr/local/php --with-mysql=/usr/local/mysql --with-openssl --with-mysqli=/usr/local/mysql/bin/mysql_config --enable-mbstring --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir=/usr --enable-xml  --enable-sockets --with-apxs2=/usr/local/apache/bin/apxs --with-mcrypt  --with-config-file-path=/etc --with-config-file-scan-dir=/etc/php.d --with-bz2  --enable-maintainer-zts



1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#with-openssl: 自动寻找本机安装的openssl
#mysql_config: 对mysql数据库进行交互的另外一个接口
#enable-mbstring: 多字节字符串支持
#freetype-dir: 支持的多字体类型
#jpeg-dir: 支持jpeg格式图片
#png-dir: png图片
#zlib: 压缩库
#libxml-dir: 处理xml格式文档
#enable-xml: 支持启用xml
#enable-sockets: 基于套接字通信
#apxs2: 用来把php编译成模块
#mcrypt: 支持加解密库
#config-file: php配置文件路径
#config-file-scan: 详细配置目录,到php.d查看
#bz2:支持bz2格式加密
#maintainer-zts: 编译成zts模块,worker和event模块必须加,prefork则不需要



     说明:
      (1)这里为了支持apache的worker或event这两个MPM,编译时使用了--enable-maintainer-zts选项。
      (2)如果使用PHP5.3以上版本,为了链接MySQL数据库,可以指定mysqlnd,这样在本机就不需要先安装MySQL或MySQL开发包了。mysqlnd从php 5.3开始可用,可以编译时绑定到它(而不用和具体的MySQL客户端库绑定形成依赖),但从PHP 5.4开始它就是默认设置了。

    编译完成后,默认httpd是不支持php的,这里需要为php提供配置文件
1
[iyunv@localhost php-5.4.26]# cp php.ini-production /etc/php.ini



     编辑apache配置文件httpd.conf以让apache支持php:
1
2
3
4
[iyunv@localhost php-5.4.26]# cd /etc/httpd24/
[iyunv@localhost httpd24]# ls
extra  httpd.conf  httpd.conf.bak  magic  mime.types  original
[iyunv@localhost httpd24]# vim httpd.conf



找到AddType选项,添加这两项:
1
2
#AddType application/x-httpd-php  .php           #Add前边没有#号。
#AddType application/x-httpd-php-source  .phps



wKioL1YCeD-TL_whAAJ3wFT9OuY315.jpg
     接着定位至DrectoryIndex index.html,修改为DirectoryIndex  index.php  index.html
wKiom1YCeLbz_GI6AAEmR6QPad8345.jpg
    而后重启httpd,或让其重新载入配置文件即可,使用httpd -M 可以查看php模块已加载
1
2
3
4
5
6
[iyunv@localhost ~]# httpd -M | tail -5
status_module (shared)
autoindex_module (shared)
dir_module (shared)
alias_module (shared)
php5_module (shared)      #可以看到php模块已经加载



    编译安装后默认首页文件保存于/usr/local/apache/htdocs里:
1
2
3
4
5
6
7
8
[iyunv@localhost ~]# cd /usr/local/apache/
[iyunv@localhost apache]# ls
bin  build  cgi-bin  error  htdocs  icons  include  logs  man  manual  modules
[iyunv@localhost apache]# cd htdocs/
[iyunv@localhost htdocs]# ls         #默认为html,改为php
index.html
[iyunv@localhost htdocs]# mv index.html index.php
[iyunv@localhost htdocs]# vim index.php   #编辑一下内容,看测试效果



wKiom1YCeYSzkooiAACINy11fvU601.jpg
      接下来在windows浏览器里输入本机IP地址就可以看到测试页:
   wKioL1YCecnQQjm_AAMPf82qRiA087.jpg

    php首页测试没有问题,这样php就安装完成

    关闭数据库测试一下:
1
2
[iyunv@localhost htdocs]# service mysqld stop
Shutting down MySQL..                                      [  OK  ]



wKiom1YCef-BtSiTAAHA1zxZaxU657.jpg

测试没有问题
1
[iyunv@localhost htdocs]# service mysqld start #重新开启mysql服务




到此,LAMP正式搭建完成。。。。







运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-117934-1-1.html 上篇帖子: LAMP编译介绍二、 php以fpm的方式结合apache工作 下篇帖子: 在安装配置LNMP过程中遇到的低端小麻烦
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表