CentOS 6.5 搭建PHP环境(Nginx+MariaDB+PHP7)

分享下CentOS 6.5 搭建PHP环境(Nginx+MariaDB+PHP7)的心得笔记,有什么不对的地方,还请各位大大指出。

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
gpgcheck=1

sudo yum install MariaDB-server MariaDB-client
#启动MariaDB
sudo /etc/init.d/mysql start

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

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

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

2.nginx

#此命令可以一键安装开发工具包
yum -y groupinstall “Development Tools” “Development Libraries”

 #创建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/bash
# nginx Startup script for the Nginx HTTP Server
#
# chkconfig: – 85 15
# description: Nginx is a high-performance web and proxy server.
#              It has a lot of features, but it’s not for everyone.
# processname: nginx
# pidfile: /var/run/nginx.pid
# config: /usr/local/nginx/conf/nginx.conf

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

RETVAL=0
prog=”nginx”

# Source function library.
. /etc/rc.d/init.d/functions

# Source networking configuration.
. /etc/sysconfig/network

# Check that networking is up.
[ ${NETWORKING} = “no” ] && exit 0

[ -x $nginxd ] || exit 0

# Start nginx daemons functions.
start() {

if [ -e $nginx_pid ];then
  echo “nginx already running….”
  exit 1
fi

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

}

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

# reload nginx service functions.
reload() {

    echo -n $”Reloading $prog: “
    #kill -HUP `cat ${nginx_pid}`
    killproc $nginxd -HUP
    RETVAL=$?
    echo

}

# See how we were called.
case “$1” in
start)
        start
        ;;

stop)
        stop
        ;;

reload)
        reload
        ;;

restart)
        stop
        start
        ;;

status)
        status $prog
        RETVAL=$?
        ;;
*)
        echo $”Usage: $prog {start|stop|restart|reload|status|help}”
        exit 1
esac

exit $RETVAL

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

#cp ./nginx /etc/init.d

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

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

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

#chkconfig –add nginx

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

3.php

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

# 编译安装
# make &&  make install

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

# 启动
# /etc/init.d/php-fpm

# 查看是否启动
ps aux | grep php

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

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

简单配置如下:

user  www www;

worker_processes 10;

#error_log  /data/logs/nginx_error.log  crit;

#pid        logs/nginx.pid;

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

events
{
    use epoll;

    worker_connections 51200;
}

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

    #charset  gbk;
   
    server_names_hash_bucket_size 128;
    client_header_buffer_size 32k;
    large_client_header_buffers 4 32k;
    #client_max_body_size 8m;

    server_tokens off;

    expires      1h;

    sendfile on;
    tcp_nopush    on;
    keepalive_timeout 60;
    tcp_nodelay on;

    error_page  404  /404.jpg;

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

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

    log_format  access  ‘$remote_addr – $remote_user [$time_local] “$request” ‘
                          ‘$status $body_bytes_sent “$http_referer” ‘
                          ‘”$http_user_agent” $http_x_forwarded_for’;

server {
        listen      80;
        server_name  localhost;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        location / {
            root  html;
            index  index.html index.htm index.php;
        }

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

        #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  html;
        }
location ~ \.php$
            {
        fastcgi_pass  127.0.0.1:9000;
              fastcgi_index index.php;
            include fastcgi.conf;
            }
}

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

#    include block_ips.conf ;
#    include vhost/*.conf ;

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

最后phpinfo(),成功。

文章来源网络,作者:运维,如若转载,请注明出处:https://shuyeidc.com/wp/214768.html<

(0)
运维的头像运维
上一篇2025-04-11 22:54
下一篇 2025-04-11 22:55

相关推荐

  • 个人主题怎么制作?

    制作个人主题是一个将个人风格、兴趣或专业领域转化为视觉化或结构化内容的过程,无论是用于个人博客、作品集、社交媒体账号还是品牌形象,核心都是围绕“个人特色”展开,以下从定位、内容规划、视觉设计、技术实现四个维度,详细拆解制作个人主题的完整流程,明确主题定位:找到个人特色的核心主题定位是所有工作的起点,需要先回答……

    2025-11-20
    0
  • 社群营销管理关键是什么?

    社群营销的核心在于通过建立有温度、有价值、有归属感的社群,实现用户留存、转化和品牌传播,其管理需贯穿“目标定位-内容运营-用户互动-数据驱动-风险控制”全流程,以下从五个维度展开详细说明:明确社群定位与目标社群管理的首要任务是精准定位,需明确社群的核心价值(如行业交流、产品使用指导、兴趣分享等)、目标用户画像……

    2025-11-20
    0
  • 香港公司网站备案需要什么材料?

    香港公司进行网站备案是一个涉及多部门协调、流程相对严谨的过程,尤其需兼顾中国内地与香港两地的监管要求,由于香港公司注册地与中国内地不同,其网站若主要服务内地用户或使用内地服务器,需根据服务器位置、网站内容性质等,选择对应的备案路径(如工信部ICP备案或公安备案),以下从备案主体资格、流程步骤、材料准备、注意事项……

    2025-11-20
    0
  • 如何企业上云推广

    企业上云已成为数字化转型的核心战略,但推广过程中需结合行业特性、企业痛点与市场需求,构建系统性、多维度的推广体系,以下从市场定位、策略设计、执行落地及效果优化四个维度,详细拆解企业上云推广的实践路径,精准定位:明确目标企业与核心价值企业上云并非“一刀切”的方案,需先锁定目标客户群体,提炼差异化价值主张,客户分层……

    2025-11-20
    0
  • PS设计搜索框的实用技巧有哪些?

    在PS中设计一个美观且功能性的搜索框需要结合创意构思、视觉设计和用户体验考量,以下从设计思路、制作步骤、细节优化及交互预览等方面详细说明,帮助打造符合需求的搜索框,设计前的规划明确使用场景:根据网站或APP的整体风格确定搜索框的调性,例如极简风适合细线条和纯色,科技感适合渐变和发光效果,电商类则可能需要突出搜索……

    2025-11-20
    0

发表回复

您的邮箱地址不会被公开。必填项已用 * 标注