ubuntu通过apt-get方式搭建lnmp环境以及php扩展安装

v

  一直是在用的lnmp的集成安装包搭建lnmp环境,因为工作需要需要安装ldap扩展,在网上怎么都找不到源码安装包,只能卸载掉原来的lnmp环境,用ubuntu的php5-ldap扩展,

在安装中遇到一些问题,网上的文章坑爹的比较多,写篇文章记录下来。

       

1.安装MySQL

     

[sql] view plain copy
 
  1. sudo apt-get install mysql-server mysql-client  

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

 

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

 

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

 

[sql] view plain copy
 
  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

 

[sql] view plain copy
 
  1. sudo apt-get install nginx  

 

 

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

 

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

 


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

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

 

[sql] view plain copy
 
  1. sudo apt-get install php5-fpm   


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

 

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

[sql] view plain copy
 
  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相关的一些组件。

 

[sql] view plain copy
 
  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.重启服务

 

[sql] view plain copy
 
  1. sudo service php5-fpm restart   
  2. sudo service nginx restart  

      一直是在用的lnmp的集成安装包搭建lnmp环境,因为工作需要需要安装ldap扩展,在网上怎么都找不到源码安装包,只能卸载掉原来的lnmp环境,用ubuntu的php5-ldap扩展,

    在安装中遇到一些问题,网上的文章坑爹的比较多,写篇文章记录下来。

           

    1.安装MySQL

         

    [sql] view plain copy
     
    1. sudo apt-get install mysql-server mysql-client  
    安装过程中要输入root用户的密码。

     

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

     

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

     

    [sql] view plain copy
     
    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

     

    [sql] view plain copy
     
    1. sudo apt-get install nginx  
     

     

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

     

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

     

    
    

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

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

     

    [sql] view plain copy
     
    1. sudo apt-get install php5-fpm   

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

     

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

    [sql] view plain copy
     
    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相关的一些组件。

     

    [sql] view plain copy
     
    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.重启服务

     

    [sql] view plain copy
     
    1. sudo service php5-fpm restart   
    2. sudo service nginx restart  
posted @ 2016-04-21 13:10  brady-wang  阅读(375)  评论(0编辑  收藏  举报