CentOS 7 nginx+php5.6环境搭建

CentOS 7 nginx+php5.6环境搭建

  • linux+nginx+php5.6+mysql 安装配置
    • 环境安装
    • 服务配置
      • nginx配置
      • php配置
      • php-fpm配置
      • mysql配置

linux+nginx+php5.6+mysql 安装配置

首先安装环境,包含:nginx、php5.6、mysql和php相关扩展。

环境安装

centOS安装常用软件:

  1. 基础环境
    #rpm扩展包
    yum install epel-release
    yum install redis
    #常用软件安装
    yum install lrzsz git zip unzip
    
  2. nginx
    #安装
    yum install nginx
    
  3. php5.6
    #配置remi源
    rpm -ivh http://rpms.famillecollet.com/enterprise/remi-release-7.rpm
    yum install --enablerepo=remi --enablerepo=remi-php56 php php-fpm
    yum install --enablerepo=remi --enablerepo=remi-php56 php-opcache php-mbstring php-mysql* php-gd php-redis php-mcrypt php-xml php-redis
    
  4. mysql
    #下载mysql5.7的仓库
    wget http://dev.mysql.com/get/mysql57-community-release-el7-7.noarch.rpm
    #本地yum安装
    yum localinstall mysql57-community-release-el7-7.noarch.rpm
    #启用mysql5.7的仓库
    yum repolist enabled | grep "mysql.*-community.*"
    yum install mysql-community-server
    

服务配置

nginx配置

#设置开启启动
systemctl enable nginx
systemctl start nginx

#如果多个网站,需配置虚拟主机
vim /etc/nginx/nignx.conf
server {
    listen       80;
    server_name  www.test.com test.com;
    root     /data/www/Public;
    index  index.php index.html;

    location / {
            try_files $uri $uri/ /index.php?$args;
    }
    location ~ index.php {
        fastcgi_connect_timeout 20s;     # default of 60s is just too long
        fastcgi_read_timeout 20s;       # default of 60s is just too long
        include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_pass 127.0.0.1:9000;    # assumes you are running php-fpm locally on port 9000
        fastcgi_param  PHP_VALUE  "open_basedir=/data/www/:/data/www/Data:/tmp/";
    }
}

#https配置
server {
    listen 443;
    server_name  www.test.com test.com;
    root     /data/www/Public;
    index  index.php index.html;

    ssl on;
    ssl_certificate   cert/www.test.com.pem;
    ssl_certificate_key  cert/www.test.com.key;
    ssl_session_timeout 5m;
    ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4;
    ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
    ssl_prefer_server_ciphers on;

    location / {
        try_files $uri $uri/ /index.php?$args;
    }
    location ~ index.php {
        fastcgi_connect_timeout 20s;     # default of 60s is just too long
        fastcgi_read_timeout 20s;       # default of 60s is just too long
        include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_pass 127.0.0.1:9000;    # assumes you are running php-fpm locally on port 9000
        fastcgi_param  PHP_VALUE  "open_basedir=/data/www/:/data/www/Data:/tmp/";
    }
}

php配置

#配置php.ini
vim /etc/php.ini
#禁用函数
disable_functions =exec,passthru,system,shell_exec,ini_alter,ini_restore,dl,syslog,readlink,symlink,popen

php-fpm配置

#php-fpm属主配置
vim /etc/php-fpm.d/www.conf
user = nginx
group = nginx
#开启启动
systemctl restart php-fpm
systemctl enable php-fpm

mysql配置

#mysql5.7安装后,自动初始化root密码,并写到/var/log/mysqld.log中
#查看初始化root密码
grep "temporary password" /var/log/mysqld.log
#使用临时root密码登录,并设置root密码(需要强密码)
SET PASSWORD = PASSWORD('你的新密码');

#开启远程访问
GRANT ALL PRIVILEGES ON *.* TO 'dbuser'@'%' IDENTIFIED BY 'mysql密码' WITH GRANT OPTION;
flush privileges;

#使用dbuser尝试远程链接
#使用navcat活着mysql -udbuser -p mysql密码 连接

#开启启动
systemctl restart mysqld
systemctl enable mysqld

你可能感兴趣的:(linux)