CentOS下安装配置 Ngnix_tomcat_PHP_Mysql

安装Nginx

yum install nginx

如果显示找不到 nginx包,新建一个文件/etc/yum.repos.d/nginx.repo,内容:


[nginx]
name=nginx repo
baseurl=http://nginx.org/packages/OS/OSRELEASE/$basearch/
gpgcheck=0
enabled=1

其中:OS替换成centos或者rhel,根据你安装的发行版版本 OSRELEASE替换成5,6或者7,分别对应着5.想,6.x,7.x

如:

[nginx]
name=nginx repo
baseurl=http://nginx.org/packages/centos/6/$basearch/
gpgcheck=0
enabled=1
~

删除之前的httpd

yum remove httpd

安装

yum install ngnix

判断conf

 /usr/sbin/nginx -t

启动:

service nginx restart

加入自启动

chkconfig --levels 235 nginx on

安装PHP

yum install php-fpm php-cli php-mysql php-gd php-imap php-ldap php-odbc php-pear php-xml php-xmlrpc php-mbstring php-mcrypt php-mssql php-snmp php-soap php-tidy

vi /etc/php.ini

在文件末尾添加cgi.fix_pathinfo = 1

启动php-fpm:

service php-fpm start

php-fpm加入启动项:

chkconfig --levels 235 php-fpm on

安装Tomcat

下载解压到/usr/local/tomcat

端口改为8090

启动即可

安装mysql:

yum install mysql mysql-server

修改密码:

grant all on *.* to 'root'@'localhost' IDENTIFIED BY '你的密码'with grant option ;
flush privileges

配置Nginx:

进入/etc/nginx

新建一个文件:

proxy.conf:

proxy_redirect          off;
proxy_set_header        Host $host;
proxy_set_header        X-Real-IP $remote_addr;
#proxy_set_header       X-Forwarded-For   $proxy_add_x_forwarded_for;
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;

进入:/etc/nginx/conf.d

新建tomcat.conf

