Centos 6.5 搭建php环境(nginx+mariadb+php7),centosnginx_PHP教程

WBOY
풀어 주다: 2016-07-12 09:01:57
원래의
850명이 탐색했습니다.

Centos 6.5 搭建php环境(nginx+mariadb+php7),centosnginx

php小菜一枚,第一次写bolg,有什么不对的地方,还请各位大大指出

1.mariaDb

vim /etc/<span>yum</span>.repos.d/MariaDB.repo
로그인 후 복사
<span class="o">[mariadb<span class="o">]
<span class="nv">name <span class="o">= MariaDB
<span class="nv">baseurl <span class="o">= http://yum.mariadb.org/5.5/centos5-x86
<span class="nv">gpgkey<span class="o">=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB
<span class="nv">gpgcheck<span class="o">=1<br /><br />sudo yum install MariaDB-server MariaDB-client<br />#启动MariaDB<br /></span></span></span></span></span></span></span></span></span></span>sudo /etc/init.d/mysql start
로그인 후 복사

通过在创建MariaDB.repo,可以实现yum安装

对应不同linux版本配置文件,和详细方法可以参考下面链接

https://mariadb.com/kb/zh-cn/installing-mariadb-with-yum/

https://downloads.mariadb.org/mariadb/repositories/#mirror=opencas

2.nginx

<span>#此命令可以一键安装开发工具包<br />yum</span> -y groupinstall <span>"</span><span>Development Tools</span><span>"</span> <span>"</span><span>Development Libraries</span><span>"</span>
로그인 후 복사

 #创建www组与www用户
groupadd www
useradd -g www -s /usr/sbin/nologin www

 # 安装Nginx

 tar zxvf nginx-1.9.9.tar.gz

 cd nginx-1.9.9.tar.gz/
 ./configure --user=www --group=www --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module
 make && make install

 #启动Nginx
 /usr/local/nginx/sbin/nginx
 #测试配置文件是否正确
 /usr/local/nginx/sbin/nginx -t

还可以通过service命令来操作nginx服务,如下

1.先创建一个文件,里面写入以下shell脚本如:

Centos 6.5 搭建php环境(nginx+mariadb+php7),centosnginx_PHP教程文件

#!/bin/<span>bash
# nginx Startup script </span><span>for</span><span> the Nginx HTTP Server
#
# chkconfig: </span>- <span>85</span> <span>15</span><span>
# description: Nginx is a high</span>-<span>performance web and proxy server.
#              It has a lot of features, but it</span><span>'</span><span>s not for everyone.</span>
<span># processname: nginx
# pidfile: </span>/var/run/<span>nginx.pid
# config: </span>/usr/local/nginx/conf/<span>nginx.conf

nginxd</span>=/usr/local/nginx/sbin/<span>nginx
nginx_config</span>=/usr/local/nginx/conf/<span>nginx.conf
nginx_pid</span>=/var/run/<span>nginx.pid

RETVAL</span>=<span>0</span><span>
prog</span>=<span>"</span><span>nginx</span><span>"</span><span>

# Source </span><span>function</span><span> library.
. </span>/etc/rc.d/init.d/<span>functions

# Source networking configuration.
. </span>/etc/sysconfig/<span>network

# Check that networking is up.
[ ${NETWORKING} </span>= <span>"</span><span>no</span><span>"</span> ] && exit <span>0</span><span>

[ </span>-x $nginxd ] || exit <span>0</span><span>


# Start nginx daemons functions.
start() {

</span><span>if</span> [ -e $nginx_pid ];<span>then</span>
   <span>echo</span> <span>"</span><span>nginx already running....</span><span>"</span><span>
   exit </span><span>1</span>
<span>fi</span>

   <span>echo</span> -n $<span>"</span><span>Starting $prog: </span><span>"</span><span>
   daemon $nginxd </span>-<span>c ${nginx_config}
   RETVAL</span>=$?
   <span>echo</span><span>
   [ $RETVAL </span>= <span>0</span> ] && <span>touch</span> /var/lock/subsys/<span>nginx
   return $RETVAL

}


