一、配置CentOS 第三方yum源(CentOS默认的标准源里没有nginx软件包)

[root@localhost ~]# yum install wget  #安装下载工具wget
[root@localhost ~]#wget http://www.atomicorp.com/installers/atomic #下载atomic yum源
[root@localhost ~]#sh ./atomic #安装
[root@localhost ~]# yum check-update #更新yum软件包

二、安装开发包和库文件

[root@localhost ~]# yum -y install ntp make openssl openssl-devel pcre pcre-devel libpng libpng-devel libjpeg-6b libjpeg-devel-6b freetype freetype-devel gd gd-devel zlib zlib-devel gcc gcc-c++ libXpm libXpm-devel ncurses ncurses-devel libmcrypt libmcrypt-devel libxml2 libxml2-devel imake autoconf automake screen sysstat compat-libstdc++-33 curl curl-devel

三、卸载已安装的apache、mysql、php

[root@localhost ~]# yum remove httpd
[root@localhost ~]# yum remove mysql
[root@localhost ~]# yum remove php

四、安装nginx

[root@localhost ~]# yum install nginx -y
[root@localhost ~]# systemctl start nginx.service
[root@localhost ~]# systemctl status nginx.service
[root@localhost ~]# systemctl enable nginx.service
Created symlink from /etc/systemd/system/multi-user.target.wants/nginx.service to /usr/lib/systemd/system/nginx.service.
[root@localhost ~]#

五、安装mariadb

[root@localhost ~]# yum install mariadb-devel mariadb mariadb-server
[root@localhost ~]# systemctl start mariadb.service
[root@localhost ~]# systemctl status mariadb.service
● mariadb.service - MariaDB database server
   Loaded: loaded (/usr/lib/systemd/system/mariadb.service; disabled; vendor preset: disabled)
   Active: active (running) since Sat 2017-12-23 10:37:58 HKT; 4s ago
  Process: 18474 ExecStartPost=/usr/libexec/mariadb-wait-ready $MAINPID (code=exited, status=0/SUCCESS)
  Process: 18395 ExecStartPre=/usr/libexec/mariadb-prepare-db-dir %n (code=exited, status=0/SUCCESS)
 Main PID: 18473 (mysqld_safe)
   CGroup: /system.slice/mariadb.service
           ├─18473 /bin/sh /usr/bin/mysqld_safe --basedir=/usr
           └─18635 /usr/libexec/mysqld --basedir=/usr --datadir=/var/lib/mysql --plugin-dir=/usr/lib64/mysql/plugin --log-error=/var/log/... Dec 23 10:37:56 localhost.localdomain mariadb-prepare-db-dir[18395]: MySQL manual for more instructions.
Dec 23 10:37:56 localhost.localdomain mariadb-prepare-db-dir[18395]: Please report any problems at http://mariadb.org/jira
Dec 23 10:37:56 localhost.localdomain mariadb-prepare-db-dir[18395]: The latest information about MariaDB is available at http://mar...org/.
Dec 23 10:37:56 localhost.localdomain mariadb-prepare-db-dir[18395]: You can find additional information about the MySQL part at:
Dec 23 10:37:56 localhost.localdomain mariadb-prepare-db-dir[18395]: http://dev.mysql.com
Dec 23 10:37:56 localhost.localdomain mariadb-prepare-db-dir[18395]: Consider joining MariaDB's strong and vibrant community:
Dec 23 10:37:56 localhost.localdomain mariadb-prepare-db-dir[18395]: https://mariadb.org/get-involved/
Dec 23 10:37:56 localhost.localdomain mysqld_safe[18473]: 171223 10:37:56 mysqld_safe Logging to '/var/log/mariadb/mariadb.log'.
Dec 23 10:37:56 localhost.localdomain mysqld_safe[18473]: 171223 10:37:56 mysqld_safe Starting mysqld daemon with databases from /v.../mysql
Dec 23 10:37:58 localhost.localdomain systemd[1]: Started MariaDB database server.
Hint: Some lines were ellipsized, use -l to show in full.
[root@localhost ~]# systemctl enable mariadb.service
Created symlink from /etc/systemd/system/multi-user.target.wants/mariadb.service to /usr/lib/systemd/system/mariadb.service
#为root账户设置密码
[root@localhost ~]#mysql_secure_installation  #初始化MySQL
Enter current password for root (enter for none):   <---输入现在的root密码,因为我们还没设置,直接回车
Set root password? [Y/n] Y                                    <---是否设定root密码,当然设置了,输入Y回车
New password:                                                      <---输入root密码,并回车,输入的过程中不会有任何显示
Re-enter new password:                                        <---再次输入root密码,并回车,输入的过程中不会有任何显示
Remove anonymous users? [Y/n] Y                      <---是否删除匿名用户,删除,输入Y回车
Disallow root login remotely? [Y/n] Y                     <---是否删禁止root用户远程登录,当然禁止,输入Y回车
Remove test database and access to it? [Y/n]      <---是否删除测试数据库test,看个人喜好
Reload privilege tables now? [Y/n] Y                    <---刷新权限,输入Y回车
最后出现:Thanks for using MySQL!
MySql密码设置完成,重新启动 MySQL:

