ubuntu12.04 apt-get安装 lnmp环境(转)

1.安装mysqlphp

     

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

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

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

 

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

  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.安装nginxsql

 

  1. sudo apt-get install nginx  

 

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

 

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

启动以后咱们就能够访问如下咱们的地址了。看能不能出现nginx的欢迎界面。ubuntu

4.这里咱们使用php5-fpm来做为咱们的php解析。服务器

 

  1. sudo apt-get install php5-fpm   


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

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

相关文章
相关标签/搜索