【Linux系列】Centos 7安裝 PHP(四)

目的


爲了下面的Laravel部署,本篇開始安裝PHP。php

設置PHP源

查看Centos源是否有PHP。html

yum list php*

1

進一步查看PHP的版本。mysql

yum info php.x86_64

2

上圖看出自帶的PHP源版本過低,須要更高版本的。linux

設置高版本的PHP源。nginx

rpm -ivh https://mirror.webtatic.com/yum/el7/epel-release.rpm
rpm -ivh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm
yum list php* #更新源並查看如今的PHP源

3

如今已有php72版本,安裝。web

yum install -y php72w-fpm  php72w-fpm php72w-cli.x86_64 php72w-common.x86_64 php72w.x86_64 php72w-dba.x86_64 php72w-devel.x86_64 php72w-embedded.x86_64 php72w-enchant.x86_64 php72w-gd.x86_64 php72w-imap.x86_64 php72w-interbase.x86_64 php72w-intl.x86_64 php72w-ldap.x86_64 php72w-mbstring.x86_64 php72w-mysqlnd.x86_64  php72w-odbc.x86_64 php72w-opcache.x86_64 php72w-pdo.x86_64 php72w-pdo_dblib.x86_64 php72w-soap.x86_64 php72w-xml.x86_64 php72w-xmlrpc.x86_64 php72w-mbstring.x86_64 php72w-mcrypt.x86_64 php-posix

安裝成功後,查看phpsql

php -v

4

下面來新建一個網站站點。php7

service php-fpm start # 啓動php
systemctl enable php-fpm # 設置開機啓動項
ps -ef | grep php # 查看是否正常啓動

5

設置SELinuxphp-fpm

vi /etc/selinux/config
SELINUX=permissive

重啓虛擬機,不設置SELinux,nginx訪問php-fpm會有權限問題。網站

mkdir -p /var/www/Test
cd /var/www/Test   
vi index.php

index.php

<?php
    phpinfo();
?>

nginx站點config配置

cd /etc/nginx/conf.d
vi devtest.plat.goods
server {
   listen       80;
   server_name  devtest.plat.goods;
   root "/var/www/Test";

   index index.html index.htm index.php;

   location ~ (.+\.php)(.*)$ {

        fastcgi_split_path_info ^(.+\.php)(.+)$;
        fastcgi_pass unix:/var/run/php-fpm/php7-fpm.sock;   #用unix套接字通信
        fastcgi_index index.php;
        include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_param PATH_INFO $fastcgi_path_info;

        fastcgi_intercept_errors off;
        fastcgi_buffer_size 16k;
        fastcgi_buffers 4 16k;
        fastcgi_connect_timeout 300;
        fastcgi_send_timeout 300;
        fastcgi_read_timeout 300;
   }
}

配置php-fpm

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

listen = /var/run/php-fpm/php7-fpm.sock 
listen.owner = nginx
listen.group = nginx
listen.mode = 0660

6

service php-fpm restart 
service nginx reload
service nginx status

7

物理主機訪問虛擬機站點,須要配置物理機的hosts
C:\Windows\System32\drivers\etc\hosts
192.168.10.18 devtest.plat.goods

訪問 http://devtest.plat.goods/index.php
8

相關文章
相關標籤/搜索