linux yum 安裝 lnmp(linux+php+mysql)

來源:互聯網
上載者:User

標籤:blog   http   io   ar   os   使用   sp   for   java   

yum搭建lnmp環境(CentOS6)

1.關閉防火牆
[[email protected] ~]# chkconfig iptables off

2.關閉selinux
vi /etc/sysconfig/selinux 
//將SELINUX=enforcing修改為disabled然後重啟生效

3、配置CentOS 6.0 第三方yum源(CentOS預設的標準源裡沒有nginx軟體包)
[[email protected] ~]# yum install wget
//下載wget工具
[[email protected] ~]# wget http://www.atomicorp.com/installers/atomic
//下載atomic yum源
[[email protected] ~]# sh ./atomic
//安裝提示輸入時輸yes
[[email protected] ~]# yum check-update
//更新yum軟體包

4.安裝開發包和庫檔案
[[email protected] ~]# 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
[[email protected] ~]# yum remove httpd
[[email protected] ~]# yum remove mysql
[[email protected] ~]# yum remove php

6.安裝nginx
[[email protected] ~]# yum install nginx
[[email protected] ~]# service nginx start
[[email protected] ~]# chkconfig --levels 235 nginx on
//設2、3、5層級開機啟動

7.安裝mysql
[[email protected] ~]# yum install mysql mysql-server mysql-devel
[[email protected] ~]# service mysqld start
[[email protected] ~]# chkconfig --levels 235 mysqld on
[[email protected] ~]# mysqladmin -u root password "123456"
//為root使用者佈建密碼
[[email protected] ~]# service mysqld restart
//重啟mysql

8.安裝php
[[email protected] ~]# 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-tidy php-common php-devel php-fpm
//安裝php和所需組件使PHP支援MySQL、FastCGI模式
[[email protected] ~]# service php-fpm start
[[email protected] ~]# chkconfig --levels 235 php-fpm on

9.配置nginx支援php
[[email protected] ~]# mv /etc/nginx/nginx.conf /etc/nginx/nginx.confbak
//將設定檔改為備份檔案
[[email protected]tOS ~]# cp /etc/nginx/nginx.conf.default /etc/nginx/nginx.conf
//由於原設定檔要自己去寫因此可以使用預設的設定檔作為設定檔
//修改nginx設定檔,添加fastcgi支援
[[email protected] ~]# vi /etc/nginx/nginx.conf
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;
}
//將以上代碼注釋去掉,並修改成nginx預設路徑

10.配置php
//編輯檔案php.ini,在檔案末尾添加cgi.fix_pathinfo = 1
[[email protected] ~]# vi /etc/php.ini

11.重啟nginx php-fpm
[[email protected] ~]# service nginx restart
[[email protected] ~]# service php-fpm restart

12.建立info.php檔案
[[email protected] ~]# vi /usr/share/nginx/html/info.php
<?php
phpinfo();
?>

13.由於我的網段是  172的所有 瀏覽器中 敲入  172.16.10.12 查看php 是否配置成功

###########################

14.個人總結

nginx 的設定檔目錄  /etc/nginx/nginx.conf

                              /etc/nginx/conf.d/default.conf

php.ini 目錄

 

[[email protected] nginx]# whereis php.ini
php: /usr/bin/php /etc/php.ini /etc/php.d /usr/lib64/php /usr/include/php /usr/share/php /usr/share/man/man1/php.1.gz

驗證mysql  

[[email protected] nginx]# mysql -uroot -p
Enter password:          [斷行符號]

mysql> show databases;   走到這裡說明 mysql 已經安裝成功

#################

 

nginx.conf 中的配置

http {
  include 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/www/log/nginx/access.log main;

  sendfile on;
  #tcp_nopush on;

  #keepalive_timeout 0;
  keepalive_timeout 65;

  #gzip on;
  # Load config files from the /etc/nginx/conf.d directory
  include /etc/nginx/conf.d/*.conf;
  server {
    listen 80;
    server_name localhost;

    #charset koi8-r;

    #access_log logs/host.access.log main;

    location / {
      root /var/www/;
      index index.php index.html index.htm;
    }

    error_page 404 /404.html;
    location = /404.html {
      root /usr/share/nginx/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;
    } 
  }
}

 

在 conf.d 目錄下 建立 default.conf設定檔

vim default.conf

server {
listen 80;
server_name _;
root /var/www/;

location /{
index index.php index.html index.htm;
if (-e $request_filename) {
break;
}
if (!-e $request_filename) {
rewrite ^/(.*)$ /index.php/$1 last;
break;
}
}

location ~ .+\.php($|/) {
root /var/www/;
fastcgi_index index.php;
fastcgi_split_path_info ^(.+\.php)(.*)$;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info;
fastcgi_pass 127.0.0.1:9000;
include fastcgi_params;
}
}

 

 

linux yum 安裝 lnmp(linux+php+mysql)

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.