2019独角兽企业重金招聘Python工程师标准>>>
Centos7.4 安装nginx和php-fpm:
1. 安装nginx:
rpm -ivh http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm
yum install -y nginx
systemctl restart nginx
2. 配置php-fpm
项目目录在/root/html下面,需要更改nginx默认目录
查看nginx配置文件:
nginx -t
server {
listen 80 default_server;
listen [::]:80 default_server;
server_name _;
root /root/html;
#修改所有root对应的目录为/var/www/html
location ~ \.php$ {
root /root/html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
#fastcgi_param SCRIPT_FILENAME /root/html/$fastcgi_script_name;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
重新加载nginx配置:
nginx -s reload
3. 安装php-fpm:
用yum search all php-fpm安装自己需要的版本
yum install -y php-fpm
这是PHP5的版本,要安装高版本的php-fpm,需要按如下步骤:
1).安装epel-release
通过命令:
yum -y install epel-release
2).安装PHP7
终端再次运行如下命令:
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
3). yum查看
yum search php70w-fpm #PHP7.0
yum search php71w-fpm #PHP7.1
yum search php72w-fpm #PHP7.2
4). 安装PHP 7.0、7.1的yum源,然后再执行:
安装php 7.0以及扩展:
yum install php70w php70w-fpm php70w-cli php70w-common php70w-devel php70w-gd php70w-pdo php70w-mysql php70w-mbstring php70w-bcmath php70w-xml php70w-pecl-redis php70w-process php70w-intl php70w-xmlrpc php70w-soap php70w-ldap php70w-opcache
安装php 7.1以及扩展:
yum install php71w php71w-fpm php71w-cli php71w-common php71w-devel php71w-gd php71w-pdo php71w-mysql php71w-mbstring php71w-bcmath php71w-xml php71w-pecl-redis php71w-process php71w-intl php71w-xmlrpc php71w-soap php71w-ldap php71w-opcache
安装php 7.2以及扩展:
yum install -y php72w php72w-fpm php72w-cli php72w-common php72w-devel php72w-gd php72w-pdo php72w-mysql php72w-mbstring php72w-bcmath php72w-xml php72w-pecl-redis php72w-process php72w-intl php72w-xmlrpc php72w-soap php72w-ldap php72w-opcache
5). 开启服务
systemctl start php-fpm
6). 开机开启服务
systemctl enable php-fpm
4. 写一个PHP脚本phpinfo.php放到服务器web根目录下:
在浏览器输入:ip
http://192.168.1.108/phpinfo.php