Linux environment to configure Nginx + PHP 7

Nginx configuration

  • system update
sudo yum -y install epel-release
sudo yum update -y
  • Using yum install nginx, and set the boot
yum install -y nginx
systemctl start nginx
systemctl enable nginx
  • View nginx version
nginx -v
  • View nginx running state
ps -ef | grep nginx

PHP Configuration

  • Yum install source
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
  • Install PHP and components
yum -y install php72w php72w-cli php72w-common php72w-devel php72w-embedded php72w-fpm php72w-gd php72w-mbstring php72w-mysqlnd php72w-opcache php72w-pdo php72w-xml php72w-ldap
  • PHP start and set to boot
systemctl start php-fpm
systemctl enable php-fpm
  • See the PHP version and operating state
php -v
  • View PHP running state
ps -ef | grep php-fpm

Nginx configuration modification

vim /etc/nginx/conf.d/default.conf
找到第一个location中的这一行
    index  index.html index.htm;
    修改为:
    index  index.php index.html index.htm; #添加index.php
        
    把FastCGI server这行下面的location的注释去掉,并修改成下面这样子
     # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
     #
     location ~ \.php$ {
         root            /usr/share/nginx/html;  #网站根目录
         fastcgi_pass   127.0.0.1:9000;
         fastcgi_index  index.php;
         fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
         include        fastcgi_params;
     }
service nginx restart   #重启nginx
service php-fpm start   #开启php-fpm
  • New index.php file in the root of the site
vim /usr/share/nginx/html/index.php
<?php
phpinfo();
?>
  • Enter the virtual machine ip in your browser, you can already see the information of the phpinfo

Guess you like

Origin www.cnblogs.com/nethrd/p/10951088.html