此处的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.repowget -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 repobaseurl=http://nginx.org/packages/centos/$releasever/$basearch/gpgcheck=0enabled=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.rpmrpm -Uvh http://rpms.famillecollet.com/enterprise/remi-release-6.rpm// CentOS 7.0的源。yum install epel-release -yrpm -ivh http://rpms.famillecollet.com/enterprise/remi-release-7.rpm
- 3 安装nginx
yum install -y nginx// 启动nginx
安装mysql
- 1 安装数据库
// 查看系统版本cat /etc/redhat-releaseCentOS 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.servicesystemctl 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 #停止firewallsystemctl disable firewalld.service #禁止firewall开机启动
安装php
// 可选卸载原PHP版本yum -y remove php*// 更新rpmrpm -Uvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpmrpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm// 可选,查看可安装版本列表,可以发现从4-7.2的版本都有,7.2版本名为72wyum 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-fpmsystemctl enable php-fpm.servicesystemctl 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 条评论