centos7 RPM 安装nginx+php7.4环境

1.安装nginx

#1.下载rpm包
wget https://nginx.org/packages/centos/7/x86_64/RPMS/nginx-1.20.2-1.el7.ngx.x86_64.rpm
#2.安装
rpm -ivh nginx-1.20.2-1.el7.ngx.x86_64.rpm
#3.启动
systemctl start nginx
#4.加入开机启动
systemctl enable nginx
#5.查找nginx的路径
find / -name nginx

2.安装php7.4

#1.添加第三方rpm源
yum install http://rpms.remirepo.net/enterprise/remi-release-7.rpm
#2.安装 这里是安装php相关的拓展模块,可以根据自己的需要进行增删,
#下面列出的模块,除了redis和swoole外,其他基本都是必须模块
yum install -y php74-php-fpm php74-php-cli php74-php-bcmath php74-php-gd php74-php-json  php74-php-mbstring php74-php-mcrypt php74-php-mysqlnd php74-php-opcache php74-php-pdo php74-php-pecl-crypto php74-php-pecl-mcrypt php74-php-pecl-geoip php74-php-recode php74-php-snmp php74-php-soap php74-php-xml php74-php-imagick php74-php-pecl-zip  php74-php-redis php74-php-swoole

#3.启动
systemctl start php74-php-fpm
#4.添加开机启动
systemctl enable php74-php-fpm
#5.查看版本
cp /usr/bin/php74 /usr/bin/php #如果不复制的话,所有的php 替换成php74
chmod +x /usr/bin/php #文件给与执行权限
php -v
#6.查看已安装模块
php -m
#7.查看配置信息(相当于phpinfo)
php -i

#8.编辑php-fpm的配置 一般来说php-fpm的配置文件都是www.conf,如果不知道文件路径,可以find以下
find / -name www.conf
#查找的结果
/etc/opt/remi/php74/php-fpm.d/www.conf
vim /etc/opt/remi/php74/php-fpm.d/www.conf
#查找到user 和 group 修改为 nginx (这里是nginx.conf中的user参数,不知道的话 在/etc/nginx/nginx.conf中找一下)
#将listen_mode 取消注释,并将权限修改为0777
#然后保存,重启php-fpm
结果如下
; Per pool prefix
; It only applies on the following directives:
; - 'access.log'
; - 'slowlog'
; - 'listen' (unixsocket)
; - 'chroot'
; - 'chdir'
; - 'php_values'
; - 'php_admin_values'
; When not set, the global prefix (or @php_fpm_prefix@) applies instead.
; Note: This directive can also be relative to the global prefix.
; Default Value: none
;prefix = /path/to/pools/$pool

; Unix user/group of processes
; Note: The user is mandatory. If the group is not set, the default user's group
;       will be used.
; RPM: apache user chosen to provide access to the same directories as httpd
user = nginx
; RPM: Keep a group allowed to write in log dir.
group = nginx

; The address on which to accept FastCGI requests.
; Valid syntaxes are:
;   'ip.add.re.ss:port'    - to listen on a TCP socket to a specific IPv4 address on
;                            a specific port;
;   '[ip:6:addr:ess]:port' - to listen on a TCP socket to a specific IPv6 address on
;                            a specific port;
;   'port'                 - to listen on a TCP socket to all addresses
;                            (IPv6 and IPv4-mapped) on a specific port;
;   '/path/to/unix/socket' - to listen on a unix socket.
; Note: This value is mandatory.
listen = 127.0.0.1:9000

; Set listen(2) backlog.
; Default Value: 511
;listen.backlog = 511

; Set permissions for unix socket, if one is used. In Linux, read/write
; permissions must be set in order to allow connections from a web server.
; Default Values: user and group are set as the running user
;                 mode is set to 0660
;listen.owner = nobody
;listen.group = nobody
listen.mode = 0777

3.修改nginx的default.conf

vim /etc/nginx/conf.d/default.conf
#修改结果如下
server {
    listen       80;
    server_name  localhost;

    #access_log  /var/log/nginx/host.access.log  main;

    location / {
        root   /usr/share/nginx/html;
        index  index.php index.html index.htm;
    }

    #error_page  404              /404.html;

    # redirect server error pages to the static page /50x.html
    #
    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   /usr/share/nginx/html;
    }

    # proxy the PHP scripts to Apache listening on 127.0.0.1:80
    #
    #location ~ \.php$ {
    #    proxy_pass   http://127.0.0.1;
    #}

    # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
    #
    #location ~ \.php$ {
    #    root           html;
        fastcgi_pass   127.0.0.1:9000;
        fastcgi_index  index.php;
        fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
        include        fastcgi_params;
    #}

    # deny access to .htaccess files, if Apache's document root
    # concurs with nginx's one
    #
    #location ~ /\.ht {
    #    deny  all;
    #}
}

修改完成后重启nginx,然后在/usr/share/nginx/html下创建一个index.php的文件,里面加入echo phpinfo()的代码,操作如下

touch /usr/share/nginx/html/index.php
vim /usr/share/nginx/html.php
#输入如下内容
<?php 
echo phpinfo();

然后在浏览器中输入服务器ip,就能查看服务器的php的配置信息。到此centos7的nginx+php7.4的安装,如果需要安装数据库,请查看centos安装apache+php7.4+mysql的环境中的mariadb部分。
剩下的就是针对不同的框架做不同的解析。

如果程序部署之后,打开报以下错误:

session_start(): open(/var/opt/remi/php74/lib/php/session/sess_pql5ks4ognp0scd9lkoriedi9m, O_RDWR) failed: Permission denied (13)

请进入到/var/opt/remi/php74/lib/php/,将session目录用户和组切换到nginx/apache ,根据你的当前的web服务使用的用户和组为准,并且给session目录可执行(+x)的权限

你可能感兴趣的:(LINUX,nginx,php,运维)