一 环境搭建
(1)关闭防火墙
systemctl status firewalld //查看防火墙是否关闭
systemctl stop firewalld //关闭防火墙
setenforce 0 //临时关闭se或彻底关闭se需要进config目录里关闭,如下:
vi /etc/selinux/config //进入config目录
把红框内的enforcing改成disabled就可以了(上图为修改完的)
(2)安装常用工具
yum install -y vim gcc net-tools tree
// vim 是vi编译器的升级版 gcc 是编译二进制源码包需要
// net-tools 自带两个命令 (ifconfig 查看网络)和(netstat 查看端口占用情况)
// tree 以树状形式查看目录结构。
(3)上传安装包
上传安装包至 /opt 目录下
两种方法:一个是使用xftp 从windos本地上传,二是使用XShell
(下载源码包的地址:https://aminglinux.coding.net/public/resource/resource/git/files)
二、安装
MySQL安装
1、解压 tar -zxvf mysql-5.6.47-linux-glibc2.12-x86_64.tar.gz
mv mysql-5.6.47-linux-glibc2.12-x86_64 /usr/local/mysql
2、创建MySQL用户
useradd -s /sbin/nologin mysql
3、初始化
mkdir -p /data/mysql //创建MySQL数据存储目录
chown -R mysql:mysql /data/mysql //更改权限
4、安装
yum install -y perl-Module-Install #安装脚本执行环境perl
[root@localhost ~]# cd /usr/local/mysql/
./scripts/mysql_install_db --user=mysql --datadir=/data/mysql
- -user 指定MySQL用户 ---datadir 指定数据存放目录
5、配置
# 修改配置文件:
cp /usr/local/mysql/support-files/my-default.cnf /etc/my.cnf
vim /etc/my.cnf
# 主要是修改basedir 和datadir
basedir = /usr/local/mysql
datadir = /data/mysql
port = 3306
server_id = 50
socket = /tmp/mysql.sock
#basedir 设置MySQL安装的目录
#datadir MySQL数据存放的目录
# port mysql的端口号 #server_id 一般是集群的时候需要,一般设置为ip地址最后一位
# socket
5.2修改启动脚本
[root@localhost mysql]# cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
[root@localhost mysql]# vim /etc/init.d/mysqld
basedir=/usr/local/mysql
datadir=/data/mysql
5.3 启动MySQL,设置开机自启
[root@localhost mysql]# service mysqld start
Starting MySQL.Logging to '/data/mysql/localhost.localdomain.err'.
..... SUCCESS!
[root@localhost mysql]# chkconfig --add mysqld
[root@localhost mysql]# chkconfig mysqld on
# 查看服务是否启动。 MySQL 3306端口
[root@localhost mysql]# netstat -ntlp
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 1463/sshd
tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 2620/master
tcp6 0 0 :::3306 :::* LISTEN 3114/mysqld
tcp6 0 0 :::22 :::* LISTEN 1463/sshd
tcp6 0 0 ::1:25 :::* LISTEN 2620/maste
源码安装apache
解压
[root@localhost opt]# tar -zxvf httpd-2.4.33.tar.gz
[root@localhost opt]# tar -zxvf apr-1.5.1.tar.gz
[root@localhost opt]# tar -zxvf apr-util-1.5.4.tar.gz
[root@localhost opt]# ls
apr-1.5.1 httpd-2.4.33
apr-1.5.1.tar.gz httpd-2.4.33.tar.gz
apr-util-1.5.4 mysql-5.6.47-linux-glibc2.12-x86_64.tar.gz
apr-util-1.5.4.tar.gz phpredis-develop.zip
安装apr
检查编译安装结果是否正确 如果输出是0就代表运行正确。
[root@localhost apr-1.5.1]# echo $?
安装apr-util
[root@localhost apr-util-1.5.4]#./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr
[root@localhost apr-util-1.5.4]# make && make install
[root@localhost apr-util-1.5.4]# echo $?
如果有依赖之类的报错,就安装这些依赖
[root@localhost apr-1.5.1]# yum install -y libtool pcre-devel
[root@localhost apr-1.5.1]# cd ../httpd-2.4.33
[root@localhost httpd-2.4.33]# ./configure --prefix=/usr/local/apache2.4 --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util --enable-so --enable-mods-shared=most
[root@localhost httpd-2.4.33]# make && make install
查看加载了哪些模块
[root@localhost httpd-2.4.33]# /usr/local/apache2.4/bin/httpd -M
安装PHP
解压:
[root@localhost opt]# yum install -y bzip2
[root@localhost opt]# tar jxvf php-5.6.39.tar.bz2
[root@localhost opt]# cd php-5.6.39
[root@localhost php-5.6.39]# yum install -y libxml2-devel openssl openssl-devel bzip2 bzip2-devel libpng libpng-devel freetype freetype-devel epel-release libmcrypt-devel
[root@localhost php-5.6.39]# ./configure --prefix=/usr/local/php --with-apxs2=/usr/local/apache2.4/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
[root@localhost php-5.6.39]# make && make install
[root@localhost php-5.6.39]# cp php.ini-production /usr/local/php/etc/php.ini
配置httpd支持PHP
修改配置文档
[root@localhost php-5.6.39]# vim /usr/local/apache2.4/conf/httpd.conf
//编辑httpd的主配置文件
①、搜索ServerName,把ServerName www.example.com:80前#去掉;
②、<Directory />
AllowOverride none
Require all denied
</Directory>
改成:
<Directory />
AllowOverride none
Require all granted
</Directory> //目的允许所有请求访问
③、搜索AddType application/x-gzip .gz .tgz,
在下面添加一行 AddType application/x-httpd-php .php
④、<IfModule dir_module>
DirectoryIndex index.html
</IfModule>
改成:
<IfModule dir_module>
DirectoryIndex index.html index.php
</IfModule>
测试apache服务
# 显示Syntax OK即可代表配置成功、如果没有显示这个,代表配置错误,继续配置
[root@localhost php-5.6.39]# /usr/local/apache2.4/bin/apachectl -t
Syntax OK
# 启动服务 [root@localhost php-5.6.39]# /usr/local/apache2.4/bin/apachectl start
# 有httpd服务占用80即可
[root@localhost php-5.6.39]# netstat -ntlp |grep httpd
tcp6 0 0 :::80 :::* LISTEN 120180/httpd
[root@localhost php-5.6.39]# curl localhost
<html><body><h1>It works!</h1></body></html>
测试PHP解析是否正常
[root@localhost php-5.6.39]# vim /usr/local/apache2.4/htdocs/1.php
<?php
echo "PHP解析正常"
?>
[root@localhost php-5.6.39]# curl localhost/1.php
PHP解析正常
LAMP环境搭建完成