此处的lnmp分别指:centos7.2,nginx1.14,mysql5.7,php7.2
修改yum源
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-6.repo
wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-6.repo
安装nginx
- 1 新建文件
/etc/yum.repos.d/nginx.repo
,内容如下:
[nginx]
name=nginx repo
baseurl=http://nginx.org/packages/centos/$releasever/$basearch/
gpgcheck=0
enabled=1
- 2 使用remi源
// 追加CentOS 6.5的epel及remi源
rpm -Uvh http://ftp.iij.ad.jp/pub/linux/fedora/epel/6/x86_64/epel-release-6-8.noarch.rpm
rpm -Uvh http://rpms.famillecollet.com/enterprise/remi-release-6.rpm
// CentOS 7.0的源。
yum install epel-release -y
rpm -ivh http://rpms.famillecollet.com/enterprise/remi-release-7.rpm
- 3 安装nginx
yum install -y nginx
// 启动
nginx
安装mysql
- 1 安装数据库
// 查看系统版本
cat /etc/redhat-release
CentOS Linux release 7.2.1511 (Core)
//下载YUM库
wget http://dev.mysql.com/get/mysql57-community-release-el7-7.noarch.rpm
//安装YUM库
yum localinstall -y mysql57-community-release-el7-7.noarch.rpm
//安装数据库
yum install -y mysql-community-server
//启动MySQL服务
systemctl enable mysqld.service
systemctl start mysqld.service
- 2 配置数据库
//安装完毕后,会在/var/log/mysqld.log 中能看到默认的密码
cat /var/log/mysqld.log |grep "A temporary password is generated"
(=zftZwCO9ys
//登陆
mysql -uroot -p
//修改密码
ALTER USER 'root'@'localhost' IDENTIFIED BY 'MyNewPass4!';
//可选:允许root远程访问
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'youpassword' WITH GRANT OPTION;
// 更新
flush privileges;
//有时会因为系统默认安装的防火墙导致无法访问
可关闭防火墙
systemctl stop firewalld.service #停止firewall
systemctl disable firewalld.service #禁止firewall开机启动
安装php
// 可选卸载原PHP版本
yum -y remove php*
// 更新rpm
rpm -Uvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm
// 可选,查看可安装版本列表,可以发现从4-7.2的版本都有,7.2版本名为72w
yum list php*
// 安装php72w 并安装php常用扩展
yum -y install php72w php72w-cli php72w-common php72w-devel php72w-embedded php72w-fpm php72w-gd php72w-mbstring php72w-mysqlnd php72w-opcache php72w-pdo php72w-xml php72w-imap php72w-ldap php72w-odbc php72w-pear php72w-xmlrpc
// 开机启动Php-fpm
systemctl enable php-fpm.service
systemctl start php-fpm.service
// 查看开机启动列表
systemctl list-units --type=service
配置nginx
编辑文件 /etc/nginx/conf.d/default.conf,内容如下
location / {
root /usr/share/nginx/html;
index index.php index.html index.htm;
}
location ~ \.php$ {
root /usr/share/nginx/html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
// 检查nginx语法
nginx -t
// 平滑重启
nginx -s reload
0 条评论