码迷,mamicode.com
首页 > 数据库 > 详细

ubuntu-12.04.2-desktop-amd64 安装整合 nginx + php + mysql + phpmyadmin + tomcat

时间:2014-08-03 23:11:36      阅读:495      评论:0      收藏:0      [点我收藏+]

标签:des   style   http   color   java   使用   os   strong   

最近需要做jsp项目,部署在ubuntu 下,周末抽时间配置了nginx + php + mysql + phpmyadmin + tomcat 环境,从windows 的C# 转过来, 多少有些不适应, 估计要走全栈的方向了. 顺便整理了一下入门的配置方法, 完全在控制台下完成.

1.1  Common

  • Start Terminal

    Ctrl+Alt+T

  •  使用root用户

    sudo –sH

  • 查看进程

    linux命令ps aux|grep xxx

  • 软连接

    ln -s 源地址  目的地址

   比如把linux文件系统rootfs_dir软链接到/home/jyg/目录下

   ln -s /opt/linux/rootfs_dir  /home/jyg/rootfs_dir就可以了

  • 查找文件

    find / -name [filename]

  • 基于Debian 软件库安装

    apt-get

1.2  Install Java

  • OpenJDK 1.6.0

sudo apt-get install openjdk-6-jdk

sudo apt-get install openjdk-7-jdk

sudo update-alternatives --config java

sudo update-alternatives --config javac

sudo update-alternatives --config javaws

sudo vi /etc/environment

#Add following

JAVA_HOME=”/usr/lib/jvm/java-1.6.0-openjdk-i386”

Test:

source /etc/environment

echo $JAVA_HOME

 

uninstall

sudo apt-get remove openjdk-6-jdk

 

  • oracle JDK 1.7:

The easy way to install the last JKD1.7

-- sudo apt-get install python-software-properties

sudo add-apt-repository ppa:webupd8team/java

sudo apt-get update

sudo apt-get install oracle-java7-installer

  uninstall

    sudo apt-get remove oracle-java7-installer

  • Oralce JDK 1.7.0_03 (由于公司要求,live环境指定了JDK 版本)

  Download JDK

http://download.oracle.com/otn-pub/java/jdk/7u3-b04/jdk-7u3-linux-x64.tar.gz

