1、准备
1、添加3306和80防火墙例外
步骤1:vi /etc/sysconfig/iptables
步骤2:service iptables restart #重启防火墙
2、卸载默认安装的MySQL和Apache
步骤1:分别通过【rpm -qa | grep mysql】和【rpm -qa | grep http】查看已经安装的软件包名称
步骤2:通过【rpm -e 查看的包名 –nodeps】卸载
步骤3:再通过【rpm -qa | grep mysql】和【rpm -qa | grep http】检查是否全部卸载
3、环境目录初始化
# 创建目录
mkdir -p /php/tools
mkdir -p /php/wwwroot
mkdir -p /php/server/php
mkdir -p /php/server/mysql
mkdir -p /php/server/apache
mkdir -p /php/server/data # MySQL数据存放目录
4、将本地安装包上传到服务器/php/tools目录中
2、Linux下源代码包一般安装步骤
步骤1:解压 (tar命令)
步骤2:进入到解压目录 (cd命令)
步骤3:配置(收集服务器信息、指定安装目录等)
./configure –prefix=指定安装目录
步骤4:编译 (make) 说明:make是将源代码文件编译成二进制文件
步骤5:安装 (make install) 说明:将二进制文件移动到指定目录中
3、安装MySQL
1、安装依赖cmake
shell> cd /php/tools/mysql #进入tools目录
shell> tar zxvf cmake-2.8.5.tar.gz #解压cmake安装包
shell> cd cmake-2.8.5 #进入解压目录
shell> ./bootstrap
shell> make && make install #源代码文件 -> 进行编译 -> 二进制文 && 安装
2、安装ncurses-devel(MySQL依赖)
shell> cd /php/tools/mysql #进入tools目录
shell> rpm -ivh ncurses-devel-5.7-3.20090208.el6.i686.rpm #通过rpm命令安装
3、安装MySQL
1)安装
shell> cd /php/tools/mysql #进入tools目录
shell> tar -zxvf mysql-5.6.35.tar.gz #解压MySQL安装包
shell> cd mysql-5.6.35 #进入解压目录
shell> #配置
shell> #配置
cmake \
-DCMAKE_INSTALL_PREFIX=/php/server/mysql \
-DMYSQL_DATADIR=/php/server/data \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci
shell> make && make install #源代码文件 -> 进行编译 -> 二进制文 && 安装
2)配置
复制安装目录中的MySQL配置文件,到/etc/my.cnf
shell> cp -r /php/tools/mysql/mysql-5.6.35/support-files/my-default.cnf /etc/my.cnf
修改MySQL配置文件
shell> vi /etc/my.cnf
#在[mysqld]下设置这一行:datadir = /php/server/data (修改配置文件声明MySQL数据存放目录)
创建MySQL用户组并创建用户加入用户组(-s /sbin/nologin参数表示用户不能登录)
shell> groupadd mysql
shell> useradd -g mysql -s /sbin/nologin mysql
将mysql文件的拥有者改为mysql组的mysql用户
shell> chown -R mysql:mysql /php/server/data/
shell> chown -R mysql:mysql /php/server/mysql/
#说明:工作中需要管理mysql 通过root用户显然权限太大,所以单独新建mysql用户管理(后面等初始化数据后,将msyql安装目录的主人改为root用户,因为生产环境中只需要针对 data 数据目录有写权限)
初始化数据库
shell> /php/server/mysql/scripts/mysql_install_db \
–basedir=/php/server/mysql \
–datadir=/php/server/data \
–user=mysql
把mysql安装文件(除了data)的主人都改为root,避免数据库恢复为出厂设置。
shell> chown -R root /php/server/mysql
&后台运行mysql服务
shell> /php/server/mysql/bin/mysqld_safe –user=mysql &
验证:是否安装成功(查看mysql是否有启动)
shell> ps -A | grep mysql
初始化数据库,设置root帐户的密码(默认密码空)
shell> /php/server/mysql/bin/mysql -uroot -p #回车输入密码
drop database test; — 删除测试数据库
delete from mysql.user where user=”; — 删除本机匿名连接的空密码帐号
# 修改密码
update mysql.user set password=password(‘admin888′) where user=’root’;
flush privileges;
4、安装Apache
1、安装zlib
shell> cd /php/tools/apache #进入tools目录
shell> tar zxvf zlib-1.2.5.tar.gz #解压zlib安装包
shell> cd zlib-1.2.5 #进入解压目录
shell> ./configure #这个配置编译命令不要加目录参数
shell> make && make install #源代码文件 -> 进行编译 -> 二进制文 && 安装
2、安装apache
■安裝
shell> cd /php/tools/apache #进入tools目录
shell> tar -jxvf httpd-2.2.19.tar.bz2 #解压apache安装包
shell> cd httpd-2.2.19 #进入解压目录
shell> #配置
./configure –prefix=/php/server/apache \
–enable-modules=all \
–enable-mods-shared=all \
–enable-so
shell> make && make install #源代码文件 -> 进行编译 -> 二进制文 && 安装
■启动Apache
shell> vi /php/server/apache/conf/httpd.conf
shell> /php/server/apache/bin/apachectl start/stop/restart
■测试(脚下留心:记得关闭防火墙或者添加80端口例外)
浏览器打开: http://虚拟机IP
看到 “it works!”,即为成功
3、配置虚拟主机
步骤1:配置host文件
打开C:/windows/system32/drivers/etc/hosts 文件
增加域名记录
如:
这里写自己Linux的IP地址 www.one.com
这里写自己Linux的IP地址 www.two.com
步骤2:引入虚拟主机文件
shell> vi /php/server/apache/conf/httpd.conf
#引入自定义虚拟主机(写在apache配置文件最后一行)
Include conf.d/*.conf
步骤3:增加虚拟主机1
shell> mkdir -p /php/server/apache/conf.d/
shell> vi /php/server/apache/conf.d/one.conf
NameVirtualHost *:80
# 需要绑定的域名(改1)
ServerName www.one.com
# 绑定多个域名
# 设置默认的访问的页面
DirectoryIndex index.php index.html index.htm
# 指定网站/站点目录(虚拟主机)(改2)
DocumentRoot “/php/wwwroot/one/”
# 指定目录的权限(改3)
<Directory “/php/wwwroot/one/”>
# 如果首页不存在,则显示目录列表(Options Indexes FollowSymLinks)
Options Indexes FollowSymLinks
# 允许哪些IP访问虚拟主机
Allow from All
步骤4:增加虚拟主机2
shell> vi /php/server/apache/conf.d/two.conf
# 需要绑定的域名(改1)
ServerName www.two.com
# 绑定多个域名
# 设置默认的访问的页面
DirectoryIndex index.php index.html index.htm
# 指定网站/站点目录(虚拟主机)(改2)
DocumentRoot “/php/wwwroot/two/”
# 指定目录的权限(改3)
<Directory “/php/wwwroot/two/”>
# 如果首页不存在,则显示目录列表(Options Indexes FollowSymLinks)
Options Indexes FollowSymLinks
# 允许哪些IP访问虚拟主机
Allow from All
步骤5:创建虚拟主机目录
shell>mkdir -p /php/wwwroot/one /php/wwwroot/two
shell>echo one > /php/wwwroot/one/index.html
shell>echo two > /php/wwwroot/two/index.html
步骤6:重启apache
shell> /php/server/apache/bin/apachectl restart
步骤7:浏览器打开www.one.com和www.two.com
看到不同的网站内容,虚拟主机创建完毕!
5、安装PHP
■说明:安装图形库,为编译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
1、安装libxml2
shell> cd /php/tools/php
shell> tar -zxvf libxml2-2.7.2.tar.gz
shell> cd libxml2-2.7.2
shell> ./configure –prefix=/php/server/libxml2 –without-zlib
shell> make && make install
2、安装jpeg8
shell> cd /php/tools/php
shell> tar -zxvf jpegsrc.v8b.tar.gz
shell> cd jpeg-8b
shell> ./configure –prefix=/php/server/jpeg –enable-shared –enable-static
shell> make && make install
3、安装libpng
shell> cd /php/tools/php
shell> tar zxvf libpng-1.4.3.tar.gz
shell> cd libpng-1.4.3
shell> ./configure –prefix=/php/server/png
shell> make && make install
4、安装freetype(字体库)
shell> cd /php/tools/php
shell> tar zxvf freetype-2.4.1.tar.gz
shell> cd freetype-2.4.1
shell> ./configure –prefix=/php/server/freetype
shell> make && make install
5、安装GD库
shell> cd /php/tools/php
shell> tar -zvxf gd-2.0.35.tar.gz
shell> mkdir -p /php/server/gd
shell> cd gd-2.0.35
shell> ./configure –prefix=/php/server/gd \
–with-jpeg=/php/server/jpeg \
–with-png –with-zlib \
–with-freetype=/php/server/freetype
shell> make && make install
6、安装PHP
shell> cd /php/tools/php
shell> tar -zxvf php-5.6.31.tar.gz
shell> cd php-5.6.31
shell> 配置复制
./configure –prefix=/php/server/php \
–with-apxs2=/php/server/apache/bin/apxs \
–with-mysql=mysqlnd \
–with-pdo-mysql=mysqlnd \
–with-mysqli=mysqlnd \
–with-freetype-dir=/php/server/freetype \
–with-gd \
–with-zlib –with-libxml-dir=/php/server/libxml2 \
–with-jpeg-dir=/php/server/jpeg \
–with-png-dir=/php/server/png \
–enable-mbstring=all \
–enable-mbregex \
–enable-shared
shell> make && make install
■ 配置Apache支持PHP
步骤1:复制php.ini配置文件到指定目录
shell> cp -rf php.ini-development /php/server/php/lib/php.ini
步骤2:修改Apache配置文件
shell> vi /php/server/apache/conf/httpd.conf
#在httpd.conf(Apache主配置文件)中增加:AddType application/x-httpd-php .php
步骤3:重启apache
shell> /php/server/apache/bin/apachectl stop
shell> /php/server/apache/bin/apachectl start
步骤4:查看效果
#再次浏览器查看http://虚拟机IP 如果看到php信息,工作就完成了!
哈哈哈,老王!