设为首页 收藏本站
查看: 827|回复: 0

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

[复制链接]

尚未签到

发表于 2015-8-21 10:29:25 | 显示全部楼层 |阅读模式
  1.安装mysql
  



[sql] view plaincopy

  • sudo apt-get install mysql-server mysql-client
  安装过程中要输入root用户的密码。
  我在安装中出错,是原来的mysql-cilent mysql-workbench 未完全卸载,将mysql组件完全卸载的方法:
  
  删除mysql前 先删除一下 /var/lib/mysql 还有 /etc/mysql



[sql] view plaincopy

  • sudo rm /var/lib/mysql/ -R
  • sudo rm /etc/mysql/ -R

  • sudo apt-get autoremove mysql* --purge  
  • sudo apt-get remove apparmor
  
全部删除之后再执行  apt-get install mysql-server mysql -client
  2.安装nginx
  



[sql] view plaincopy

  • sudo apt-get install nginx
  
  3.安装成功后。我们重启下nginx服务
  



[sql] view plaincopy

  • 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 plaincopy

  • sudo apt-get install php5-fpm
  
5.接下来我们要修改一下nginx的站点配置了。

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




[sql] view plaincopy

  • server {

  •         listen   80; ## listen for ipv4; this line is default and implied   

  •         listen   [::]:80 default ipv6only=on; ## listen for ipv6   

  •         root /usr/share/nginx/www;

  •         index index.php index.html index.htm;   

  •         # Make site accessible from http://localhost/   

  •         server_name _;

  •         location / {

  •                 # First attempt to serve request as file, then   

  •                 # as directory, then fall back to index.html   

  •                 try_files $uri $uri/ /index.html;   

  •         }

  •         location /doc {

  •                 root /usr/share;

  •                 autoindex on;   

  •                 allow 127.0.0.1;

  •                 deny all;   

  •         }

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

  •         }

  •         # 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$ {

  •                 try_files $uri =404;

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

  •         }

  •         # deny access to .htaccess files, if Apache's document root   

  •         # concurs with nginx's one   

  •         #

  •         location ~ /\.ht {

  •                 deny all;   

  •         }

  • }
  

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



[sql] view plaincopy

  • sudo apt-cache search php5
  • 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 plaincopy

  • sudo service php5-fpm restart
  • 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.iyunv.com/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;
#    }
#}

  

运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-102084-1-1.html 上篇帖子: 一键安装LNMP 下篇帖子: LEMP aka LNMP
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表