Centos 下安装 PHP7.2 + Nginx + Mariadb

Centos 下安装 PHP7.2 + Nginx + Mariadb过程全记录。

安装Nginx

  1. 下载Nginx源代码:
    wget http://nginx.org/download/nginx-1.15.7.tar.gz

  2. 解压Nginx源代码:
    tar -zxvf nginx-1.15.7.tar.gz

  3. 安装依赖:
    sudo yum install pcre-devel zlib-devel gcc gcc-c++ openssl openssl-devel

  4. 进入源代码文件夹,配置、编译、安装:

    cd nginx-1.15.7/

    ./configure --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module --with-http_v2_module

    make

    sudo make install

  1. 为nginx添加环境变量, 在 /etc/profile 文件 末尾添加一行:
    PATH=/usr/local/nginx/sbin/:$PATH

  2. 使环境变量生效:
    source /etc/profile

  3. 添加sudo环境变量,编辑 /etc/sudoers 文件中 Defaults secure_path 属性加上nginx的路径:,修改后的内容:
    Defaults secure_path = /sbin:/bin:/usr/sbin:/usr/bin:/usr/local/nginx/sbin/:

  4. 启动Nginx:
    sudo nginx

安装Mariadb

  1. 安装mariadb
    sudo yum install mariadb mariadb-server
  2. 启动mariadb:
    sudo systemctl start mariadb
  3. 执行数据库初始化安装、设置root密码:
    sudo mysql_secure_installation

安装PHP

  1. 下载PHP 7.2源代码:
    wget http://hk2.php.net/get/php-7.2.12.tar.gz/from/this/mirror

  2. 解压缩源代码:
    tar -zxvf mirror

  3. 安装依赖:
    sudo yum install openssl-devel libxml2-devel bzip2-devel libcurl-devel libjpeg-devel libpng-devel freetype-devel libmcrypt-devel recode-devel libicu-devel libzip-devel

  4. 进入源代码包文件夹,编译、安装:
    cd php-7.2.12/

    ./configure --prefix=/usr/local/php7 --with-config-file-scan-dir=/usr/local/php7/etc/php.d --with-config-file-path=/usr/local/php7/etc --enable-mbstring --enable-zip --enable-bcmath --enable-pcntl --enable-ftp --enable-xml --enable-shmop --enable-soap --enable-intl --with-openssl --enable-exif --enable-calendar --enable-sysvmsg --enable-sysvsem --enable-sysvshm --enable-opcache --enable-fpm --enable-session --enable-sockets --enable-mbregex --enable-wddx --with-curl --with-iconv --with-gd --with-jpeg-dir=/usr --with-png-dir=/usr --with-zlib-dir=/usr --with-freetype-dir=/usr --enable-gd-jis-conv --with-openssl --with-pdo-mysql=mysqlnd --with-gettext=/usr --with-zlib=/usr --with-bz2=/usr --with-recode=/usr --with-xmlrpc --with-mysqli=mysqlnd

    sudo make install

  5. 复制php-fpm配置文件:
    sudo cp /usr/local/php7/etc/php-fpm.conf.default /usr/local/php7/etc/php-fpm.conf

    sudo cp /usr/local/php7/etc/php-fpm.d/www.conf.default /usr/local/php7/etc/php-fpm.d/www.conf

  6. 复制php配置文件:
    sudo cp php.ini-production /usr/local/php7/etc/php.ini

  7. 为php添加环境变量,编辑 /etc/profile,文件末尾添加一行:
    PATH=/usr/local/php7/bin:/usr/local/php7/sbin:$PATH

  8. 将php添加到sudo环境变量,编辑 /etc/sudoers中的 Defaults secure_path,加上PHP路径 :
    /usr/local/php7/bin:/usr/local/php7/sbin:

  9. 使环境变量生效:
    source /etc/profile

  10. 启动PHP:
    sudo php-fpm