1、安装源
安装epel-release:yum -y install epel-release
添加remi源:rpm -Uvh http://rpms.remirepo.net/enterprise/remi-release-7.rpm
安装yum-config-manager实用程序:yum -y install yum-utils
2、安装PHP
选择对应的版本进行安装
安装PHP5.4:yum install -y php
安装PHP7.0:yum-config-manager --enable remi-php70
yum -y install php php-opcache
安装PHP7.1:yum-config-manager --enable remi-php71
yum -y install php php-opcache
安装前可使用yum search php71
搜索可安装的软件包。
完成后还需要添加PHP常用扩展:yum -y install php-mysql php-gd php-ldap php-odbc php-pear php-xml php-xmlrpc php-mbstring php-soap curl curl-devel
yum -y install php71-php-fpm.x86_64
systemctl restart php71-php-fpm #启动php
netstat -tunlp|grep 9000 #查看php启动状态
vim /etc/opt/remi/php71/php-fpm.d/www.conf
user = nginx #修改用户为nginx
group = nginx #修改组为nginx
3、nginx配置
yum install nginx #安装nginx
vim /etc/nginx/conf.d/test.conf
server {
listen 80;
#listen [::]:80;
server_name 39.105.1.170;
client_max_body_size 50m;
location / {
charset utf-8;
root /var/www;
index index.html index.htm;
}
location ~ \.php$ {
root /var/www;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /var/www$fastcgi_script_name;
include fastcgi_params;
}
}
nginx -s reload #启动nginx
在/var/www新建两个文件,一个html文件,一个php文件
test.html的内容为:
Hello World
test.php的内容为:
浏览器访问:39.105.1.170/test.html 和 39.105.1.170/test.php