zoukankan      html  css  js  c++  java
  • ubuntu12.04 apt-get安装 lnmp环境(转)

    1.安装mysql

         

    1. sudo apt-get install mysql-server mysql-client  

    安装过程中要输入root用户的密码。

    我在安装中出错,是原来的mysql-cilent mysql-workbench 未完全卸载,将mysql组件完全卸载的方法:

     

    删除mysql前 先删除一下 /var/lib/mysql 还有 /etc/mysql

    1. sudo rm /var/lib/mysql/ -R  
    2. sudo rm /etc/mysql/ -R  
    3.   
    4. sudo apt-get autoremove mysql* --purge  
    5. sudo apt-get remove apparmor  


    全部删除之后再执行  apt-get install mysql-server mysql -client 

    2.安装nginx

     

    1. sudo apt-get install nginx  

     

    3.安装成功后。我们重启下nginx服务

     

    1. sudo service nginx restart<span style="font-size: 16px; font-family: 'Microsoft Yahei', Arial, Helvetica, sans-serif;"> </span>  

    启动之后我们就可以访问以下我们的地址了。看能不能出现nginx的欢迎界面。

    4.这里我们使用php5-fpm来作为我们的php解析。

     

    1. sudo apt-get install php5-fpm   


    5.接下来我们要修改一下nginx的站点配置了。

    ngnix的配置文件存放在/etc/nginx/sites-availble/default

    1. server {   
    2.   
    3.         listen   80; ## listen for ipv4; this line is default and implied   
    4.   
    5.         listen   [::]:80 default ipv6only=on; ## listen for ipv6   
    6.   
    7.         root /usr/share/nginx/www;   
    8.   
    9.         index index.php index.html index.htm;   
    10.   
    11.         # Make site accessible from http://localhost/   
    12.   
    13.         server_name _;   
    14.   
    15.         location / {   
    16.   
    17.                 # First attempt to serve request as file, then   
    18.   
    19.                 # as directory, then fall back to index.html   
    20.   
    21.                 try_files $uri $uri/ /index.html;   
    22.   
    23.         }   
    24.   
    25.         location /doc {   
    26.   
    27.                 root /usr/share;   
    28.   
    29.                 autoindex on;   
    30.   
    31.                 allow 127.0.0.1;   
    32.   
    33.                 deny all;   
    34.   
    35.         }   
    36.   
    37.         #error_page 404 /404.html;   
    38.   
    39.         # redirect server error pages to the static page /50x.html   
    40.   
    41.         #   
    42.   
    43.         error_page 500 502 503 504 /50x.html;   
    44.   
    45.         location = /50x.html {   
    46.   
    47.                 root /usr/share/nginx/www;   
    48.   
    49.         }   
    50.   
    51.         # proxy the PHP scripts to Apache listening on 127.0.0.1:80   
    52.   
    53.         #   
    54.   
    55.         #location ~ .php$ {   
    56.   
    57.         #       proxy_pass http://127.0.0.1;   
    58.   
    59.         #}   
    60.   
    61.         # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000   
    62.   
    63.         #   
    64.   
    65.         location ~ .php$ {   
    66.   
    67.                 try_files $uri =404;   
    68.   
    69.                 # With php5-cgi alone:  
    70.                 # fastcgi_pass 127.0.0.1:9000;  
    71.                 # With php5-fpm:  
    72.                 # fastcgi_pass unix:/var/run/php5-fpm.sock;   
    73.   
    74.                 fastcgi_index index.php;   
    75.   
    76.                 include fastcgi_params;   
    77.   
    78.         }   
    79.   
    80.         # deny access to .htaccess files, if Apache's document root   
    81.   
    82.         # concurs with nginx's one   
    83.   
    84.         #   
    85.   
    86.         location ~ /.ht {   
    87.   
    88.                 deny all;   
    89.   
    90.         }   
    91.   
    92. }   


    6.我们在安装php5相关的一些组件。

     

    1. sudo apt-cache search php5   
    2. apt-get install php5-mysql php5-curl php5-gd php5-intl php-pear php5-imagick php5-imap php5-mcrypt php5-memcache php5-ming php5-ps php5-pspell php5-recode php5-snmp php5-sqlite php5-tidy php5-xmlrpc php5-xsl   

    7.重启服务

     

    1. sudo service php5-fpm restart   
    2. sudo service nginx restart  


    经测试,现在应该已经安装成功了。


    PHP扩展的安装方式通常分为两种:
    1. 随同PHP编译
    2. 生成单独的.so文件
    这里介绍第二种方式,对于第二种方式执行效率可能低些,但是模块化,就是可以保持php安装不变的情况下,通过php.ini连接单独生成的so文件实现扩展,
    比如您已经通过了tar包方式安装了php,那么现在想增加扩展:

    安装CURL扩展
    I. 生成动态链接库文件.SO
    方法如下:
    方法1. apt-get install php5-curl
    方法2. 去PHP网站下载tar包,phpize本地编译生成.so
    方法3. pear方式安装,通过pecl命令去在线下载编译生成.so


    方法1在ubuntu下是最简单的,命令执行完会告知.so所在目录

    II. 配置php.ini
    打开php.ini,指定extension_dir目录,如果extension_dir = '/usr/lib',那么接下来把生成的.so文件(如curl.so)复制到/usr/lib目录下,并且加入一个新条目:
    extension=curl.so

    III. 使之生效
    重新启动apache,运行phpinfo()看是否生效

    安装PDO_MYSQL扩展

    采用pear方式安装
    I. 安装pear
    apt-get install php-pear 如果没有pear要先安装pear
    II. 安装pdo,pdo_mysql
    pecl install pdo pecl install pdo_mysql
    生成.so复制到/usr/lib目录下.

    如果没有安装php和mysql的开发包,在执行第II步之前还需要安装
    apt-get install php5-devapt-get install libmysqlclient15-dev
    III. 修改配置文件php.ini
    增加条目
    extension=pdo.so
    extension=pdo_mysql.so
    IV. 使之生效
    重新启动apache,运行phpinfo()看是否生效

    在php5.2.10中,php默认已经安装了pdo,所以extension=pdo.so不加,但是发现和自己生成的pdo_mysql.so不匹配错误,解决办法是:
    重新安装php,增加参数--disable-pdo 禁止pdo模块,用自己前面生成pdo.so,pdo+mysql.so就OK了

    安装ImageMagic扩展

    采用pear方式安装
    I. 安装ImageMagick
    sudo apt-get install imagemagick

    II. 安装imagemagick 的lib 供php调用
    sudo apt-get install libmagick++-dev

    III. 调用当前的pecl安装imagick
    pecl install imagick

    IV. 修改php.ini.重启apache服务器
    在php.ini中添加: extension = imagick.so


    phpize的安装

    phpize是属于php-devel的内容,所以只要运行
    apt-get install php-devel就行。ubuntu 下是 apt-get install php-dev

    我安装的时候装的是php5-dev

    装完之后是用phpize5来装自己编写的php扩展

    本人转自 http://blog.csdn.net/zhxp_870516/article/details/8520358

    同时也参考了 http://blog.slps.tp.edu.tw/00086/?p=585

    下面是我自己的defalut 文件内容 #的是注释 因为有的为了tp整合 支持pathinfo 所以有很多注释没去掉,可以参考上面原作者的default配置 这一段我和原作者不一样

    /*

        location ~ .php$ {
            try_files $uri = 404;
            fastcgi_split_path_info ^(.+.php)(/.+)$;
        #    # NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini
        #
        #    # With php5-cgi alone:
            fastcgi_pass 127.0.0.1:9000;
        #    # With php5-fpm:
        #    fastcgi_pass unix:/var/run/php5-fpm.sock;
            fastcgi_index index.php;
            include fastcgi_params;
        }

    */

    以下是defautl的配置

    # You may add here your
    # server {
    #    ...
    # }
    # statements for each of your virtual hosts to this file

    ##
    # You should look at the following URL's in order to grasp a solid understanding
    # of Nginx configuration files in order to fully unleash the power of Nginx.
    # http://wiki.nginx.org/Pitfalls
    # http://wiki.nginx.org/QuickStart
    # http://wiki.nginx.org/Configuration
    #
    # Generally, you will want to move this file somewhere, and start with a clean
    # file but keep this around for reference. Or just disable in sites-enabled.
    #
    # Please see /usr/share/doc/nginx-doc/examples/ for more detailed examples.
    ##

    server {
        
        listen   80; ## listen for ipv4; this line is default and implied
        listen   [::]:80 default ipv6only=on; ## listen for ipv6
     server_name bbb.test.pt;
        root /usr/share/nginx/www;
        index  index.php index.html index.htm;
        #index index.php
        #1.php
        # Make site accessible from http://localhost/
        server_name localhost;

        location / {
            # First attempt to serve request as file, then
            # as directory, then fall back to index.html
            try_files $uri $uri/ /index.html;
            # Uncomment to enable naxsi on this location
     if (!-e $request_filename) {
       rewrite  ^(.*)$  /index.php?s=$1  last;
       break;
        }
            # include /etc/nginx/naxsi.rules
        }

        location /doc/ {
            root /usr/share/;
            autoindex on;
            allow 127.0.0.1;
            deny all;
        }

        # Only for nginx-naxsi : process denied requests
        #location /RequestDenied {
            # For example, return an error code
            #return 418;
        #}

        #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/www;
        }

        # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
        #
        location ~ .php$ {
            try_files $uri = 404;
            fastcgi_split_path_info ^(.+.php)(/.+)$;
        #    # NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini
        #
        #    # With php5-cgi alone:
            fastcgi_pass 127.0.0.1:9000;
        #    # With php5-fpm:
        #    fastcgi_pass unix:/var/run/php5-fpm.sock;
            fastcgi_index index.php;
            include fastcgi_params;
        }
    ###############################
         #去掉$是为了不匹配行末,即可以匹配.php/,以实现pathinfo
        #如果你不需要用到php5后缀,也可以将其去掉
    #    location ~ .php
    #        {
                    #原有代码
                    
                    #定义变量 $path_info ,用于存放pathinfo信息
     #               set $path_info "";
                    #定义变量 $real_script_name,用于存放真实地址
         #           set $real_script_name $fastcgi_script_name;
                    #如果地址与引号内的正则表达式匹配
          #          if ($fastcgi_script_name ~ "^(.+?.php)(/.+)$") {
                            #将文件地址赋值给变量 $real_script_name
           #                 set $real_script_name $1;
                            #将文件地址后的参数赋值给变量 $path_info
            #                set $path_info $2;
             #       }
                    #配置fastcgi的一些参数
              #      fastcgi_param SCRIPT_FILENAME $document_root$real_script_name;
               #     fastcgi_param SCRIPT_NAME $real_script_name;
                #    fastcgi_param PATH_INFO $path_info;
           # }
    #######
         #如果请求既不是一个文件,也不是一个目录,则执行一下重写规则
       # if (!-e $request_filename)
        #    {
                #地址作为将参数rewrite到index.php上。
         #       rewrite ^/(.*)$ /index.php/$1;
                #若是子目录则使用下面这句,将subdir改成目录名称即可。
                #rewrite ^/subdir/(.*)$ /subdir/index.php/$1;
          #  }
    ######

    ##############################
        # deny access to .htaccess files, if Apache's document root
        # concurs with nginx's one
        #
        location ~ /.ht {
            deny all;
        }
    # include /etc/nginx/conf.d/*
    }
    #include /etc/nginx/conf.d/*;

    # another virtual host using mix of IP-, name-, and port-based configuration
    #
    #server {
    #    listen 8000;
    #    listen somename:8080;
    #    server_name somename alias another.alias;
    #    root html;
    #    index index.html index.htm;
    #
    #    location / {
    #        try_files $uri $uri/ /index.html;
    #    }
    #}


    # HTTPS server
    #
    #server {
    #    listen 443;
    #    server_name localhost;
    #
    #    root html;
    #    index index.html index.htm;
    #
    #    ssl on;
    #    ssl_certificate cert.pem;
    #    ssl_certificate_key cert.key;
    #
    #    ssl_session_timeout 5m;
    #
    #    ssl_protocols SSLv3 TLSv1;
    #    ssl_ciphers ALL:!ADH:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv3:+EXP;
    #    ssl_prefer_server_ciphers on;
    #
    #    location / {
    #        try_files $uri $uri/ /index.html;
    #    }
    #}

  • 相关阅读:
    MYSQL转MSSQL
    SVN 服务器IP地址变更后客户端的修改
    gridview
    gridview外边距
    Android开发:自定义GridView/ListView数据源
    Android之Adapter用法总结
    collection set
    listview优化
    android应用开发全程实录-你有多熟悉listview
    android模块
  • 原文地址:https://www.cnblogs.com/xiabaizhu/p/3904822.html
Copyright © 2011-2022 走看看