六、安装php

[root@localhost ~]# yum -y install php php-cli php-mysql php-gd php-imap php-ldap php-odbc php-pear php-xml php-xmlrpc php-mbstring php-mcrypt php-mssql php-snmp php-soap 

安装php和所需组件使PHP支持MySQL、FastCGI模式

[root@localhost ~]# yum install  php-tidy php-common php-devel php-fpm php-mysql -y
[root@localhost ~]# systemctl start php-fpm.service
[root@localhost ~]# systemctl status php-fpm.service
● php-fpm.service - The PHP FastCGI Process Manager
   Loaded: loaded (/usr/lib/systemd/system/php-fpm.service; disabled; vendor preset: disabled)
   Active: active (running) since Sat 2017-12-23 10:53:59 HKT; 4s ago
 Main PID: 18953 (php-fpm)
   Status: "Ready to handle connections"
   CGroup: /system.slice/php-fpm.service
           ├─18953 php-fpm: master process (/etc/php-fpm.conf)
           ├─18955 php-fpm: pool www
           ├─18956 php-fpm: pool www
           ├─18957 php-fpm: pool www
           ├─18958 php-fpm: pool www
           └─18959 php-fpm: pool www Dec 23 10:53:59 localhost.localdomain systemd[1]: Starting The PHP FastCGI Process Manager...
Dec 23 10:53:59 localhost.localdomain systemd[1]: Started The PHP FastCGI Process Manager.
[root@localhost ~]#
[root@localhost ~]# systemctl enable php-fpm.service
Created symlink from /etc/systemd/system/multi-user.target.wants/php-fpm.service to /usr/lib/systemd/system/php-fpm.service.
[root@localhost ~]#

七、配置nginx支持php

[root@localhost ~]# cp /etc/nginx/nginx.conf{,.bak} #将配置文件改为备份文件

#修改nginx配置文件,添加fastcgi支持
[root@localhost ~]# vim /etc/nginx/nginx.conf
vim /etc/nginx/nginx.conf  #编辑
user  nginx  nginx;  #修改nginx运行账号为:nginx组的nginx用户
:wq!    #保存退出 [root@localhost nginx]# vim /etc/nginx/conf.d/default.conf     location / {
        root   /usr/share/nginx/html;
        index  index.php index.html index.htm;   #增加index.php
    }
      location ~ \.php$ {
        root           /usr/share/nginx/html;
        fastcgi_pass   127.0.0.1:9000;
        fastcgi_index  index.php;
        fastcgi_param  SCRIPT_FILENAME  /usr/share/nginx/html$fastcgi_script_name;
        include        fastcgi_params;
    }

八、配置php

[root@localhost nginx]# cp /etc/php.ini{,.bak}
[root@localhost nginx]#vim /etc/php.ini
expose_php = Off #禁止显示php版本的信息

九、重启nginx php-fpm

[root@localhost ~]# systemctl restart nginx.service
[root@localhost ~]# systemctl restart php-fpm.service

十、测试

[root@localhost ~]# cd /usr/share/nginx/html/
[root@localhost html]# vim index.php
<?php
phpinfo();
?>
[root@localhost html]# chown nginx.nginx /usr/share/nginx/html/ -R #设置目录所有者
#配置防火墙,开启80端口、3306端口
[root@localhost html]# firewall-cmd --zone=public --add-port=/tcp --permanent
success
[root@localhost html]# firewall-cmd --zone=public --add-port=/tcp --permanent
success
[root@localhost html]# systemctl restart firewalld.service
[root@localhost html]# systemctl enable firewalld.service

在客户端浏览器输入服务器IP地址,可以看到相关的配置信息!


#############################################################################
 
备注

nginx默认站点目录是:/usr/share/nginx/html/
权限设置:chown nginx.nginx/usr/share/nginx/html/ -R
MySQL数据库目录是:/var/lib/mysql
权限设置:chown mysql.mysql -R /var/lib/mysql

参考:

https://www.cnblogs.com/xiaoit/p/3991037.html

http://www.kuitao8.com/20150305/3571.shtml

