首頁  >  文章  >  後端開發  >  基於CentOS6.5的LNMP環境手工搭建

基於CentOS6.5的LNMP環境手工搭建

不言
不言原創
2018-05-04 15:28:061395瀏覽

这篇文章主要介绍了关于基于CentOS6.5的LNMP环境手工搭建,有着一定的参考价值,现在分享给大家,有需要的朋友可以参考一下

  Lnmp安装有两种方式,一是一键安装,由于安装过程中升级系统文件,在编译golang的时候出现问题,有待于进一步解决;二是分布安装,该过程安装后可以正常编译相关程序。
    1、查看环境:
[root@localhost ~]# cat /etc/redhat-release
CentOS release 6.5 (Final)
[root@localhost ~]# 
    2、关闭防火墙:
[root@localhost ~]# service iptables stop
iptables: Setting chains to policy ACCEPT: filter          [  OK  ]
iptables: Flushing firewall rules:                         [  OK  ]
iptables: Unloading modules:                               [  OK  ]
[root@localhost ~]# service iptables status
iptables: Firewall is not running.
[root@localhost ~]#  
    3、配置CentOS 6.0 第三方yum源(CentOS默认的标准源里没有nginx软件包)
[root@localhost src]# wget http://www.atomicorp.com/installers/atomic  
[root@localhost src]# sh ./atomic 
[root@localhost src]# yum check-update 
    4、安装开发包和库文件:    
[root@localhost src]# 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 
    5、卸载已安装的Apache、MySQL、PHP;(分别执行)
[root@localhost src]# yum remove httpd  
[root@localhost src]# yum remove mysql
[root@localhost src]# yum remove php
    6、安装Nginx;
[root@localhost src]# yum install nginx
[root@localhost src]# service nginx start
[root@localhost src]# chkconfig –levels 235 nginx on
//设2、3、5级别开机启动
    7、安装MySQL;
[root@localhost src]# yum install mysql mysql-server mysql-devel
[root@localhost src]# service mysqld start
[root@localhost src]# chkconfig --levels 235 mysqld on
    登录MySQL,删除空用户及修改用户密码;
[root@localhost src]# mysql -uroot -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.5.55 MySQL Community Server (GPL) by Atomicorp
Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> use mysql 
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed 
//查看mysql用户信息;
mysql>select user,host,password from mysql.user;
//删除空用户;
mysql> drop user ''@localhost;
Query OK, 0 rows affected (0.00 sec) 
mysql> delete from user where user = '';
Query OK, 1 row affected (0.00 sec) 
//更新用户密码;
mysql> update mysql.user set password = password('root') where user='root';
Query OK, 4 rows affected (0.00 sec)
Rows matched: 4  Changed: 4  Warnings: 0
//授权:允许root用户用root密码登录,*.*表示哪个库的哪个表;%从哪个IP地址访问;
mysql>  grant all privileges on *.* to root@'%' identified by 'root' with grant option;
Query OK, 0 rows affected (0.00 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
//更新数据库生效;
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
//退出
 mysql> exit;Bye
    8、安装PHP;
 [root@localhost src]# yum install php lighttpd-fastcgi 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 src]# yum install  php-tidy php-common php-devel php-fpm php-mysql 
    //启动PHP服务和设置开机启动;
[root@localhost src]# service php-fpm start
Starting php-fpm: No log handling enabled - turning on stderr logging
Created directory: /var/lib/net-snmp/mib_indexes
                                                           [  OK  ]
[root@localhost src]# chkconfig --levels 235 php-fpm on
[root@localhost src]# 
    9、配置Nginx,支持PHP;
[root@localhost wwwroot]# cd /etc/nginx/conf.d/
[root@localhost conf.d]# vi default.conf 
//配置文件如下:
server {
    listen       80;
    server_name localhost;
    location / {
        root   /home/wwwroot;
        index  index.html index.htm index.php;
        if (!-e $request_filename){
            rewrite ^(.*)$ /index.php?s=$1 last;
        }
    }
    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   /usr/share/nginx/html;
    }
    location ~ \.php$ {
        root           /home/wwwroot;
        fastcgi_pass   127.0.0.1:9000;
        fastcgi_index  index.php;
        include        fastcgi_params;
        fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
        set $path_info "";
        set $fastcgi_script_name_new $fastcgi_script_name;
        if ($fastcgi_script_name ~*   "^(.+\.php)(/.+)$"  ) {
                set $fastcgi_script_name_new $1;
                set $path_info $2;
         }
        fastcgi_param   SCRIPT_FILENAME   $document_root$fastcgi_script_name_new;
        fastcgi_param   SCRIPT_NAME   $fastcgi_script_name_new;
        fastcgi_param   PATH_INFO $path_info;
    }
}
    10、重启Nginx和php-fpm;
[root@localhost conf.d]# service nginx restart
Stopping nginx:                                            [  OK  ]
Starting nginx:                                            [  OK  ]
[root@localhost conf.d]# service php-fpm restart
Stopping php-fpm:                                          [  OK  ]
Starting php-fpm:                                          [  OK  ]
[root@localhost conf.d]#  
    11、测试,在Nginx解析的目录下创建info.php文件,并在浏览器访问http://localhost/info.php,查看是否显示PHP页面;
//info.php文件内容如下:

相关推荐:

基于CentOS 6.5操作系统搭建MongoDB服务


以上是基於CentOS6.5的LNMP環境手工搭建的詳細內容。更多資訊請關注PHP中文網其他相關文章!

陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn