gaojinguan 发表于 2015-8-21 10:45:32

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

yum搭建lnmp环境(CentOS6)
  1.关闭防火墙
# chkconfig iptables off
  2.关闭selinux
vi /etc/sysconfig/selinux
//将SELINUX=enforcing修改为disabled然后重启生效
  3、配置CentOS 6.0 第三方yum源(CentOS默认的标准源里没有nginx软件包)
# yum install wget
//下载wget工具
# wget http://www.atomicorp.com/installers/atomic
//下载atomic yum源
# sh ./atomic
//安装提示输入时输yes
# yum check-update
//更新yum软件包
  4.安装开发包和库文件
# 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
# yum remove httpd
# yum remove mysql
# yum remove php
  6.安装nginx
# yum install nginx
# service nginx start
# chkconfig --levels 235 nginx on
//设2、3、5级别开机启动
  7.安装mysql
# yum install mysql mysql-server mysql-devel
# service mysqld start
# chkconfig --levels 235 mysqld on
# mysqladmin -u root password "123456"
//为root用户设置密码
# service mysqld restart
//重启mysql
  8.安装php
# 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模式
# service php-fpm start
# chkconfig --levels 235 php-fpm on
  9.配置nginx支持php
# mv /etc/nginx/nginx.conf /etc/nginx/nginx.confbak
//将配置文件改为备份文件
# cp /etc/nginx/nginx.conf.default /etc/nginx/nginx.conf
//由于原配置文件要自己去写因此可以使用默认的配置文件作为配置文件
//修改nginx配置文件,添加fastcgi支持
# 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
# vi /etc/php.ini
  11.重启nginx php-fpm
# service nginx restart
# service php-fpm restart
  12.建立info.php文件
# 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 目录
  
  # 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
  # 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;
}
}
  
  
页: [1]
查看完整版本: linux yum 安装 lnmp(linux+php+mysql)