Centost 搭建PHP运行环境

网上有很多搭建PHP运行环境的文章,之前也都是按照这些文章去搭建的环境,遇到过很多坑。
所以这里总结了一些用着还是比较好用的文章。

  • 安装LNMP之前要安装EPEL,以便安装源以外的软件,如Nginx,phpMyAdmin等。

    yum install epel-release
    yum update
    

  • 安装Nginx
    yum install nginx 
    systemctl start nginx #启动nginx 
    systemctl enable nginx #设置开机启动
    

  • 修改nginx的配置
vim /etc/nginx/conf.d/default.conf  
user root;
# 进程数默认auto
#worker_processes 2;
# 开启两个进程,对应两个cpu
#worker_cpu_affinity 01 10;
# 进程最大打开文件数 | 可设置到65536
worker_rlimit_nofile 10240;

error_log /var/log/nginx/error.log;
pid /run/nginx.pid;

include /usr/share/nginx/modules/*.conf;

events {
    # 单个进程允许的客户端最大连接数
    worker_connections 1024;
    # 使用epoll模型
    use epoll;
}

http {
    # 日志格式
    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';
    access_log  /var/log/nginx/access.log  main;

    # 文件扩展名与文件类型映射表
    include /etc/nginx/mime.types;
    # 避免浏览器自动播放文件
    default_type        application/octet-stream;

    charset UTF-8;


    # nginx优化----------------------
    #隐藏版本号
    server_tokens on;

    #优化服务器域名的散列表大小
    server_names_hash_bucket_size 64;
    server_names_hash_max_size 2048;

    #开启高效文件传输模式
    sendfile on;
    #减少网络报文段数量
    tcp_nopush on;
    #提高I/O性能
    tcp_nodelay on;

    #连接超时 时间定义 默认秒 默认65秒
    keepalive_timeout 60;

    #读取客户端请求头数据的超时时间 默认秒 默认60秒
    client_header_timeout 15;

    #读取客户端请求主体的超时时间 默认秒 默认60秒
    client_body_timeout 15;

    #响应客户端的超时时间 默认秒 默认60秒
    send_timeout 25;

    #上传文件的大小限制  默认1m
    client_max_body_size 8M;
    # 如果上传文件小于下面的配置,就存在缓存中,大于就存入文件中
    client_body_buffer_size 128k;
    # 默认配置存入文件的地址,默认是 /tmp/文件下
    #client_body_temp /tmp/

    # 默认关闭 off | on表示接收fastcgi输出的http 1.0 response code,
    # 后端php可以输出header指示nginx输出什么错误页面。开启这个之后,我们才能在php里面自定义错误代码和页面。
    fastcgi_intercept_errors off;


    open_file_cache max=100000 inactive=20s;
    open_file_cache_valid 30s;
    open_file_cache_min_uses 1;

    #fastcgi_cache_path /home/cache/fcgi levels=1:2 keys_zone=fcgi:15m inactive=1d max_size=5g;
    # 15m为内存占用  1g为硬盘最大占用空间

    fastcgi_connect_timeout 300;
    fastcgi_send_timeout 300;
    fastcgi_read_timeout 300;
    fastcgi_buffer_size 512k;
    fastcgi_buffers 6 512k;
    fastcgi_busy_buffers_size 512k;
    fastcgi_temp_file_write_size 512k;


  # 开启gzip---------------------
  gzip on;

  # 启用gzip压缩的最小文件;小于设置值的文件将不会被压缩
  gzip_min_length 1k;

  # gzip 压缩级别,1-9,数字越大压缩的越好,也越占用CPU时间
  gzip_comp_level 2;

  # 进行压缩的文件类型。
  gzip_types text/plain application/javascript application/x-javascript text/css application/xml text/javascript application/x-httpd-php image/jpeg image/gif image/png;

  # nginx对于静态文件的处理模块,开启后会寻找以.gz结尾的文件,直接返回,不会占用cpu进行压缩,如果找不到则不进行压缩
  gzip_static on;

  # 是否在http header中添加Vary: Accept-Encoding,建议开启
  gzip_vary on;
  # 设置压缩所需要的缓冲区大小,以4k为单位,如果文件为7k则申请2*4k的缓冲区
  gzip_buffers 2 4k;

  # 设置gzip压缩针对的HTTP协议版本
  gzip_http_version 1.1;


    server {
        listen       80 default_server;
        index index.php index.html;
        server_name  localhost;
        root         /var/www;

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

        # 单独目录开启目录树
        # location /resource/ {
        #     autoindex  on;
        # }


        location ~ \.php$ {
            root           /var/www;
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.php;
            fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
            include        fastcgi_params;
        }



        error_page 404 /404.html;
        location = /40x.html {

        }

        error_page 500 502 503 504 /50x.html;
        location = /50x.html {

        }
    }

    include /etc/nginx/default.d/*.conf;

}

  • 安装PHP
  1. 换源:

    rpm -Uvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
    rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm
    
  2. 安装:

    yum install -y php71w php71w-devel php71w-fpm php71w-mysql php71w-common php71w-devel php71w-gd libjpeg* php71w-imap php71w-ldap php71w-odbc php71w-pear php71w-xml php71w-xmlrpc php71w-mbstring php71w-mcrypt php71w-bcmath php-mhash libmcrypt libmcrypt-devel
    
  3. 开启php-fpm

    systemctl start php-fpm #开启php-fpm 
    systemctl enable php-fpm #开机自动启动
    

  • 安装MySQL

    方法一:安装mariadb

    yum install mariadb-server mariadb 
    systemctl start mariadb # 启动mariadb
    systemctl enable mariadb # 设置开机启动
    

    mariadb数据库的相关命令是:

    systemctl start mariadb  #启动MariaDB
    systemctl stop mariadb  #停止MariaDB
    systemctl restart mariadb  #重启MariaDB
    systemctl enable mariadb  #设置开机启动
    

    然后就可以正常使用mysql了

    mysql -u root -p
    

    方法二:官网下载安装mysql-server

    wget http://dev.mysql.com/get/mysql-community-release-el7-5.noarch.rpm
    rpm -ivh mysql-community-release-el7-5.noarch.rpm
    yum install mysql-community-server
    
    systemctl start mysql # 启动MySQL
    systemctl enable mysql # 设置开机启动
    

    初次安装MySQL,root账号是没有密码的

    设置密码:

    mysql> set password for 'root'@'localhost' =password('password');
    Query OK, 0 rows affected (0.00 sec) # 成功返回状态
    

    配置MySQL编码:

    vim /etc/my.cnf # 编辑配置文件
    

    在最后加上编码配置

    [mysql]
    default-character-set =utf8
    

    远程连接设置:
    把在所有数据库的所有表的所有权限赋值给位于所有IP地址的root用户。

    mysql> grant all privileges on *.* to root@'%'identified by 'password';
    

    如果是新用户而不是root,则要先新建用户

    mysql> create user 'username'@'%' identified by 'password';  
    

    此时就可以进行远程连接了。


安装了PHP肯定得知道怎么卸载才干净的

yum 安装的PHP卸载

查看php版本命令:
#php -v

这个命令是删除不干净的
#yum remove php

因为使用这个命令以后再用
#php -v
还是会看到有版本信息的。。。。。

必须强制删除
#rpm -qa|grep php

提示如下
#php-pdo-5.1.6-27.el5_5.3
#php-mysql-5.1.6-27.el5_5.3
#php-xml-5.1.6-27.el5_5.3
#php-cli-5.1.6-27.el5_5.3
#php-common-5.1.6-27.el5_5.3
#php-gd-5.1.6-27.el5_5.3

注意卸载要先卸载没有依赖的

pdo是mysql的依赖项;common是gd的依赖项;
例如:# rpm -e php-pdo-5.1.6-27.el5_5.3
error: Failed dependencies:
php-pdo is needed by (installed) php-mysql-5.1.6-27.el5_5.3.i386

所以正确的卸载顺序是:
#rpm -e php-mysql-5.1.6-27.el5_5.3
#rpm -e php-pdo-5.1.6-27.el5_5.3
#rpm -e php-xml-5.1.6-27.el5_5.3
#rpm -e php-cli-5.1.6-27.el5_5.3
#rpm -e php-gd-5.1.6-27.el5_5.3
#rpm -e php-common-5.1.6-27.el5_5.3

再用 # php -v
查看版本信息已经没有提示


原文转载地址:
https://blog.csdn.net/u011323949/article/details/73379146
http://www.cnblogs.com/starof/p/4680083.html
https://blog.csdn.net/woshizhangliang999/article/details/56667934

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值