Home >php教程 >php手册 >Centos6.5 builds php environment (nginx mariadb php7)

Centos6.5 builds php environment (nginx mariadb php7)

WBOY
WBOYOriginal
2016-07-06 13:31:021248browse

php小菜一枚,第一次写bolg,有什么不对的地方,还请各位大大指出 1.mariaDb vim /etc/ yum .repos.d/MariaDB.repo [mariadb ] name = MariaDB baseurl = http://yum.mariadb.org/5.5/centos5-x86 gpgkey =https://yum.mariadb.org/RPM-GPG-KEY-MariaDB gpgc

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

1.mariaDb

vim /etc/<span style="color: #0000ff;">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 style="color: #0000ff;">#此命令可以一键安装开发工具包<br>yum</span> -y groupinstall <span style="color: #800000;">"</span><span style="color: #800000;">Development Tools</span><span style="color: #800000;">"</span> <span style="color: #800000;">"</span><span style="color: #800000;">Development Libraries</span><span style="color: #800000;">"</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脚本如:

进入编辑模式并复制以下内容:查看nginx.shell文件

 

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

nginxd</span>=/usr/local/nginx/sbin/<span style="color: #000000;">nginx
nginx_config</span>=/usr/local/nginx/conf/<span style="color: #000000;">nginx.conf
nginx_pid</span>=/var/run/<span style="color: #000000;">nginx.pid

RETVAL</span>=<span style="color: #800080;">0</span><span style="color: #000000;">
prog</span>=<span style="color: #800000;">"</span><span style="color: #800000;">nginx</span><span style="color: #800000;">"</span><span style="color: #000000;">

# Source </span><span style="color: #0000ff;">function</span><span style="color: #000000;"> library.
. </span>/etc/rc.d/init.d/<span style="color: #000000;">functions

# Source networking configuration.
. </span>/etc/sysconfig/<span style="color: #000000;">network

# Check that networking is up.
[ ${NETWORKING} </span>= <span style="color: #800000;">"</span><span style="color: #800000;">no</span><span style="color: #800000;">"</span> ] && exit <span style="color: #800080;">0</span><span style="color: #000000;">

[ </span>-x $nginxd ] || exit <span style="color: #800080;">0</span><span style="color: #000000;">


# Start nginx daemons functions.
start() {

</span><span style="color: #0000ff;">if</span> [ -e $nginx_pid ];<span style="color: #0000ff;">then</span>
   <span style="color: #0000ff;">echo</span> <span style="color: #800000;">"</span><span style="color: #800000;">nginx already running....</span><span style="color: #800000;">"</span><span style="color: #000000;">
   exit </span><span style="color: #800080;">1</span>
<span style="color: #0000ff;">fi</span>

   <span style="color: #0000ff;">echo</span> -n $<span style="color: #800000;">"</span><span style="color: #800000;">Starting $prog: </span><span style="color: #800000;">"</span><span style="color: #000000;">
   daemon $nginxd </span>-<span style="color: #000000;">c ${nginx_config}
   RETVAL</span>=$?
   <span style="color: #0000ff;">echo</span><span style="color: #000000;">
   [ $RETVAL </span>= <span style="color: #800080;">0</span> ] && <span style="color: #0000ff;">touch</span> /var/lock/subsys/<span style="color: #000000;">nginx
   return $RETVAL

}


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


# reload nginx service functions.
reload() {

    </span><span style="color: #0000ff;">echo</span> -n $<span style="color: #800000;">"</span><span style="color: #800000;">Reloading $prog: </span><span style="color: #800000;">"</span><span style="color: #000000;">
    #</span><span style="color: #0000ff;">kill</span> -HUP `<span style="color: #0000ff;">cat</span><span style="color: #000000;"> ${nginx_pid}`
    killproc $nginxd </span>-<span style="color: #000000;">HUP
    RETVAL</span>=$?
    <span style="color: #0000ff;">echo</span><span style="color: #000000;">

}

# See how we were called.
</span><span style="color: #0000ff;">case</span> <span style="color: #800000;">"</span><span style="color: #800000;">$1</span><span style="color: #800000;">"</span> <span style="color: #0000ff;">in</span><span style="color: #000000;">
start)
        start
        ;;

stop)
        stop
        ;;

reload)
        reload
        ;;

restart)
        stop
        start
        ;;

status)
        status $prog
        RETVAL</span>=$?<span style="color: #000000;">
        ;;
</span>*<span style="color: #000000;">)
        </span><span style="color: #0000ff;">echo</span> $<span style="color: #800000;">"</span><span style="color: #800000;">Usage: $prog {start|stop|restart|reload|status|help}</span><span style="color: #800000;">"</span><span style="color: #000000;">
        exit </span><span style="color: #800080;">1</span>
<span style="color: #0000ff;">esac</span><span style="color: #000000;">

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

# 编译安装
# </span><span style="color: #0000ff;">make</span> &&  <span style="color: #0000ff;">make</span> <span style="color: #0000ff;">install</span><span style="color: #000000;">

