LNMP(yum和源码)

CentOS 6.5

###########################yum安装LNMP################################################

1、修改yum源

mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup

wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-6.repo

yum clean all

yum makecache

新建 /etc/yum.repos.d/nginx.repo
加入:

 [nginx] 

name=nginx repo
baseurl=http://nginx.org/packages/centos/$releasever/$basearch/   
gpgcheck=0   
enabled=1

2、安装包

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 nginx  mysql mysql-server mysql-devel 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


3、开机启动

service nginx start

service mysqld start

service php-fpm start

chkconfig nginx on

chkconfig mysqld on

chkconfig php-fpm on


4、配置nignx和php关联

修改 /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           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;
    }
    # deny access to .htaccess files, if Apache's document root
    # concurs with nginx's one
    #
    #location ~ /\.ht {
    #    deny  all;
    #}
}


5、配置php

编辑/etc/php.ini  

加入cgi.fix_pathinfo = 1


6、重启服务

service nginx restart

service php-fpm restart


7、修改iptables规则
编辑/etc/sysconfig/iptables
加入-A INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT
重启iptables    service iptables restart


8、为mysql设置密码:
进入mysql
use mysql;
update user set password=password('123') where user='root';
flush privileges;


9、测试

编辑测试页面:/usr/share/nginx/html/test.php

<?php
        $link=mysql_connect('localhost','root','123');
        if(!$link) echo "fail";
        else echo "success";
        mysql_close();
        phpinfo();
?>

http://192.168.0.111/test.php
第一排显示成功说明正常连接到mysql


###########################源码安装LNMP################################################

源码包:

nginx-1.13.3.tar.gz   http://download.csdn.net/download/yang_xu_1987/9961038

MySQL-5.5.24.tar.gz      http://download.csdn.net/download/yang_xu_1987/9960273
cmake-2.8.9.tar.gz   http://download.csdn.Net/download/yang_xu_1987/9960268
php-5.3.22.tar.gz   http://download.csdn.net/download/yang_xu_1987/9960265


1、下载源码包并安装
  1)安装mysql:http://blog.csdn.net/yang_xu_1987/article/details/77648225

  2)安装nginx:http://blog.csdn.net/yang_xu_1987/article/details/76422664

开机启动:   echo "/usr/local/nginx/sbin/nginx" >> /etc/rc.d/rc.local

  3)安装php:

  tar -zxvf php-5.3.22.tar.gz 

cd php-5.3.22

./configure --prefix=/usr/local/php --with-mysql=/usr/local/mysql/ --enable-fpm --enable-sockets

make && make install

echo "/usr/local/php/sbin/php-fpm">> /etc/rc.d/rc.local


2、修改配置文件

cp php.ini-production /usr/local/php/php.ini #复制配置文件
cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf
ln -s /usr/local/php/bin/php /usr/bin/

#启动php-fpm
mkdir /var/run/php-fpm
/usr/local/php/sbin/php-fpm
#然后配置nginx,编辑nginx配置文件
vi /usr/local/nginx/conf/nginx.conf

#user  nobody;
worker_processes  1;
#error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;
#pid        logs/nginx.pid;
events {
    worker_connections  1024;
}
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  logs/access.log  main;
    sendfile        on;
    #tcp_nopush     on;
    #keepalive_timeout  0;
    keepalive_timeout  65;
    #gzip  on;
    server {
        listen       80;
        server_name  localhost;
        #charset koi8-r;
        #access_log  logs/host.access.log  main;
        location / {
            root   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   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           html;
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.php;
            fastcgi_param  SCRIPT_FILENAME  /usr/local/nginx/html$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;
        #}
    }
    # another virtual host using mix of IP-, name-, and port-based configuration
    #
    #server {
    #    listen       8000;
    #    listen       somename:8080;
    #    server_name  somename  alias  another.alias;
    #    location / {
    #        root   html;
    #        index  index.html index.htm;
    #    }
    #}
    # HTTPS server
    #
    #server {
    #    listen       443 ssl;
    #    server_name  localhost;
    #    ssl_certificate      cert.pem;
    #    ssl_certificate_key  cert.key;
    #    ssl_session_cache    shared:SSL:1m;
    #    ssl_session_timeout  5m;
    #    ssl_ciphers  HIGH:!aNULL:!MD5;
    #    ssl_prefer_server_ciphers  on;
    #    location / {
    #        root   html;
    #        index  index.html index.htm;
    #    }
    #}
}


3、修改iptables规则
编辑/etc/sysconfig/iptables
加入-A INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT
重启iptables    service iptables restart


4、测试
编辑测试页面:/usr/local/nginx/html/test.php
其余同上


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值