server {
    listen       8080;
    server_name  localhost;

    #charset koi8-r;
    #access_log  /var/log/nginx/log/host.access.log  main;

    location / {
        #root   /usr/share/nginx/html;
        index  index.html index.htm;
	proxy_pass http://127.0.0.1:8090/;
    }

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

    # 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$ {
    #    root           html;
    #    fastcgi_pass   127.0.0.1:9000;
    #    fastcgi_index  index.php;
    #    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
    #    include        fastcgi_params;
    #}

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

nginx配置完成

配置default.conf(也可以新建一个):

server {
    listen       80;
    server_name  localhost;

    #charset koi8-r;
    #access_log  /var/log/nginx/log/host.access.log  main;

    location / {
        #root   /usr/share/nginx/html;
        root   /var/www/html;
        index  index.html index.htm;
    }

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

    # 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$ {
    #    root           html;
    #    fastcgi_pass   127.0.0.1:9000;
    #    fastcgi_index  index.php;
    #    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
    #    include        fastcgi_params;
    #}

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

重启即可

也可以平滑重启:/usr/sbin/nginx -t -c /etc/nginx/nginx.conf

注:

chkconfig 使用范例:

chkconfig --list        #列出所有的系统服务

chkconfig --add httpd        #增加httpd服务

chkconfig --del httpd        #删除httpd服务

chkconfig --level httpd 2345 on        #设置httpd在运行级别为2、3、4、5的情况下都是on(开启)的状态

chkconfig --list        #列出系统所有的服务启动情况

chkconfig --list mysqld        #列出mysqld服务设置情况

chkconfig --level 35 mysqld on        #设定mysqld在等级3和5为开机运行服务,--level 35表示操作只在等级3和5执行,on表示启动,off表示关闭

chkconfig mysqld on        #设定mysqld在各等级为on,“各等级”包括2、3、4、5等级

如何增加一个服务:

1.服务脚本必须存放在/etc/ini.d/目录下;

2.chkconfig --add servicename

在chkconfig工具服务列表中增加此服务,此时服务会被在/etc/rc.d/rcN.d中赋予K/S入口了;

3.chkconfig --level 35 mysqld on

修改服务的默认启动等级。

时间: 2024-08-25 07:29:19

CentOS下安装配置 Ngnix_tomcat_PHP_Mysql的相关文章

阿里云服务器centos下安装配置svn服务器

阿里云服务器centos下安装配置svn服务器 1.安装svn服务器端 yum install subversion      从镜像下载安装svn服务器端中间会提示是否ok,输入y,确认安装成功提示:.....complete!依次执行如下命令:cd /usr/local/              //进入目录,准备创建svn目录 mkdir svnRepo                   //创建一个svn目录 chmod -R 777 svnRepo            //修改目

CentOS下安装配置LAMP(Linux+Apache+MySQL+PHP)

关于LAMP的各种知识,今天主要是介绍一下在CentOS下安装,搭建一个Web服务器的过程.(本文是使用安装包安装) 一.简介 什么是LAMP     LAMP是一种Web网络应用和开发环境,是Linux, Apache, MySQL, Php/Perl的缩写,每一个字母代表了一个组件,每个组件就其本身而言都是在它所代表的方面功能非常强大的组件.     LAMP这个词的由来最早始于德国杂志“c't Magazine”,Michael  Kunze在1990年最先把这些项目组合在一起创造了LAM

Linux centos 下安装配置SVN服务器

centos服务器上安装配置SVN(subversion),其实是很简单的,只是有些时候在配置的过程中有个别细节如果不注意,会容易造成访问不了的情况. 网上这类的讲解很多,下面的步骤整体上都是不变的,会加一点自己遇到的问题的解决过程和方法. ------------------------------------------------------------------------------------- 在线安装方法: 1,查看当前是否已经安装了SVN: #rpm -qa | grep s

CentOS下 安装配置hadoop环境--单实例版

CentOS下1.安装linux2.安装jdk[[email protected] ~]# javac //显示信息[[email protected] ~]# rpm -qa |grep jdk //查看是否有安装包 [[email protected] ~]# which java //查看Java命令位置/usr/bin/java[[email protected] ~]# javac -version //查看Java版本javac 1.8.0_191[[email protected]

CentOS 下安装配置Varnish

#!/bin/bash# BY kerryhu# MAIL:[email protected]# BLOG:http://kerry.blog.51cto.com# Please manual operation yum of before Operation.....#============================ 更新系统时间 ============================yum install -y ntpntpdate time.nist.govecho "00 01

CentOS下安装配置Nginx

1.安装说明 系统环境:CentOS-6.3 软件:nginx-1.9.0.tar.gz 安装方式:源码编译安装 安装位置:/usr/local/src/nginx_1.9.0 下载地址:http://nginx.org/en/download.html 2.安装前提 在安装nginx前,需要确保系统安装了g++.gcc.openssl-devel.pcre-devel和zlib-devel软件.安装必须软件: 安装命令如下: [root@localhost /]# yum install gc

centos下安装配置mongodb

1:安装mkdir -p /app/mongodb tar zxvf mongodb-linux-x86_64-rhel62-3.4.6.tgz vi .bash_profile PATH=$PATH:$HOME/binPATH=$PATH:/app/mongodb/mongodb-linux-x86_64-rhel62-3.4.5/binexport PATH --让配置文件生效source .bash_profile --在/app/mongodb目录下创建mongo.confdbpath=

CentOS下安装配置KVM

OS version: CentOS Linux release 7.6.1810 (Core) Install KVM kernel yum install -y centos-release-qemu-ev.noarchyum install -y qemu-kvm.x86_64 qemu-kvm-tools.x86_64 Install virt mgmt tool yum install libvirt.x86_64 libvirt-cim.x86_64 libvirt-client.x

Linux CentOS下安装、配置mysql数据库

如果要在Linux上做j2ee开发,首先得搭建好j2ee的开发环境,包括了jdk.tomcat.eclipse的安装(这个在之前的一篇随笔中已经有详细讲解了Linux学习之CentOS(七)--CentOS下j2ee环境搭建),如果要开发web项目,我们当然可以安装一个myeclipse到Linux系统上去,这个安装方法和安装eclipse完全相同,就没有记录下来了,有了jdk.tomcat.eclipse我们就已经能进行我们的程序开发了,但是如果要做一个项目,哪怕是小的不能再小的项目都离不开数