(you get the permission by access the page:  http://www.oracle.com/technetwork/java/javase/downloads/jdk7-downloads-1637583.html )

cd ~/Downloads

tar –zxcf jdk-7u3-linux-x64.tar.gz

#you will see the folder jdk1.7.0_03, for the same which live ,change the folder name to jdk 1.7.0

 mv jdk1.7.0_03 jdk1.7.0

 sudo mkdir –p –m ug+rw /usr/lib/jvm/jdk1.7.0

 sodu mv  jdk1.7.0 /usr/lib/jvm/

 sudo update-alternatives --install "/usr/bin/java" "java" "/usr/lib/jvm/jdk1. 1.7.0/bin/java" 1

 sudo update-alternatives --install "/usr/bin/javac" "javac" "/usr/lib/jvm/jdk1. 1.7.0/bin/javac" 1

 sudo update-alternatives --install "/usr/bin/javaws" "javaws" "/usr/lib/jvm/jdk1.7.0/bin/javaws" 1

 sudo update-alternatives --config java

 sudo update-alternatives --config javac //

 sudo update-alternatives --config javaws

 sudo vi /etc/environment

#Add following

JAVA_HOME=”/usr/lib/jvm/jdk1.7.0”

 Test:

source /etc/environment

echo $JAVA_HOME 

Notice: If you want to install other version JDK, Please see Install Other JDK

1.3  Install Nginx

sudo apt-get install nginx

Useful Command about Nginx.

Start Nginx:sudo /etc/init.d/nginx start;   // sudo service nginx start

Test: Browser the location:http://localhost ; if browser show "Welcome to nginx!", you have installed Nginx successfully;

Shutdown Nginx:sudo /etc/init.d/nginx stop;

Restart nginx:sudo /etc/init.d/nginx restart;

 **You can run the following command to reveal your virtual server’s IP address.

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

When you visit your IP address page in your browser, you will see the words, “Welcome to nginx”

You can see a screenshot of the utilitarian nginx welcome page here

To ensure that nginx will be up after reboots, it’s best to add it to the startup. Type this command into terminal:

update-rc.d nginx defaults

1.4  Install PHP

  • 安装

sudo apt-get install php5-cli php5-cgi php5-fpm php5-mcrypt php5-mysql

php5-fpm:与nginx配合方式之一,另外个是:spawn-fcgi;

php5-mysql:访问mysql;

 

  • 修改nginx配置

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

将index的一行修改为:“index index.html index.htm index.php;”

去掉下面的注释用于支持php脚本:      

location ~ \.php$ {

       fastcgi_pass 127.0.0.1:9000;

       fastcgi_index index.php;

       include fastcgi_params;

}

  •  测试

Nginx 默认站点目录: cd /usr/share/nginx/www

echo "<?php phpinfo();?>" > test.php

启动nginx:

sudo /etc/init.d/nginx start

访问:http://localhost/test.php

出现php详细信息,配置成功。

关闭nginx

sudo /etc/init.d/nginx stop

1.5  Install Mysql

  • 安装

sudo apt-get install mysql-server

安装过程中要求输入用户名秘密. [mysqlUser] /[mysqlPW]

  • 测试

mysql –u [mysqlUser]–p

              进入到mysql 控制台.

1.6  Install phpmyAdmin

  • 下载phpMyAdmin-4.2.7-all-languages.tar.gz (这个需要手工下载,使用Debian 直接安装的话,和 nginx 集成会比较麻烦)

网站直接下载: http://www.phpmyadmin.net/home_page/downloads.php

Terminal 下载

wget http://prdownloads.sourceforge.net/phpmyadmin/phpMyAdmin-4.2.7-all-languages.tar.gz

保存文件到 /var/lib: sudo mv phpMyAdmin-4.2.7-all-languages.tar.gz /var/lib/phpMyAdmin

  • 下载解压:

      cd /var/lib/phpMyAdmin

sudo tar zxvf phpMyAdmin-4.2.7-all-languages.tar.gz

  • 创建软连接:

      ln –s /var/lib/phpMyAdmin/ phpMyAdmin-4.2.7-all-languages /usr/share/nginx/www/phpmyadmin

  • 测试

访问:http://localhost/phpmyadmin

出现登陆页面, 用mysql 的用户名密度登陆即可.

1.7  Install tomcat 7

sudo apt-get install tomcat7 tomcat7-docs tomcat7-examples tomcat7-admin

Choose username and password to manage tomcat and add to /etc/tomcat7/tomcat-users.xml file in the below format.

<role rolename="manager-gui"/>

<role rolename="admin-gui"/>

<user username="[tomactAdmin]" password="[tomcatPW]" roles="manager-gui,admin-gui"/>

This code must be within this < tomcat-users > …. < / tomcat-users > Tags

Now restart the service.

sudo /etc/init.d/tomcat7 restart

 

  • 与nginx整合
    • Must make sure stop tomcat7 and nginx first: (如果没有stop tomcat 7 , 会出现很多很奇怪的问题)

sudo /etc/init.d/tomcat7 stop

sudo /etc/init.d/nginx stop

 

    • 修改tomcat配置

sudo vi /etc/tomcat7/server.xml

将<Host name="localhost" appBase="webapps" ...>修改为<Host name="localhost" appBase="/usr/share/nginx/www" ...>

    • 修改nginx下proxy_params

sudo vi /etc/nginx/proxy_params

       添加:

        client_max_body_size    10m;

        client_body_buffer_size 128k;

        proxy_connect_timeout   90;

        proxy_send_timeout      90;

        proxy_read_timeout      90;

        proxy_buffer_size       4k;

        proxy_buffers           4 32k;

        proxy_busy_buffers_size 64k;

        proxy_temp_file_write_size 64k;

    • 修改ngingx配置:

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

        修改index行为:“index index.html index.htm index.php index.jsp;”

        在"location ~ \.php${...}"php配置节添加:

        location ~ \.jsp$ {

        index index.jsp;

        proxy_pass http://localhost:8080;

        include proxy_params;

        }

    • 测试

新建目录:sudo mkdir /usr/share/nginx/www/test

 新建JSP文件:sudo vi /usr/share/nginx/www /test/test.jsp

       输入:

       <HTML>

        <BODY>

          <%

             out.println("IP:");

             out.println(request.getHeader("x-forwarded-for"));

          %>

        </BODY>

       </HTML>

启动 tomcat: sudo /etc/init.d/tomcat7 start

启动nginx:sudo /etc/init.d/nginx start

访问:http://localhost/test/test.jsp

如有问题 查看tomcat log:

cat /var/log/tomcat7catalina.out |more

出现"IP:192.168.11.22"配置成功。

说明下,因为此处用了nginx代理的功能,所以要用request.getHeader("x-forwarded-for")获得IP;request.getRemoteHost()获得的将是代理的IP,即:127.0.0.1。

1.8  Install eclipse

sudo apt-get install eclipse-platform

sudo apt-get install eclipse-jdk

 --need reconfig java vm

sudo update-alternatives --config java

sudo update-alternatives --config javac

sudo update-alternatives --config javaws

 

主要参考:  

http://wenku.baidu.com/view/f1b8592a192e45361066f5ad.html

 

ubuntu-12.04.2-desktop-amd64 安装整合 nginx + php + mysql + phpmyadmin + tomcat,布布扣,bubuko.com

ubuntu-12.04.2-desktop-amd64 安装整合 nginx + php + mysql + phpmyadmin + tomcat

标签:des   style   http   color   java   使用   os   strong   

原文地址:http://www.cnblogs.com/inLearning/p/3888960.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!