centos6.8 yum安装lnmp

一、配置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 ~]# service nginx start
[root@localhost ~]# chkconfig --levels 235 nginx on  #设置2、3、5级别开机启动

输入命令 nginx -t,这是一个判断nginx配置文件格式是否正确的命令,可以用来查找nginx配置文件的路径;

[root@Server-55e30ab1-b924-43b7-94e4-4a7c59208282 html]# nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful

但是这里出现的配置文件是主配置文件,注意配置文件是否有扩展

[root@Server-55e30ab1-b924-43b7-94e4-4a7c59208282 html]# cat /etc/nginx/nginx.conf

user  nginx;
worker_processes  1;

error_log  /var/log/nginx/error.log warn;
pid        /var/run/nginx.pid;


events {
    worker_connections  1024;
}


http {
    include       /etc/nginx/mime.types;
    default_type  application/octet-stream;

    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';

    access_log  /var/log/nginx/access.log  main;

    sendfile        on;
    #tcp_nopush     on;

    keepalive_timeout  65;

    #gzip  on;

    include /etc/nginx/conf.d/*.conf;###这里就出现了扩展,其他参数去扩展配置文件配置!!
}

五、安装mysql

[root@localhost ~]# yum install mysql mysql-server mysql-devel -y
[root@localhost ~]# service mysqld start
[root@localhost ~]#  chkconfig --levels 235 mysqld on

#为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:

[root@localhost ~]#/etc/init.d/mysqld start  #启动
[root@localhost ~]# /etc/init.d/mysqld status

六、安装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 ~]# service php-fpm start
Starting php-fpm:                                          [  OK  ]
[root@localhost ~]# chkconfig --levels 235 php-fpm on

七、配置nginx支持php

[root@localhost nginx]# cp /etc/nginx/conf.d/default.conf{,.bak}

修改配置文件

[root@Server- ~]# cat /etc/nginx/conf.d/default.conf 
server {
    listen       80;
    server_name  localhost;

    #charset koi8-r;
    #access_log  /var/log/nginx/host.access.log  main;

    location / {
        root   /usr/share/nginx/html;
        index  index.php index.html index.htm;
    }

    #error_page  404              /404.html;

    # redirect server error pages to the static page /50x.html
    #
    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   /usr/share/nginx/html;
    }

    # proxy the PHP scripts to Apache listening on 127.0.0.1:80
    #
    #location ~ \.php$ {
    #    proxy_pass   http://127.0.0.1;
    #}

    # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000

    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;
        #fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
        include        fastcgi_params;
    }

    # deny access to .htaccess files, if Apache's document root
    # concurs with nginx's one
    #
    #location ~ /\.ht {
    #    deny  all;
    #}
}

八、配置php

vim /etc/php-fpm.d/www.conf 
user = nginx
group = nginx

九、重启nginx php-fpm

[root@localhost nginx]# service nginx restart
Stopping nginx:                                            [  OK  ]
Starting nginx:                                            [  OK  ]
[root@localhost nginx]# service php-fpm restart
Stopping php-fpm:                                          [  OK  ]
Starting php-fpm:  

十、测试

[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  #设置目录所有者

在客户端浏览器输入服务器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
nginx 配置文件 :/etc/nginx/conf.d/default.conf 
php-fpm 配置文件 :/etc/php-fpm.d/www.conf 

猜你喜欢

转载自blog.csdn.net/weixin_40283570/article/details/80593632