[关闭]
@khan-lau 2017-05-23T09:18:35.000000Z 字数 8811 阅读 1894

CentOS 6.6下LAMP服务器的安装与配置v1.0

LAMP


1 系统环境

系统平台:CentOS release 6.6(基础服务安装)

Apache版本:2.4.25

Php版本:5.5.38

Mysql版本:5.7.18

服务器:testweb (192.168.5.40)

公网映射IP:218.240.48.180

端口映射:12204-->22、12205-->3306、8888-->80


2 安装准备工作

2.1 配置YUM源,可以使用本地YUM源,也可以访问互联网更新的YUM源;

这里使用本地YUM源配置

  1. [root@localhost ~]# mount -o loop /root/CentOS-* /media
  2. [root@localhost ~]# vi /etc/yum.repos.d/CentOS-Media.repo
  1. [local]
  2. name=this is my server
  3. baseurl=file:///media # 修改为光盘挂载点
  4. enabled=1 * 改为1意为启用
  5. gpgcheck=0

2.2 YUM准备好后,安装编译工具:

  1. [root@localhost ~]# yum install make gcc gcc-c++

2.3 关闭Selinux和iptables防火墙:

关闭selinux

  1. [root@localhost ~]# setenforce 0
  1. [root@localhost ~]# vi /etc/selinux/config

enforce改为disabled即可

  1. [root@localhost ~]# getenforce # 验证 enforce结果

关闭iptables

  1. [root@localhost ~]# chkconfig iptables off
  2. [root@localhost ~]# service iptables stop

3 安装apache

3.1 首先编译安装Apache之前我们要先解决依赖关系 http-2.4.25安装前解决依赖关系先安装apr、apr-util和pcre,安装这apr和apr-util软件包

此次安装采用源码安装部署;

3.2 编译安装apr(apr-1.5.2.tar.gz)

  1. [root@localhost ~]# wget http://mirror.bit.edu.cn/apache//apr/apr-1.5.2.tar.gz
如果wget没有安装, 可以用yum源安装
  1. [root@localhost ~]# tar zxvf apr-1.5.2.tar.gz
  2. [root@localhost ~]# cd apr-1.5.2
  3. [root@localhost apr-1.5.2]# ./configure --prefix=/usr/local/apr
  4. [root@localhost apr-1.5.2]# make && make install

