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

來源:互聯網
上載者:User
這篇文章主要介紹了關於基於CentOS6.5的LNMP環境手工搭建,有著一定的參考價值,現在分享給大家,有需要的朋友可以參考一下

  Lnmp安裝有兩種方式,一是一鍵安裝,由於安裝過程中升級系統檔案,在編譯golang的時候出現問題,有待於進一步解決;二是分布安裝,該過程安裝後可以正常編譯相關程式。    1、查看環境:[root@localhost ~]# cat /etc/redhat-releaseCentOS release 6.5 (Final)[root@localhost ~]#     2、關閉防火牆:[root@localhost ~]# service iptables stopiptables: Setting chains to policy ACCEPT: filter          [  OK  ]iptables: Flushing firewall rules:                         [  OK  ]iptables: Unloading modules:                               [  OK  ][root@localhost ~]# service iptables statusiptables: 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 -pEnter password:Welcome to the MySQL monitor.  Commands end with ; or \g.Your MySQL connection id is 2Server version: 5.5.55 MySQL Community Server (GPL) by AtomicorpCopyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved.Oracle is a registered trademark of Oracle Corporation and/or itsaffiliates. Other names may be trademarks of their respectiveowners.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 namesYou can turn off this feature to get a quicker startup with -ADatabase 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 startStarting php-fpm: No log handling enabled - turning on stderr loggingCreated 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 restartStopping nginx:                                            [  OK  ]Starting nginx:                                            [  OK  ][root@localhost conf.d]# service php-fpm restartStopping php-fpm:                                          [  OK  ]Starting php-fpm:                                          [  OK  ][root@localhost conf.d]#      11、測試,在Nginx解析的目錄下建立info.php檔案,並在瀏覽器訪問http://localhost/info.php,查看是否顯示PHP頁面;//info.php檔案內容如下:<?php    phpinfo();?>

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.