# Stop nginx daemons functions.
stop() {
        </span><span>echo</span> -n $<span>"</span><span>Stopping $prog: </span><span>"</span><span>
        killproc $nginxd
        RETVAL</span>=$?
        <span>echo</span><span>
        [ $RETVAL </span>= <span>0</span> ] && <span>rm</span> -f /var/lock/subsys/nginx /var/run/<span>nginx.pid
}


# reload nginx service functions.
reload() {

    </span><span>echo</span> -n $<span>"</span><span>Reloading $prog: </span><span>"</span><span>
    #</span><span>kill</span> -HUP `<span>cat</span><span> ${nginx_pid}`
    killproc $nginxd </span>-<span>HUP
    RETVAL</span>=$?
    <span>echo</span><span>

}

# See how we were called.
</span><span>case</span> <span>"</span><span>$1</span><span>"</span> <span>in</span><span>
start)
        start
        ;;

stop)
        stop
        ;;

reload)
        reload
        ;;

restart)
        stop
        start
        ;;

status)
        status $prog
        RETVAL</span>=$?<span>
        ;;
</span>*<span>)
        </span><span>echo</span> $<span>"</span><span>Usage: $prog {start|stop|restart|reload|status|help}</span><span>"</span><span>
        exit </span><span>1</span>
<span>esac</span><span>

exit $RETVAL</span>
로그인 후 복사

2.把这个文件复制到/etc/init.d目录下

#cp ./nginx /etc/init.d

3.修改这个文件为可执行的权限

#chmod +x /etc/init.d/nginx

4.把这个可执行文件加到服务服务中去

#chkconfig --add nginx

之后就可以使用 service 命令来管理了!

3.php

<span>#安装前先更新所需要的模块
# </span><span>yum</span> -y <span>install</span> libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel mysql pcre-<span>devel
# </span><span>wget</span>  https:<span>//</span><span>downloads.php.net/~ab/php-7.0.0RC1.tar.gz</span>
# <span>tar</span> zxvf php-<span>7.0</span>.0RC1.<span>tar</span><span>.gz
# cd php</span>-<span>7.0</span><span>.0RC1
# .</span>/configure --prefix=/usr/local/<span>php \
 </span>--with-<span>curl \
 </span>--with-freetype-<span>dir</span><span> \
 </span>--with-<span>gd \
 </span>--with-<span>gettext \
 </span>--with-iconv-<span>dir</span><span> \
 </span>--with-<span>kerberos \
 </span>--with-libdir=<span>lib64 \
 </span>--with-libxml-<span>dir</span><span> \
 </span>--with-<span>mysqli \
 </span>--with-<span>openssl \
 </span>--with-pcre-<span>regex \
 </span>--with-pdo-<span>mysql \
 </span>--with-pdo-<span>sqlite \
 </span>--with-<span>pear \
 </span>--with-png-<span>dir</span><span> \
 </span>--with-<span>xmlrpc \
 </span>--with-<span>xsl \
 </span>--with-<span>zlib \
 </span>--enable-<span>fpm \
 </span>--enable-<span>bcmath \
 </span>--enable-<span>libxml \
 </span>--enable-inline-<span>optimization \
 </span>--enable-gd-native-<span>ttf \
 </span>--enable-<span>mbregex \
 </span>--enable-<span>mbstring \
 </span>--enable-<span>opcache \
 </span>--enable-<span>pcntl \
 </span>--enable-<span>shmop \
 </span>--enable-<span>soap \
 </span>--enable-<span>sockets \
 </span>--enable-<span>sysvsem \
 </span>--enable-<span>xml \
 </span>--enable-<span>zip</span><span>

# 编译安装
# </span><span>make</span> &&  <span>make</span> <span>install</span><span>

# 配置文件
# </span><span>cp</span> php.ini-development /usr/local/php/lib/<span>php.ini
# </span><span>cp</span> /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-<span>fpm.conf
# </span><span>cp</span> /usr/local/php/etc/php-fpm.d/www.conf.default /usr/local/php/etc/php-fpm.d/<span>www.conf
# </span><span>cp</span> -R ./sapi/fpm/php-fpm /etc/init.d/php-<span>fpm

