zoukankan      html  css  js  c++  java
  • 在Ubuntu 12.4 下安装 nginx, MySQL, PHP

    LNMP是时下很流行的网站配置,我在配置蝉大师服务器的时候顺带把经验做个分享,蝉大师的网址是:http://www.ddashi.com/

    1、第一步, 跟新apt-get

    输入:

    sudo apt-get update

    2、第二步,安装Mysql

    输入:

    sudo apt-get install mysql-server php5-mysql

    安装过程中mysql会要求你给数据库设定密码,输入两次后继续……

    输入:

    sudo mysql_install_db

    继续输入:

    sudo /usr/bin/mysql_secure_installation

    会提示你输入刚刚设定的mysql密码,输入即可

    问你是否要更改密码,输入N即可

    接下来Mysql会提示几个问题,填入下边对应的y或n即可

    By default, a MySQL installation has an anonymous user, allowing anyone
    to log into MySQL without having to have a user account created for
    them.  This is intended only for testing, and to make the installation
    go a bit smoother.  You should remove them before moving into a
    production environment.
    
    Remove anonymous users? [Y/n] y                                            
     ... Success!
    
    Normally, root should only be allowed to connect from 'localhost'.  This
    ensures that someone cannot guess at the root password from the network.
    
    Disallow root login remotely? [Y/n] y
    ... Success!
    
    By default, MySQL comes with a database named 'test' that anyone can
    access.  This is also intended only for testing, and should be removed
    before moving into a production environment.
    
    Remove test database and access to it? [Y/n] y
     - Dropping test database...
     ... Success!
     - Removing privileges on test database...
     ... Success!
    
    Reloading the privilege tables will ensure that all changes made so far
    will take effect immediately.
    
    Reload privilege tables now? [Y/n] y
     ... Success!
    
    Cleaning up...

    3、第三步、安装Nginx

    依次输入:

    echo "deb http://ppa.launchpad.net/nginx/stable/ubuntu $(lsb_release -sc) main" | sudo tee /etc/apt/sources.list.d/nginx-stable.list
    sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys C300EE8C
    sudo apt-get update
    sudo apt-get install nginx

    启动nginx:

    sudo service nginx start

    这时候你可以访问你的域名或IP地址来看看Nginx是否工作了

    输入如下命令可以知道你的IP:

    ifconfig eth0 | grep inet | awk '{ print $2 }'

    4、第四步,安装PHP

    sudo apt-get install php5-fpm

    配置PHP:

    sudo nano /etc/php5/fpm/php.ini

    找到, cgi.fix_pathinfo=1, 把1改为0即可,如下:

    cgi.fix_pathinfo=0

    接着:

    sudo nano /etc/php5/fpm/pool.d/www.conf

    找到, listen = 127.0.0.1:9000, 把 127.0.0.1:9000 改成 /var/run/php5-fpm.sock.

    listen = /var/run/php5-fpm.sock

    保存退出,启动PHP

    sudo service php5-fpm restart

    配置Nginx

    sudo nano /etc/nginx/sites-available/default

    启用PHP,绑定目录和index文件

    [...]
    server {
            listen   80;
         
    
            root /var/www;
            index index.php index.html index.htm;
    
            server_name example.com;
    
            location / {
                    try_files $uri $uri/ /index.html;
            }
    
            error_page 404 /404.html;
    
            error_page 500 502 503 504 /50x.html;
            location = /50x.html {
                  root /usr/share/nginx/www;
            }
    
            # pass the PHP scripts to FastCGI server listening on the php-fpm socket
            location ~ .php$ {
                    try_files $uri =404;
                    fastcgi_pass unix:/var/run/php5-fpm.sock;
                    fastcgi_index index.php;
                    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
                    include fastcgi_params;
                    
            }
    
    }
    [...]

    可以了,建个文件试试吧:

    sudo nano /var/www/info.php

    如果觉得有价值,欢迎加我微信(keerol)或关注我微博(weibo/yanghongjin)

  • 相关阅读:
    Mybatis入门之常规操作CURD案例Demo(附源码)
    如何捕获Wince下form程序的全局异常
    如何捕获winform程序全局异常?(续)
    log4net学习目录
    如何捕获winform程序全局异常?
    有关学习的思考
    使用VS2012主题插件创建自己的主题
    Vistual Studio 2012更换皮肤
    log4net使用经验总结
    log4net使用流程
  • 原文地址:https://www.cnblogs.com/xxingmen/p/4337894.html
Copyright © 2011-2022 走看看