centos7 安装 nginx php7

1.安装epel源

yum install epel-release

2.安装nginx

yum install nginx

3.add php7 repository

rpm -Uvh https://mirror.webtatic.com/yum/e17/webtatic-release.rpm

4.安装php7

根据需要添加删除

yum install php70w-fpm php70w-cli php70w-gd php70w-mcrypt php70w-mysql php70w-pear php70w-xml php70w-mbstring php70w-pdo php70w-json php70w-pecl-apcu php70w-pecl-apcu-devel

5配置PHP7

vi /etc/php-fpm.d/www.conf

修改

user = nginx

group = nginx

设置session

mkdir -p /var/lib/php/session

chown nginx:nginx -R /var/lib/php/session/

设置自动启动

sudo systemctl start php-fpm

sudo systemctl start nginx

sudo systemctl enable php-fpm

sudo systemctl enable nginx

6.安装MariaDB

yum install mariadb mariadb-server

自启动&配置

systemctl start mariadb

systemctl enable mariadb

mysql_secure_installation

7.配置nginx

vi /etc/nginx/conf.d/default.conf

添加

server {
    listen       80;
    server_name  server_domain_name_or_IP;

    # note that these lines are originally from the "location /" block
    root   /usr/share/nginx/html;
    index index.php index.html index.htm;

    location / {
        try_files $uri $uri/ =404;
    }
    error_page 404 /404.html;
    error_page 500 502 503 504 /50x.html;
    location = /50x.html {
        root /usr/share/nginx/html;
    }

    location ~ \.php$ {
        try_files $uri =404;
        #fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock;
        fastcgi_pass 127.0.0.1:9000;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include fastcgi_params;
    }
}

 

测试

 

发表回复

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