环境:192.168.80.102 主机名zlf3
关闭防火墙并关闭selinux服务
systemctl stop firewalld
setenforce 0
安装上传下载
yum install -y lrz*
tar xf apr-1.6.2.tar.gz -C /opt
tar xf apr-util-1.6.0.tar.gz -C /opt
tar xf httpd-2.4.37.tar.bz2 -C /opt/
mv apr-1.6.2/ httpd-2.4.37/srclib/apr
mv apr-util-1.6.0/ httpd-2.4.37/srclib/apr-util
添加C语言及其他库语言
yum -y install gcc gcc-c++ make pcre-devel expat-devel perl
cd /opt/httpd-2.4.37/
./configure --prefix=/usr/local/httpd --enable-so --enable-rewrite --enable-charset-lite --enable-cgi
编译并安装要一会时间
make && make install
cp /usr/local/httpd/bin/apachectl /etc/init.d/httpd
vi /etc/init.d/httpd
#chkconfig: 35 85 21 //3,5级别自动运行 第85个启动 第21个关闭 写在第二行
#description: Apache is a World Wide Web server
chkconfig --add httpd //将httpd加入到service管理器
vi /usr/local/httpd/conf/httpd.conf 源码编译的安装位置
去找ServerName
启动http服务
service httpd start
netstat -anpt | grep 80
ln -s /usr/local/httpd/conf/httpd.conf /etc 软连接将httpd.conf放在/etc下面
ln -s /usr/local/httpd/bin/* /usr/local/bin/ 将脚本文件加入到PATH环境变量
apachectl -t //检查apache配置文件语法错误
cd /usr/local/httpd/htdocs/
//源码编译安装apache网站服务的网页文件存在目录,即网页根目录
cat index.html
service httpd restart
访问192.168.80.102
显示It works
到此,Apache服务安装完成
以下安装mysql
yum -y install ncurses ncurses-devel bison cmake
useradd -s /sbin/nologin mysql //创建一个运行数据库服务的程序用户
tar xf mysql-boost-5.7.20.tar.gz -C /opt
cd /opt/mysql-5.7.20/
cmake \
-DCMAKE_INSTALL_PREFIX=/usr/local/mysql \
-DMYSQL_UNIX_ADDR=/usr/local/mysql/mysql.sock \
-DSYSCONFDIR=/etc \
-DSYSTEMD_PID_DIR=/usr/local/mysql \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_BLACKHOLE_STORAGE_ENGINE=1 \
-DWITH_PERFSCHEMA_STORAGE_ENGINE=1 \
-DMYSQL_DATADIR=/usr/local/mysql/data \
-DWITH_BOOST=boost \
-DWITH_SYSTEMD=1
关机给虚拟机添加内存为4G
make && make install //第一种方法
要等1个多小时
make -j8(真机几核的双倍)//第二种方法
make install 执行完make -j8在执行这个命令
到此数据库安装完成接下来改变归属
chown -R mysql:mysql /usr/local/mysql/
vi /etc/my.cnf MySQL默认主配置文件 进入删除
[client]
port = 3306
default-character-set=utf8
socket = /usr/local/mysql/mysql.sock
[mysql]
port = 3306
default-character-set=utf8
socket = /usr/local/mysql/mysql.sock
[mysqld]
user = mysql
basedir = /usr/local/mysql
datadir = /usr/local/mysql/data
port = 3306
character_set_server=utf8
pid-file = /usr/local/mysql/mysqld.pid
socket = /usr/local/mysql/mysql.sock
server-id = 1
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER,NO_AUTO_VALUE_ON_ZERO,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,PIPES_AS_CONCAT,ANSI_QUOTES
数据库模式,固定格式
chown mysql:mysql /etc/my.cnf
echo 'PATH=/usr/local/mysql/bin:/usr/local/mysql/lib:$PATH' >> /etc/profile 方便Linux系统识别
echo 'export PATH' >> /etc/profile 变为全局变量
source /etc/profile
cd /usr/local/mysql/ 在安装目录中进行初始化
bin/mysqld \
--initialize-insecure \
--user=mysql \
--basedir=/usr/local/mysql \
--datadir=/usr/local/mysql/data
cp usr/lib/systemd/system/mysqld.service /usr/lib/systemd/system/ 添加到systemctl管理器
systemctl daemon-reload 加载
systemctl start mysqld && systemctl enable mysqld
netstat -anpt | grep 3306
mysqladmin -u root -p password "abc123"
//给root账号设置密码为abc123 ,提示输入的是初始密码时,直接回车
到此安装数据库安装完成
以下安装PHP
PHP配置插件
yum -y install \
libjpeg \
libjpeg-devel \
libpng libpng-devel \
freetype freetype-devel \
libxml2 \
libxml2-devel \
zlib zlib-devel \
curl curl-devel \
openssl openssl-devel
以下两行可能用不到,如果报错有perl的,使用以下两行
vi /usr/local/httpd/bin/apxs
#!/usr/bin/perl -w
tar xf php-7.1.10.tar.bz2 -C /opt/ with代表支持 enable 启用模块
cd /opt/php-7.1.10/
./configure \
--prefix=/usr/local/php \
--with-apxs2=/usr/local/httpd/bin/apxs \
--with-mysql-sock=/usr/local/mysql/mysql.sock \
--with-mysqli \
--with-zlib \
--with-curl \
--with-gd \
--with-jpeg-dir \
--with-png-dir \
--with-freetype-dir \
--with-openssl \
--enable-mbstring \
--enable-xml \
--enable-session \
--enable-ftp \
--enable-pdo \
--enable-tokenizer \
--enable-zip \
--enable-fpm
编译并安装要等10分钟
make && make install
cp php.ini-development /usr/local/php/lib/php.ini
vi /usr/local/php/lib/php.ini
mysqli.default_socket = /usr/local/mysql/mysql.sock 指定sock文件位置 在里面找到/mysqli.default_socket =号两边都有空格
date.timezone = Asia/Shanghai 去掉#更改时区 在里面找到/date.timezone =
/usr/local/php/bin/php -m //验证安装的模块
vi /etc/httpd.conf //在合适位置新增,相近原则
AddType application/x-httpd-php .php 找这两行相似的 添加这两行
AddType application/x-httpd-php-source .phps
DirectoryIndex index.html index.php 找/Dir 加上index.php
到源码安装的apache的网页根目录中删掉index.html文件,新增index.php用来测试
cd /usr/local/httpd/htdocs/
rm -f index.html
vi index.php
访问:192.168.80.102
到此,说明apache与php连接成功
下面测试数据库工作是否正常
mysql -u root -pabc123
create database myadm; 创建新的数据库mydam
grant all on myadm.* to 'admin'@'%' identified by 'admin123'; 允许用户mydam在任何地方通过admin123登录
flush privileges;
exit;
vi /usr/local/httpd/htdocs/index.php
Success!!";
else echo "Fail!!
";
?>
换成这个用来测试apache与数据库连通情况,出现success说明两者能正常连接
到此,整个LAMP搭建成功
以下安装phpMyadmin
yum install -y unzip
unzip phpMyAdmin-4.8.3-all-languages.zip -d /opt/
cd /opt
mv phpMyAdmin-4.8.3-all-languages /usr/local/httpd/htdocs/myadm
把phpMy的名字改为myadm
cd /usr/local/httpd/htdocs/myadm
cp config.sample.inc.php config.inc.php
vi config.inc.php
c f g [ ′ S e r v e r s ′ ] [ cfg['Servers'][ cfg[′Servers′][i][‘host’] = ‘127.0.0.1’; //把localhost 改成IP 31行
http://192.168.80.102/myadm
管理数据库:使用root以及前面为abc123配置的密码登录管理系统