企业LAMP服务搭建
Posted itil
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了企业LAMP服务搭建相关的知识,希望对你有一定的参考价值。
LAMP 架构在企业里用得非常广泛,目前很多电商公司、游戏公司、移动互联网公司大多都采用这种架构。LAMP指的是Linux、Apache、mysql、php。下面记录了 LAMP 架构系统服务的搭建过程。
一、MySQL数据库安装
1. 系统环境
CentOS 6.4 x86_64 Mini 版本安装
2. 基础软件包安装
1
|
[[email protected] ~]# yum install gcc vim make wget -y
|
3. 下载
1
2
3
4
|
# 进入源码存放目录
[[email protected] ~]# cd /usr/local/src
# 下载MySQL安装包
[[email protected] src]# wget downloads.mysql.com/archives/get/file/mysql-5.5.40-linux2.6-x86_64.tar.gz
|
4. 解压安装
1
2
3
4
|
# 解压
[[email protected] src]# tar -zxf mysql-5.5.40-linux2.6-x86_64.tar.gz
# 设置安装路径
[[email protected] src]# mv mysql-5.5.40-linux2.6-x86_64 /usr/local/mysql
|
5. 建立MySQL用户
1
|
[[email protected] src]# useradd -s /sbin/nologin -M mysql
|
6. 准备数据目录
1
2
3
4
5
6
|
# 进入MySQL安装目录
[[email protected] src]# cd /usr/local/mysql
# 创建MySQL数据目录
[[email protected] mysql]# mkdir -p /var/lib/mysql
# 设置目录权限
[[email protected] mysql]# chown -R mysql:mysql /var/lib/mysql
|
7. 初始化数据库
1
2
3
4
5
6
|
[[email protected] mysql]# ./scripts/mysql_install_db --user=mysql --datadir=/var/lib/mysql
when specifying MySQL privileges !
Installing MySQL system tables...
OK
Filling help tables...
OK #看到2个OK说明初始化成功
|
8. 拷贝配置文件
1
|
[[email protected] mysql]# /bin/cp support-files/my-large.cnf /etc/my.cnf
|
9. 拷贝启动脚本
1
2
3
4
|
# 拷贝启动脚本
[[email protected] mysql]# /bin/cp support-files/mysql.server /etc/init.d/mysqld
# 赋予可执行权限
[[email protected] mysql]# chmod 755 /etc/init.d/mysqld
|
10. 修改启动脚本
1
2
3
4
|
[[email protected] mysql]# vim /etc/init.d/mysqld
# 修改设置内容如下
basedir=/usr/local/mysql
datadir=/var/lib/mysql
|
11. 把MySQL添加到服务
1
2
3
4
|
# 添加到service列表
[[email protected] mysql]# chkconfig --add mysqld
# 设置开机启动
[[email protected] mysql]# chkconfig mysqld on
|
12. 启动MySQL服务
1
2
|
[[email protected] mysql]# service mysqld start
Starting MySQL... SUCCESS!
|
13. 查看验证MySQL启动进程
1
2
3
|
[[email protected] mysql]# ps -e | grep mysql
1830 pts/1 00:00:00 mysqld_safe
2121 pts/1 00:00:00 mysqld
|
14. 配置MySQL环境变量
将 MySQL 客户端命令路径加入 PATH 环境变量中去。
1
2
3
|
# 设置PATH环境变量
[[email protected] mysql]# echo ‘export PATH=$PATH:/usr/local/mysql/bin‘ > /etc/profile.d/mysql.sh
[[email protected] mysql]# source /etc/profile.d/mysql.sh
|
15. 登录MySQL测试
1
2
3
4
5
6
|
[[email protected] mysql]# mysql # 默认没有密码
Your MySQL connection id is 1
Server version: 5.5.40-log MySQL Community Server (GPL)
Copyright (c) 2000, 2014, Oracle and/or its affiliates. All rights reserved.
... ...
mysql>
|
MySQL修改密码后的登陆命令:mysql -u root -p Enter password: (输入密码)
二、Apache服务安装
apache可以通过yum的方式来安装,也可以通过源码编译的方式来安装,这里采用编译源码的方式进行安装。
1. 系统环境
CentOS 6.4 x86_64 Mini 版本安装
2. 下载解压apache安装包
1
2
3
|
[[email protected] src]# cd /usr/local/src
[[email protected] src]# tar zxf httpd-2.2.31.tar.gz
|
3. 安装必要的库和工具
1
|
[[email protected] src]# yum install -y pcre pcre-devel apr apr-devel zlib-devel gcc make
|
4. 配置编译参数
1
2
3
4
5
6
7
8
9
10
|
[[email protected] httpd-2.2.31]# cd httpd-2.2.31
[[email protected] httpd-2.2.31]# ./configure
--prefix=/usr/local/apache2
--with-included-apr
--enable-so
--enable-deflate=shared
--enable-expires=shared
--enable-rewrite=shared
--with-pcre
[[email protected] httpd-2.2.31]# echo $?
|
5. 编译安装
1
2
|
[[email protected] httpd-2.2.31]# make && make install
[[email protected] httpd-2.2.31]# echo $?
|
6. 配置apache环境变量
1
2
|
[[email protected] httpd-2.2.31]# echo ‘export PATH=$PATH:/usr/local/apache2/bin‘ > /etc/profile.d/http.sh
[[email protected] httpd-2.2.31]# source /etc/profile.d/http.sh
|
7. apache的启动和停止
1
2
3
4
5
|
apachectl start # 启动
apachectl stop # 停止
apachectl restart # 重启
apachectl -t # 检查语法
apachectl -M # 查看加载模块
|
8. 将apache加入系统服务
1
2
3
4
5
6
7
8
9
|
# 拷贝服务脚本
[[email protected] httpd-2.2.31]# cp /usr/local/apache2/bin/apachectl /etc/init.d/httpd
[[email protected] httpd-2.2.31]# vim /etc/init.d/httpd # 第一行下边添加2行内容
#!/bin/sh
# chkconfig: 2345 61 61
# description: Apache
# 添加到系统服务 并设置开机启动
[[email protected] httpd-2.2.31]# chkconfig --add httpd
[[email protected] httpd-2.2.31]# chkconfig httpd on
|
9. 验证服务是否正常
1
2
3
|
[[email protected] httpd-2.2.31]# service httpd start
httpd: apr_sockaddr_info_get() failed for vip # 出现警告信息
httpd: Could not reliably determine the server‘s fully qualified domain name, using 127.0.0.1 for ServerName
|
解决警告信息的方法:去掉 ServerName www.example.com:80 行的注释#。
三、PHP系统安装
1. 下载解压安装包
1
2
3
|
[[email protected] ~]# cd /usr/local/src
[[email protected] src]# wget http://cn2.php.net/get/php-5.5.38.tar.gz/from/this/mirror -O php-5.5.38.tar.gz
[[email protected] src]# tar zxf php-5.5.38.tar.gz
|
2. 下载依赖库和工具
1
2
3
|
[[email protected] src]# yum install -y epel-release
[[email protected] src]# yum install -y libxml2-devel openssl openssl-devel bzip2 bzip2-devel
libjpeg-devel libpng libpng-devel freetype freetype-devel libmcrypt-devel
|
3. 编译配置安装选项
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
|
[[email protected] php-5.5.38]# cd php-5.5.38
[[email protected]p php-5.5.38]# ./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
--enable-soap
--enable-gd-native-ttf
--enable-mbstring
--enable-sockets
--enable-exif
--disable-ipv6
|
4. 编译安装
1
2
|
[[email protected] php-5.5.38]# make && make install
[[email protected] php-5.5.38]# echo $?
|
5. 拷贝php配置文件
1
|
[[email protected] php-5.5.38]# cp php.ini-production /usr/local/php/etc/php.ini
|
6. 配置php环境变量
1
2
|
[[email protected] php-5.5.38]# echo ‘export PATH=$PATH:/usr/local/php/bin‘ > /etc/profile.d/php.sh
[[email protected] php-5.5.38]# source /etc/profile.d/php.sh
|
到此为止,php完成基本的编译安装,后续解析php还得另外配置。
四、配置支持php解析
1. 修改apache配置文件
1
2
3
4
5
6
|
<Directory />
Options FollowSymLinks
AllowOverride None
Order deny,allow
Allow from all # Deny修改为Allow
</Directory>
|
2. 支持php脚本解析
1
2
3
|
AddType application/x-compress .Z
AddType application/x-gzip .gz .tgz
AddType application/x-httpd-php .php # 添加这1行
|
3. 添加php索引支持
1
2
3
|
<IfModule dir_module>
DirectoryIndex index.html index.htm index.php # 添加php索引
</IfModule>
|
4. 测试配置语法和重启apache服务
1
2
3
|
[[email protected] ~]# apachectl -t
Syntax OK
[[email protected] ~]# service httpd restart
|
5. 测试php解析
编写测试文件:/usr/local/apache2/htdocs/index.php
1
2
3
|
<?php
echo "hello php!"
?>
|
命令行curl测试:
1
2
|
[[email protected] htdocs]# curl localhost/index.php
hello php![[email protected] htdocs]#
|
解析 php 成功!
以上是关于企业LAMP服务搭建的主要内容,如果未能解决你的问题,请参考以下文章