# 启动
# </span>/etc/init.d/php-<span>fpm

# 查看是否启动
</span><span>ps</span> aux | <span>grep</span> php
로그인 후 복사

修改nginx配置,监听*.php的文件

# vim /usr/local/nginx/conf/nginx.conf

简单配置如下:

<span>user  www www;

worker_processes </span><span>10</span><span>;

#error_log  </span>/data/logs/<span>nginx_error.log  crit;


#pid        logs</span>/<span>nginx.pid;

#Specifies the value </span><span>for</span> maximum <span>file</span><span> descriptors that can be opened by this process.
worker_rlimit_nofile </span><span>51200</span><span>;

events
{
    use epoll;

    worker_connections </span><span>51200</span><span>;
}

http
{
    include       mime.types;
    default_type  application</span>/octet-<span>stream;

    #charset  gbk;
     
    server_names_hash_bucket_size </span><span>128</span><span>;
    client_header_buffer_size 32k;
    large_client_header_buffers </span><span>4</span><span> 32k;
    #client_max_body_size 8m;

    server_tokens off;

    expires       1h; 

    sendfile on;
    tcp_nopush     on;
    keepalive_timeout </span><span>60</span><span>;
    tcp_nodelay on;

    error_page   </span><span>404</span>  /<span>404</span><span>.jpg;

     fastcgi_connect_timeout </span><span>20</span><span>;
     fastcgi_send_timeout </span><span>30</span><span>;
     fastcgi_read_timeout </span><span>120</span><span>;
     fastcgi_buffer_size 256k;
     fastcgi_buffers </span><span>8</span><span> 256k;
     fastcgi_busy_buffers_size 256k;
     fastcgi_temp_file_write_size 256k;
     fastcgi_temp_path </span>/dev/<span>shm;

    </span><span>gzip</span><span> on;
    gzip_min_length  </span><span>2048</span><span>;
    gzip_buffers     </span><span>4</span><span> 16k;
    gzip_http_version </span><span>1.1</span><span>;
    gzip_types  text</span>/plain  text/css application/xml application/x-<span>javascript ;

    log_format  access  </span><span>'</span><span>$remote_addr - $remote_user [$time_local] "$request" </span><span>'</span>
                          <span>'</span><span>$status $body_bytes_sent "$http_referer" </span><span>'</span>
                          <span>'</span><span>"$http_user_agent" $http_x_forwarded_for</span><span>'</span><span>;



server {
        listen       </span><span>80</span><span>;
        server_name  localhost;

        #charset koi8</span>-<span>r;

        #access_log  logs</span>/<span>host.access.log  main;

        location </span>/<span> {
            root   html;
            index  index.html index.htm index.php;
        }

    #rewrite index.php</span>/^(.*)$ idex.php?s=/$<span>1</span> <span>last</span><span> ;

        #error_page  </span><span>404</span>              /<span>404</span><span>.html;

        # redirect server error pages to the static page </span>/<span>50x.html
        #
        error_page   </span><span>500</span> <span>502</span> <span>503</span> <span>504</span>  /<span>50x.html;
        location </span>= /<span>50x.html {
            root   html;
        }
location </span>~<span> \.php$
            {
         fastcgi_pass  </span><span>127.0</span>.<span>0.1</span>:<span>9000</span><span>;
              fastcgi_index index.php;
             include fastcgi.conf;
            }
}


#################  include  ###################

#    include block_ips.conf ;
#    include vhost</span><span>/*</span><span>.conf ;

#强制域名访问对应域名的conf
#    server {
#        listen 80 default ;
#        server_name _;
#        return 404;
#    }
} </span>
로그인 후 복사

最后phpinfo(),成功

 

 

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/1086846.htmlTechArticleCentos 6.5 搭建php环境(nginx+mariadb+php7),centosnginx php小菜一枚,第一次写bolg,有什么不对的地方,还请各位大大指出 1.mariaDb vim /etc/ yum .repos...
관련 라벨:
원천:php.cn
본 웹사이트의 성명
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.
인기 튜토리얼
더>
최신 다운로드
더>
웹 효과
웹사이트 소스 코드
웹사이트 자료
프론트엔드 템플릿