centos7安装lnmp的更多相关文章

  1. 腾讯云CentOS7安装LNMP+wordpress

    许多云主机都有学生优惠,于是我趁着现在大一买了个腾讯1元云主机+免费cn域名(高中生的话就别想了).鉴于我只知道用服务器安装博客,别的用途不了解,所以我就去安装wordpress. 而由于我看的教程有 ...

  2. centos7安装Lnmp(Linux+Nginx+MySql+Php+phpMyAdmin+Apache)

    centos7安装Lnmp(Linux+Nginx+MySql+Php)及Apache   Nginx是俄罗斯人编写的十分轻量级的HTTP服务器,Nginx是一个高性能的HTTP和反向代理服务器,Ng ...

  3. Centos7 安装lnmp

    Centos7 安装lnmp 1.下载 wget http://soft.vpser.net/lnmp/lnmp1.5-full.tar.gz 2.解压 tar -zvxf lnmp1.5-full. ...

  4. centos7安装LNMP与Laravel遇到的一些小问题

    安装LNMP 第一次安装 yum update CentOS7下 Nginx1.13.5 + PHP7.1.10 + MySQL5.7.19 源码编译安装 安装mySQL时,mysqld: error ...

  5. CentOS7 安装LNMP(Linux+Nginx+MySQL+PHP)

    由于工作须要,须要学习php,本来想安装lamp的可是考虑到如今nginxserver有良好的性能且应用广泛. 这里我决定搭建Linux(CentOS7+Nginx+MySQL+PHP)下的webse ...

  6. Centos7安装lnmp环境

    系统版本:centos7 64位 PHP版本:PHP 7.0.21 Nginx版本:1.8.1 MySQL版本:5.5.17 注:1.所有安装都必须放在 /usr/local/src文件夹下 2.添加 ...

  7. centos7 安装lnmp环境

    准备工作 一.配置防火墙 vim /etc/sysconfig/iptables 开启80端口.3306.22端口 -A INPUT -m state --state NEW -m tcp -p tc ...

  8. CentOS 7 安装phpredis和redis(接上一篇centos7安装lnmp)

    一.安装扩展phpredis 1.PHP7 安装redis 扩展phpredis cd /root/software wget https://github.com/edtechd/phpredis/ ...

  9. centos7 安装LNMP(php7)之php7.0 yum安装

    http://www.jianshu.com/p/35f21210668a 安装过程参考上面的网址

  10. centos7 安装LNMP(php7)之mysql安装,更改密码,远程授权

    1.执行命令 yum install mysql mysql-server mysql-devel -y 知道出现complete!则安装mysql完成 当执行 service mysqld rest ...

随机推荐

  1. 机器学习之路--KNN算法

    机器学习实战之kNN算法   机器学习实战这本书是基于python的,如果我们想要完成python开发,那么python的开发环境必不可少: (1)python3.52,64位,这是我用的python ...

  2. HDU3709 Balanced Number 题解 数位DP

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3709 题目大意: 求区间 \([x, y]\) 范围内"平衡数"的数量. 所谓平衡 ...

  3. 使用Theia——创建插件

    上一篇:使用Theia——创建扩展包 创建Theia插件 下面我们来看看如何创建Theia插件.作为示例,我们将注册一个Hello World命令,该命令显示一个“Hello World”通知.本文将 ...

  4. es6种for循环中let和var区别

    let和var区别: for(var i=0;i<5;i++){ setTimeout(()=>{ console.log(i);//5个5 },100) } console.log(i) ...

  5. CCPC-Wannafly Winter Camp Day1 (Div2 ABCFJ) 待补...

    Day1 Div2 场外链接 按题目顺序~ A 机器人 传送门 题意:有两条平行直线A.B,每条直线上有n个点,编号为1~n.在同一直线上,从a站点到b站点耗时为两点间的距离.存在m个特殊站点,只有在 ...

  6. JetBrains Pycharm破解,含破解文件和安装包2019.2版

    此教程支持最新的2019.3版本的Pycharm,并兼容之前的版本. 一.准备工作: 1.下载Pycharm 有条件的可以自行去官网下载,这里我提供了我下载的版本,已上传到百度网盘,链接在下方. 2. ...

  7. 原生javascript实现仿QQ延时菜单

    一.实现原理 定时器和排他思想 二.代码 <!DOCTYPE html> <html> <head> <title></title> < ...

  8. python 矩阵向右旋转90°(分行输入输出)

    输入格式 第一行输入两个整数n,m,用空格隔开. 接下来n行,每行输入m个整数,表示输入矩阵.矩阵元素都是int范围内的整数. 输出格式 输出m行,每行n个空格隔开的整数,表示旋转以后的矩阵.注意:每 ...

  9. python实现浏览器打开指定url

    关键 webbrowser+time+os     import os,timeimport webbrowser url = 'http://www.baidu.com' webbrowser.op ...

  10. P1640 [SCOI2010]连续攻击游戏 二分图最大匹配 匈牙利算法

    题目描述 lxhgww最近迷上了一款游戏,在游戏里,他拥有很多的装备,每种装备都有2个属性,这些属性的值用[1,10000]之间的数表示.当他使用某种装备时,他只能使用该装备的某一个属性.并且每种装备 ...