1、Centos6系统库中默认是没有nginx的rpn包的,所以我们需要先更新下rpm依赖库
(1):使用yum安装nginx,安装nginx库
rpm -Uvh http://nginx.org/packages/centos/6/noarch/RPMS/nginx-release-centos-6-0.el6.ngx.noarch.rpm
(2):使用下面命令安装nginx
yum -y install nginx
(3):启动nginx
service nginx start #centos6
或
systemctl start nginx.service #centos7
(4):防火墙允许通过80端口
vim /etc/sysconfig/iptables # Generated by iptables-save v1.4.7 on Thu Dec 28 19:47:19 2017 *filter :INPUT ACCEPT [0:0] :FORWARD ACCEPT [0:0] :OUTPUT ACCEPT [21691:949300] -A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT -A INPUT -p icmp -j ACCEPT -A INPUT -i lo -j ACCEPT -A INPUT -p tcp -m state --state NEW -m tcp --dport 22 -j ACCEPT -A INPUT -p tcp -m state --state NEW -m tcp --dport 80 -j ACCEPT -A INPUT -j REJECT --reject-with icmp-host-prohibited -A FORWARD -j REJECT --reject-with icmp-host-prohibited COMMIT
(5):重启防火墙
service iptables restart
(6):访问网站,查看是否出现 'Welcome To Nginx',如果想更改网站根目录,修改地址:vim /etc/nginx/conf.d/default.conf,修改Root 后面的路径,详细请参考:Liscookie
2、安装Mysql,先更新yum源
(1):yum源下载地址,根据自己需要的版本选择相应的源
https://dev.mysql.com/downloads/repo/yum/
(2):我们版本是6.x的,所以选择linux 6 下载
wget https://repo.mysql.com//mysql57-community-release-el6-11.noarch.rpm
(3):安装mysql的yum源
rpm -Uvh mysql57-community-release-el6-11.noarch.rpm
或
yum -y localinstall mysql57-community-release-el6-11.noarch.rpm
(4):查看是否配置mysql源成功
在/etc/yum.repos.d下面
(5):安装Mysql
yum -y install mysql-community-server #时间有点长,稍微等一下
(6):开始mysql服务
service mysqld start
(7):Mysql安装成功之后,会自动创建root的密码,存储在/var/log/mysqld.log,可以通过以下命令来查看
grep 'temporary password' /var/log/mysqld.log
(8):登录mysql,修改密码
mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'Wang123!';
(9):开启远程链接,iptables开放3306端口
vim /etc/sysconfig/iptables
(10):重启防火墙使iptables生效
service iptables restart
3、安装PHP
(1):更新yum源
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
(2):安装PHP
yum -y install --enablerepo=remi --enablerepo=remi-php56 php php-bcmath php-opcache php-devel php-mbstring php-mcrypt php-mysqlnd php-gd php-xml php-memcache php-redis php-fpm php-mysql php-common php-mssql
(3):配置php.ini文件,关闭php信息头
vim /etc/php.ini #366行左右 expose_php = Off #关闭phpxinxi
(4):启动PHP,设置开机启动
service php-fpm restart #启动php chkconfig php-fpm --level 2345 on #设置开机启动
OK,至此,已经安装完成了LNMP