手动搭建自己的lnmp环境:linux+nginx+mysql+php
hostnamectl set-hostname legend //修改主机名
yum install vim //安装vim命令
yum -y install wget // 安装wget命令
vim /etc/sysconfig/network-scripts/ifcfg-enp0s25 //修改网卡
vim /etc/resolv.conf //修改主机的DNS解析
reboot // 修改主机配置后重启机器
cd /etc/yum.repos.d/
#修改镜像源位置,添加epel源,这里选用的是阿里的库文件
mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo
yum clean all //清理系统缓存的源
yum makecache //更新新的源缓存
#关闭系统防火墙,及禁止防火墙开机自启
systemctl stop firewalld
systemctl disabled firewalld
yum -y install httpd //安装Apache
systemctl start httpd //启动Apache
systemctl enable httpd //设置Apache开机启动
systemctl status httpd //确认httpd运行状态
vim /etc/httpd/conf/httpd.conf //修改Apache配置文件
systemctl restart httpd //修改服务配置后,重启httpd服务
cd /var/www/html/ //进入配置网页页面所在文件夹
vim index.html //创建网页文件,在文件内编辑输入ceshi,保存退出
curl http://192.168.1.158 //请求页面,测试请求结果
wget https://dev.mysql.com/get/mysql57-community-release-el7-11.noarch.rpm //下载mysql的rpm包
rpm -Uvh mysql57-community-release-el7-11.noarch.rpm //rpm安装后会出现mysql的库文件
yum -y install mysql-community-server //安装mysql
systemctl start mysqld //启动mysql
systemctl enable mysqld //设置mysql开机自启
cat /var/log/mysqld.log | grep password //查找mysql初始密码,十二位,区分大小写,含数字、特殊字符
mysql -uroot -p //根据查到的密码登录数据库,注意特殊字符也是密码的一部分
alter user 'root'@'localhost' identified by 'Ccipa@361'; //登录后必须先修改密码才能进行后续操作
#退出mysql按“\q”或者输入“exit;”然后回车
#登录mysql查看编码格式:
show variables like 'character%';
#修改编码格式
vim /etc/my.cnf
在[mysqld]之前添加
[client]
default-character-set=utf8
在[mysqld]之后添加
character-set-server=utf8
rpm -Uvh http://rpms.famillecollet.com/enterprise/remi-release-7.rpm //添加PHP的yum库
yum list --enablerepo=remi --enablerepo=remi-php56 | grep php //查看PHP可安装版本
yum install --enablerepo=remi --enablerepo=remi-php56 php php-opcache php-pecl-apcu php-devel php-mbstring php-mcrypt php-mysqlnd php-phpunit-PHPUnit php-pecl-xdebug php-pecl-xhprof php-pdo php-pear php-fpm php-cli php-xml php-bcmath php-process php-gd php-common //安装PHP5.6
php -v //确认安装的PHP版本
yum -y install nginx //安装nginx
systemctl stop firewalld //关闭防火墙
systemctl stop httpd //关闭Apache;若不关闭Apache,需更改端口号,防止与nginx冲突
systemctl start nginx //启动nginx;
systemctl enable nginx //设置nginx开机自启