注意:如果报出错误:

  1. [apr] rm: cannot remove `libtoolT’: No such file or directory

处理方法:打开configure文件
找到30055(不同的版本可能位置不一样)
将这行代码注释掉

  1. # $RM "$cfgfile"

然后重新编译,问题可以解决

3.3 编译安装apr-util(apr-util-1.5.4.tar.gz)

  1. [root@localhost ~]# wget http://mirror.bit.edu.cn/apache//apr/apr-util-1.5.4.tar.gz
  2. [root@localhost ~]# tar zxvf apr-util-1.5.4.tar.gz
  3. [root@localhost ~]# cd apr-util-1.5.4
  4. [root@localhost apr-util-1.5.4]# ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr
  5. #编译安装apr-util必须指定apr的安装位置
  6. [root@localhost apr-util-1.5.4]# make && make install

3.4 编译安装pcre-8.40(pcre-8.40.tar.gz)

  1. [root@localhost ~]# wget https://sourceforge.net/projects/pcre/files/pcre/8.40/pcre-8.40.tar.gz
  2. [root@localhost ~]# tar zxvf pcre-8.40.tar.gz
  3. [root@localhost ~]# cd pcre-8.40
  4. [root@localhost pcre-8.40]# ./configure --prefix=/usr/local/pcre
  5. [root@localhost pcre-8.40]# make && make install

3.5 编译安装httpd-2.4.25(httpd-2.4.25.tar.gz)

  1. [root@localhost ~]# wget http://mirror.bit.edu.cn/apache//httpd/httpd-2.4.25.tar.gz
  2. [root@localhost ~]# tar zxvf httpd-2.4.25.tar.gz
  3. [root@localhost ~]# cd httpd-2.4.25
  4. [root@localhost httpd-2.4.25]# ./configure --prefix=/usr/local/apache \
  5. --sysconfdir=/etc/httpd \
  6. --enable-so --enable-cgi \
  7. --enable-rewrite \
  8. --with-zlib \
  9. --with-pcre=/usr/local/pcre \
  10. --with-apr=/usr/local/apr \
  11. --with-apr-util=/usr/local/apr-util \
  12. --enable-mods-shared=most \
  13. --enable-mpms-shared=all \
  14. --with-mpm=event
  15. [root@localhost httpd-2.4.25]# make && make install
  1. #选项解释:
  2. --prefix=/usr/local/apache # 指定安装目录
  3. --enable-so #允许运行时加载DSO模块
  4. --enable-cgi --enable-rewrite # 启用cgi协议 #启用URL重写功能
  5. --with-zlib --with-pcre # 指定pcre的安装路径
  6. --with-apr=/usr/local/apr #指定apr的安装路径
  7. --with-apr-util=/usr/local/apr-util # 指定apr-util的安装路径
  8. --enable-modules=most # 启用大多数共享模块
  9. --enable-mpms-shared=most #启用MPM大多数参数
  10. --with-mpm=event #指定使用的MPM的类型

3.6 启动Apache服务并验证

  1. [root@localhost ~]# /usr/local/apache/bin/apachectl start -f /etc/httpd/httpd.conf
  2. [root@localhost ~]# curl http://localhost # 验证apache是否可以正常访问

注意:在启动过程中会有警告域名的问题,可以不理会,需要配置服务器名称,此次只是测试系统。

  1. vim /etc/httpd/httpd.conf

添加

  1. ServerName localhost:80

4 安装mysql

4.1 mysql数据库的安装采用rpm包安装的方式,首先在安装mysql前要做准备工作,下载rpm的bundle.

  1. [root@localhost ~]# wget https://cdn.mysql.com//Downloads/MySQL-5.7/mysql-5.7.18-1.el6.x86_64.rpm-bundle.tar
  2. [root@localhost ~]# tar xvf mysql-*

4.2 使用YUM源安装依赖包

  1. [root@localhost ~]# yum install perl-Time-HiRes numactl ncurses-devel

4.3 删除系统默认的mysql-libs(不删除原有的mysql-libs,会导致函数库冲突)

  1. [root@localhost ~]# yum remove mysql-libs

4.4 安装mysql

  1. [root@localhost ~]# rpm -ivh mysql-commu* #(主要是安装server、client、common、devel即可)

4.5 开启mysqld,并重置root密码

  1. [root@localhost ~]# mysqld_safe --skip-grant-tables --skip-networking & --无密码启动mysqld
  2. [root@localhost ~]# mysql -uroot -p
  1. update mysql.user set authentication_string=password('xxxxxxxx') where user='root' and Host = 'localhost';
  2. flush privileges; --刷新权限;(很重要)
  3. quit --退出
  1. [root@localhost ~]# service mysqld restart 重启mysqld
  1. set password for 'root'@'localhost'=password('xxxxxxxxx'); 重新登录后需要再次重置密码,至此成功设置完mysql密码;

4.6 mysql的root用户开启远程连接;

  1. [root@localhost ~]# mysql -uroot -p
  1. use mysql;
  2. set global validate_password_policy=0; --*变更密码复杂策略,否则修改密码会不成功
  3. GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'zhongjinshuju' WITH GRANT OPTION;
  4. flush privileges; --刷新权限;(很重要)

4.7 mysql创建zhongjin数据库并导入sql;

  1. create database zhongjin; 注意:mysql的字符集为默认的字符集,如果需要指定字符集需要带参数
  2. use zhongjin;
  3. source /root/zhongjin.sql *导入数据按实际目录;

5 安装php

5.1 安装php的基本依赖软件包

  1. [root@localhost ~]# yum -y install libtool libtool-libs kernel-devel \
  2. libjpeg libjpeg-devel libpng libpng-devel libtiff libtiff-devel \
  3. gettext gettext-devel \
  4. libxml2 libxml2-devel \
  5. zlib-devel net-snmp file glib2 glib2-devel bzip2 \
  6. diff* openldap-devel bzip2-devel ncurses ncurses-devel \
  7. curl curl-devel e2fsprogs e2fsprogs-devel krb5 krb5-devel \
  8. libidn libidn-devel openssl openssl-devel vim-minimal unzip \
  9. freetype freetype-devel png jpeg zlib gd php-gd* libiconv libevent

5.2 安装php扩展包mcrypt-2.6.8.tar.gz、libmcrypt-2.5.8.tar.gz、mhash-0.9.9.9.tar.gz

安装顺序( libmcrypt –> mhash –> mcrypt )

5.3 编译安装libmcrypt(libmcrypt-2.5.8.tar.gz)

  1. [root@localhost ~]# wget https://sourceforge.net/projects/mcrypt/files/Libmcrypt/2.5.8/libmcrypt-2.5.8.tar.gz
  2. [root@localhost ~]# tar zxvf libmcrypt-2.5.8.tar.gz
  3. [root@localhost ~]# cd libmcrypt-2.5.8
  4. [root@localhost libmcrypt-2.5.8]# ./configure --prefix=/usr/local/libmcrypt
  5. [root@localhost libmcrypt-2.5.8]# make && make install
  6. [root@localhost ~]# vim /etc/ld.so.conf.d/libmcrypt.conf # 此选项为将libmcrypt的库文件能让系统找到,不然后面编译安装mcrypt会报错

添加

  1. /usr/local/libmcrypt/lib
  1. [root@localhost ~]# ldconfig -v # 重新加载库文件

5.4 编译安装mhash(mhash-0.9.9.9.tar.gz)

  1. [root@localhost ~]# wget https://sourceforge.net/projects/mhash/files/mhash/0.9.9.9/mhash-0.9.9.9.tar.gz
  2. [root@localhost ~]# tar -zxvf mhash-0.9.9.9.tar.gz
  3. [root@localhost ~]# cd mhash-0.9.9.9
  4. [root@localhost mhash-0.9.9.9]# ./configure --prefix=/usr/local/mhash
  5. [root@localhost mhash-0.9.9.9]# make && make install
  6. [root@localhost ~]# vim /etc/ld.so.conf.d/mhash.conf # 做添加mhash的库文件让系统找到,不然后面编译安装mcrypt会报错

添加:

  1. /usr/local/mhash/lib
  1. [root@server1 mhash-0.9.9.9]# ldconfig -v # 重新加载库文件

5.5 编译安装mcrypy(mcrypt-2.6.8.tar.gz)

  1. [root@localhost ~]# wget https://sourceforge.net/projects/mcrypt/files/MCrypt/2.6.8/mcrypt-2.6.8.tar.gz
  2. [root@localhost ~]# tar zxvf mcrypt-2.6.8.tar.gz
  3. [root@localhost ~]# cd mcrypt-2.6.8
  4. [root@localhost mcrypt-2.6.8]# export LD_LIBRARY_PATH=/usr/local/libmcrypt/lib/:/usr/local/mhash/lib/
  5. [root@localhost mcrypt-2.6.8]# export LDFLAGS="-L/usr/local/mhash/lib/ -I/usr/local/mhash/include/"
  6. [root@localhost mcrypt-2.6.8]# export CFLAGS="-I/usr/local/mhash/include/"
  7. [root@localhost mcrypt-2.6.8]# ./configure --with-libmcrypt-prefix=/usr/local/libmcrypt/
  8. [root@localhost mcrypt-2.6.8]# make && make install

5.6 编译安装php

  1. [root@localhost ~]# wget http://cn2.php.net/distributions/php-5.5.38.tar.gz
  2. [root@localhost ~]# tar -zxvf php-5.5.38.tar.gz
  3. [root@localhost ~]# cd php-5.5.38
  4. [root@localhost php-5.5.38]# ./configure --prefix=/usr/local/php \
  5. --with-config-file-path=/usr/local/php/etc \
  6. --enable-maintainer-zts \
  7. --with-apxs2=/usr/local/apache/bin/apxs \
  8. --enable-fpm \
  9. --with-mcrypt=/usr/local/libmcrypt \
  10. --enable-mbstring \
  11. --enable-pdo \
  12. --with-curl \
  13. --disable-debug \
  14. --disable-rpath \
  15. --enable-inline-optimization \
  16. --with-bz2 \
  17. --with-zlib \
  18. --enable-sockets \
  19. --enable-sysvsem \
  20. --enable-sysvshm \
  21. --enable-pcntl \
  22. --enable-mbregex \
  23. --with-mhash \
  24. --enable-zip \
  25. --with-pcre-regex \
  26. --with-mysql \
  27. --with-mysqli \
  28. --with-gd \
  29. --with-jpeg-dir \
  30. --with-freetype-dir \
  31. --enable-calendar \
  32. --enable-opcache=no
  33. [root@localhost php-5.5.38]# make && make install

5.7 安装编译pthreads

  1. [root@localhost ~]# wget http://pecl.php.net/get/pthreads-2.0.5.tgz
  2. [root@localhost ~]# tar zxvf pthreads-2.0.5.tgz
  3. [root@localhost ~]# cd pthreads-2.0.5
  4. [root@localhost pthreads-2.0.5]# /usr/local/php/bin/phpize
  5. [root@localhost pthreads-2.0.5]# ./configure --with-php-config=/usr/local/php/bin/php-config
  6. [root@localhost pthreads-2.0.5]# make && make install

5.8 php配置

  1. [root@localhost php-5.5.38]# cp -a php.ini-production /usr/local/php/etc/php.ini #php.ini在源码的目录里面有
  2. [root@localhost php-5.5.38]# cp -a /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf #默认没有php-fpm.conf 需要copy默认配置

5.8.1 添加扩展

  1. [root@localhost ~]# vim /usr/local/php/etc/php.ini

添加

  1. extension=pthreads.so;

然后看看扩展安装是否成功

  1. [root@localhost ~]# /usr/local/php/bin/php -i |grep pthreads

6 apache关联php配置

6.1 编辑apache配置文件httpd.conf,以apache支持php

  1. [root@localhost ~]# vim /etc/httpd/httpd.conf

6.1.1 添加如下二行

  1. AddType application/x-httpd-php .php
  2. AddType application/x-httpd-php-source .phps

6.1.2 定位至DirectoryIndex index.html

修改为:

  1. DirectoryIndex index.php index.html

6.1.3 定位至LoadModule rewrite_module modules/mod_rewrite.so模块

将模块行首的注释去掉

6.1.4 修改httpd.conf的web的主目录

默认为/usr/local/apache/htdocs
直接可以将生产的default目录直接复制到该目录下,然后调整目录为

  1. DocumentRoot "/usr/local/apache/htdocs/default/zhongjin"
  2. <Directory "/usr/local/apache/htdocs/default/zhongjin">

6.2 重启apache,让配置生效;

6.3 创建源码需要的日志目录,否则会报内存溢出错误

  1. [root@localhost ~]# cd /usr/local/apache/htdocs/default/zhongjin/web/
  2. [root@localhost web]# mkdir -p ./runtime/logs
  3. [root@localhost ~]# cd /usr/local/apache/htdocs/default/zhongjin/admin/
  4. [root@localhost web]# mkdir -p ./runtime/logs

6.4 变更操作系统的目录属主,让apache进程有权限写日志,否则还会报内存溢出操作如下;

  1. [root@localhost ~]# cd /usr/local/apache
  2. [root@localhost apache]# chown -R daemon:daemon ./htdocs

至此整个安装过程结束。

添加新批注
在作者公开此批注前,只有你和作者可见。
回复批注