# 配置文件
# </span><span style="color: #0000ff;">cp</span> php.ini-development /usr/local/php/lib/<span style="color: #000000;">php.ini
# </span><span style="color: #0000ff;">cp</span> /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-<span style="color: #000000;">fpm.conf
# </span><span style="color: #0000ff;">cp</span> /usr/local/php/etc/php-fpm.d/www.conf.default /usr/local/php/etc/php-fpm.d/<span style="color: #000000;">www.conf
# </span><span style="color: #0000ff;">cp</span> -R ./sapi/fpm/php-fpm /etc/init.d/php-<span style="color: #000000;">fpm

# 启动
# </span>/etc/init.d/php-<span style="color: #000000;">fpm

# 查看是否启动
</span><span style="color: #0000ff;">ps</span> aux | <span style="color: #0000ff;">grep</span> php

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

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

简单配置如下:

<span style="color: #000000;">user  www www;

worker_processes </span><span style="color: #800080;">10</span><span style="color: #000000;">;

#error_log  </span>/data/logs/<span style="color: #000000;">nginx_error.log  crit;


#pid        logs</span>/<span style="color: #000000;">nginx.pid;

#Specifies the value </span><span style="color: #0000ff;">for</span> maximum <span style="color: #0000ff;">file</span><span style="color: #000000;"> descriptors that can be opened by this process.
worker_rlimit_nofile </span><span style="color: #800080;">51200</span><span style="color: #000000;">;

events
{
    use epoll;

    worker_connections </span><span style="color: #800080;">51200</span><span style="color: #000000;">;
}

http
{
    include       mime.types;
    default_type  application</span>/octet-<span style="color: #000000;">stream;

    #charset  gbk;
     
    server_names_hash_bucket_size </span><span style="color: #800080;">128</span><span style="color: #000000;">;
    client_header_buffer_size 32k;
    large_client_header_buffers </span><span style="color: #800080;">4</span><span style="color: #000000;"> 32k;
    #client_max_body_size 8m;

    server_tokens off;

    expires       1h; 

    sendfile on;
    tcp_nopush     on;
    keepalive_timeout </span><span style="color: #800080;">60</span><span style="color: #000000;">;
    tcp_nodelay on;

    error_page   </span><span style="color: #800080;">404</span>  /<span style="color: #800080;">404</span><span style="color: #000000;">.jpg;

     fastcgi_connect_timeout </span><span style="color: #800080;">20</span><span style="color: #000000;">;
     fastcgi_send_timeout </span><span style="color: #800080;">30</span><span style="color: #000000;">;
     fastcgi_read_timeout </span><span style="color: #800080;">120</span><span style="color: #000000;">;
     fastcgi_buffer_size 256k;
     fastcgi_buffers </span><span style="color: #800080;">8</span><span style="color: #000000;"> 256k;
     fastcgi_busy_buffers_size 256k;
     fastcgi_temp_file_write_size 256k;
     fastcgi_temp_path </span>/dev/<span style="color: #000000;">shm;

    </span><span style="color: #0000ff;">gzip</span><span style="color: #000000;"> on;
    gzip_min_length  </span><span style="color: #800080;">2048</span><span style="color: #000000;">;
    gzip_buffers     </span><span style="color: #800080;">4</span><span style="color: #000000;"> 16k;
    gzip_http_version </span><span style="color: #800080;">1.1</span><span style="color: #000000;">;
    gzip_types  text</span>/plain  text/CSS application/xml application/x-<span style="color: #000000;">javascript ;

    log_format  access  </span><span style="color: #800000;">'</span><span style="color: #800000;">$remote_addr - $remote_user [$time_local] "$request" </span><span style="color: #800000;">'</span>
                          <span style="color: #800000;">'</span><span style="color: #800000;">$status $body_bytes_sent "$http_referer" </span><span style="color: #800000;">'</span>
                          <span style="color: #800000;">'</span><span style="color: #800000;">"$http_user_agent" $http_x_forwarded_for</span><span style="color: #800000;">'</span><span style="color: #000000;">;



server {
        listen       </span><span style="color: #800080;">80</span><span style="color: #000000;">;
        server_name  localhost;

        #charset koi8</span>-<span style="color: #000000;">r;

        #access_log  logs</span>/<span style="color: #000000;">host.access.log  main;

        location </span>/<span style="color: #000000;"> {
            root   html;
            index  index.html index.htm index.php;
        }

    #rewrite index.php</span>/^(.*)$ idex.php?s=/$<span style="color: #800080;">1</span> <span style="color: #0000ff;">last</span><span style="color: #000000;"> ;

        #error_page  </span><span style="color: #800080;">404</span>              /<span style="color: #800080;">404</span><span style="color: #000000;">.html;

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


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

#    include block_ips.conf ;
#    include vhost</span><span style="color: #008000;">/*</span><span style="color: #008000;">.conf ;

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

最后phpinfo(),成功

 

 


Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn