lamp完整安装
LAMP环境配置安装注意安装步骤及说明事项。
1. 访问ftp报错
解决:
关闭 selinux
vi /etc/selinux/config
内容修改为: selinux=disable
之后重启reboot。
下图分别为selinux关闭前 和 关闭后:
一、安装gcc
gcc(gcc-4.4.7-3.el6.i686.rpm)
cloog-ppl(cloog-ppl-0.15.7-1.2.el6.i686.rpm)
ppl(cloog-ppl-0.15.7-1.2.el6.i686.rpm)
libppl.so.7
libppl_c.so.2
(ppl-0.10.2-11.el6.i686.rpm)
cpp(cpp-4.4.7-3.el6.i686.rpm)
libmpfr.so.1(mpfr-2.4.1-6.el6.i686.rpm)
glibc-devel(glibc-devel-2.12-1.107.el6.i686.rpm)
glibc-headers(glibc-headers-2.12-1.107.el6.i686.rpm)
kernel-headers(kernel-headers-2.6.32-358.el6.i686.rpm)
gcc-c++ (gcc-c+±4.4.7-3.el6.i686.rpm)
libstdc+±devel(libstdc+±devel-4.4.7-3.el6.i686.rpm)
二、初始化
1.1 关闭防火墙(线下测试)
shell> service iptables stop
关闭防火墙(线上项目操作)
sed '/22/a -A INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT' -i /etc/sysconfig/iptables
sed '/80/a -A INPUT -m state --state NEW -m tcp -p tcp --dport 3306 -j ACCEPT' -i /etc/sysconfig/iptables
1.2 关闭SELinux
打开/etc/selinux/config文件修改
1.3 检测是否已经安装apache 、mysql、php
shell> rpm -qa | grep mysql
shell> rpm -qa | grep php
shell> rpm -qa | grep httpd
rpm -e mysql //普通删除模式
rpm -e mysql --nodeps // 强力删除模式,上面命令删除提示有依赖的其它文件,用该命令可以对其进行强力删除
1.4 卸载
shell> yum -y remove httpd php-* mysql-*
1.5 说明
#创建目录
shell> mkdir -p /php0225/wwwroot
shell> mkdir -p /php0225/server/php
shell> mkdir -p /php0225/server/mysql
shell> mkdir -p /php0225/server/apache
shell> mkdir -p /php0225/server/data # MySQL数据存放目录
/php0225/tools 存放安装工具
/php0225/wwwroot 根目录用于存放网站
/php0225/wwwroot/a 开启虚拟主机(多站点)a项目
/php0225/wwwroot/b 开启虚拟主机(多站点)b项目
/php0225/server apache、mysql、php等软件安装目录
/php0225/server/php php安装目录
/php0225/server/mysql mysql安装目录
/php0225/server/apache apache安装目录
三、安装MySQL
- 安装cmake(更先进的configure)
shell> cd /php0225/tools
shell> tar zxvf cmake-2.8.5.tar.gz
shell> cd cmake-2.8.5
shell> ./bootstrap
shell> make && make install
- 安装依赖ncurses和ncurses-devel否则下面会报错
bison :MySQL语法解析器需要使用bison进行编译。
ncurses-devel :用于终端操作的开发包。
shell> tar -zxvf bison-2.7.tar.gz
shell> cd bison-2.7
shell> ./configure && make && make install
//在光盘安挂载目录安装【ncurses-devel-5.7-3.20090208.el6.i686.rpm】
shell> rpm -ivh ncurses-devel-5.7-3.20090208.el6.i686.rpm
- 编译安装MySQL
shell> cd /php0225/tools
shell> tar zxvf mysql-5.5.17.tar.gz
shell> cd mysql-5.5.17
shell> cmake \
-DCMAKE_INSTALL_PREFIX=/php0225/server/mysql \
-DMYSQL_DATADIR=/php0225/server/data \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci
shell> make && make install
shell> \cp -f support-files/my-medium.cnf /etc/my.cnf # 复制MySQL配置文件
说明:\cp中 “\”忽略按y提示
【MySQL cmake 常规参数介绍】
-DCMAKE_INSTALL_PREFIX= 安装根目录
-DMYSQL_DATADIR= 数据存储目录
-DDEFAULT_CHARSET=utf8 指定默认的字符集为utf8
-DDEFAULT_COLLATION=utf8_general_ci 设定默认排序规则
- 配置并初始化MySQL
#创建MySQL用户组并创建用户加入用户组
shell> groupadd mysql
shell> useradd -g mysql -s /sbin/nologin mysql
//将mysql文件的拥有者改为mysql组的mysql用户
shell> chown -R mysql:mysql /php0225/server/data/
shell> chown -R mysql:mysql /php0225/server/mysql/
//初始化数据库
shell> /php0225/server/mysql/scripts/mysql_install_db \
--basedir=/php0225/server/mysql \
--datadir=/php0225/server/data \
--user=mysql
//把mysql安装文件(除了data)的主人都改为root,避免数据库恢复为出厂设置。
shell> chown -R root /php0225/server/mysql
//&后台运行mysql服务
shell> /php0225/server/mysql/bin/mysqld_safe --user=mysql &
//mysql在启动时没有指定配置文件时会使用/etc/my.cnf配置文件,请打开这个文件查看在[mysqld]节下有没有指定数据目录(datadir)。
解决方法:请在[mysqld]下设置这一行:datadir = /php0225/server/data
//查看mysql是否有启动
shell> ps -A | grep mysql
- 初始化,设置root帐户的密码
//登陆数据库(默认密码空)
shell> /php0225/server/mysql/bin/mysql -uroot -p
//默认项目配置
mysql> drop database test; //删除测试数据库
mysql> delete from mysql.user where user=''; //删除本机匿名连接的空密码帐号
//修改密码
Cd php0225
Cd server
Cd mysql
Ll
[root@localhost mysql]# ./bin/mysql_secure_installation
mysql> update mysql.user set password=password(‘admin888’) where user='root';
mysql> delete from mysql.user where not (user='root') ;
mysql> flush privileges;
mysql> exit
四、安装zlib压缩库
shell> cd /php0225/tools
shell> tar -zxvf zlib-1.2.5.tar.gz
shell> cd zlib-1.2.5
shell> ./configure //这个配置编译命令不要加目录参数
shell> make && make install
说明:安装apache需要先安装zlib库否则编译报错
mod_deflate has been requested but can not be built due to prerequisite failures(ubuntu centent
五、安装apache
1) 安装
shell> cd /php0225/tools
shell> tar -jxvf httpd-2.2.19.tar.bz2
shell> cd httpd-2.2.19
shell> ./configure --prefix=/php0225/server/apache \
--enable-modules=all \
--enable-mods-shared=all \
--enable-so
shell> make && make install
说明:
//--enable-mods-shared=all // 编译所有模块
//--enable-so // 参数是使httpd服务能够动态加载模块功能,让 Apache 可以支持DSO模式,注意,这里采用的是 Apache2.0 的语法。如果你的Apache 是1.3版本,应改为--enable-module=so(打开 so 模块,so 模块是用来提 DSO 支持的 apache 核心模块)
2) 启动Apache
shell> /php0225/server/apache/bin/apachectl start/stop/restart
httpd: Could not reliably determine the server’s fully qualified domain name, using localhost.localdomain for ServerName
解决:
1、用记事本打开 httpd.conf
2、将里面的 #ServerName localhost:80 注释去掉即可。
3、重启apache
3) 测试
浏览器打开: http://虚拟机IP
看到 “it works!”,即为成功
4) 配置虚拟主机
- 配置host文件
打开C:/windows/system32/drivers/etc/hosts 文件
增加域名记录
如:
192.168.xxx.xxx www.one.com
192.168.xxx.xxx www.two.com - 增加虚拟主机
vi /php0225/server/apache/conf/httpd.conf
引入自定义虚拟主机
Include conf.d/*.conf
保存退出
【增加虚拟主机记录1】
vi /php0225/server/apache/conf.d/one.conf
NameVirtualHost *:80
<VirtualHost *:80>
# 需要绑定的域名(改1)
ServerName www.one.com
# 绑定多个域名
# 设置默认的访问的页面
DirectoryIndex index.php index.html index.htm
# 指定网站/站点目录(虚拟主机)(改2)
DocumentRoot "/php0225/wwwroot/one/"
# 指定目录的权限(改3)
<Directory "/php0225/wwwroot/one/">
# 如果首页不存在,则显示目录列表(Options Indexes FollowSymLinks)
Options Indexes FollowSymLinks
# 允许哪些IP访问虚拟主机
Allow from All
</Directory>
【增加虚拟主机记录2】
vi /php0225/server/apache/conf.d/two.conf
<VirtualHost *:80>
# 需要绑定的域名(改1)
ServerName www.two.com
# 绑定多个域名
# 设置默认的访问的页面
DirectoryIndex index.php index.html index.htm
# 指定网站/站点目录(虚拟主机)(改2)
DocumentRoot "/php0225/wwwroot/two/"
# 指定目录的权限(改3)
<Directory "/php0225/wwwroot/two/">
# 如果首页不存在,则显示目录列表(Options Indexes FollowSymLinks)
Options Indexes FollowSymLinks
# 允许哪些IP访问虚拟主机
Allow from All
</Directory>
-
重启apache
/php0225/server/apache/bin/apachectl restart -
浏览器打开www.one.com,和www.two.com
看到不同的网站内容,虚拟主机创建完毕!安装图形库,为编译PHP做准备
libxml2-2.7.2.tar.gz
jpegsrc.v8b.tar.gz
libpng-1.4.3.tar.gz
freetype-2.4.1.tar.gz
gd-2.0.35.tar.gz
六、安装libxml2
shell> cd /php0225/tools
shell> tar zxvf libxml2-2.7.2.tar.gz
shell> cd libxml2-2.7.2
shell> ./configure --prefix=/php0225/server/libxml2 \
--without-zlib
shell> make && make install
七、安装jpeg8
shell> cd /php0225/tools
shell> tar -zxvf jpegsrc.v8b.tar.gz
shell> cd jpeg-8b
shell> ./configure --prefix=/php0225/server/jpeg \
--enable-shared --enable-static
shell> make && make install
//--enable-shared 解释把jpeg需要的函数库程序都编译到该软件里边
//优点:函数调用速度快 缺点:软件本身比较大
//--enable-static 静态方式函数处理,需要什么函数,马上include来
//优点:软件本身比较小 缺点:函数调用速度慢
八、安装libpng
shell> cd /php0225/tools
shell> tar zxvf libpng-1.4.3.tar.gz
shell> cd libpng-1.4.3
shell> ./configure #和zlib一样不要带参数,让它默认安装到相应目录
shell> make && make install
九、安装freetype(字体库)
shell> cd /php0225/tools
shell> tar zxvf freetype-2.4.1.tar.gz
shell> cd freetype-2.4.1
shell> ./configure --prefix=/php0225/server/freetype
shell> make && make install
十、安装GD库
shell> cd /php0225/tools
shell> tar -zvxf gd-2.0.35.tar.gz
shell> mkdir -p /php0225/server/gd
shell> cd gd-2.0.35
shell> ./configure --prefix=/php0225/server/gd \
--with-jpeg=/php0225/server/jpeg/ \
--with-png --with-zlib \
--with-freetype=/php0225/server/freetype
shell> make && make install
十一、安装 php5
安装
shell> cd /php0225/tools
shell> tar -jxvf php-5.3.6.tar.bz2
shell> cd php-5.3.6
shell> ./configure --prefix=/php0225/server/php \
--with-apxs2=/php0225/server/apache/bin/apxs \
--with-mysql=mysqlnd \
--with-pdo-mysql=mysqlnd \
--with-mysqli=mysqlnd \
--with-freetype-dir=/php0225/server/freetype \
--with-gd=/php0225/server/gd \
--with-zlib --with-libxml-dir=/php0225/server/libxml2 \
--with-jpeg-dir=/php0225/server/jpeg \
--with-png-dir \
--enable-mbstring=all \
--enable-mbregex \
--enable-shared
shell>make && make install
//复制php.ini配置文件到指定目录
shell>\cp -f php.ini-development /php0225/server/php/lib/php.ini
//配置Apache使其支持php
vi /php0225/server/apache/conf/httpd.conf
//在httpd.conf(Apache主配置文件)中增加:
AddType application/x-httpd-php .php
//找到下面这段话:
<IfModule dir_module>
DirectoryIndex index.html
</IfModule>
在index.html 前面添加index.php
建立php测试网页
输入如下内容:
<?php phpinfo(); ?>重启apache
shell># /php0225/server/apache/bin/apachectl restart
再次浏览器查看http://虚拟机IP
如果看到php信息,工作就完成了!
十二、配置apache和mysql配置为开机启动
使用vim打开 /etc/rc.local,
linux系统每次启动后都会自动执行这个文件,在该文件中,加入以下两行内容:
/php0225/server/apache/bin/apachectl start
/php0225/server/mysql/bin/mysqld_safe --user=mysql &
切记防火墙!