Linux系统配置php环境

5 篇文章 0 订阅

本文介绍在Linux(CentOS 7.6 64位)下搭建nginx + php + mysql 开发环境。

搭建nginx服务器

1.安装nginx

登录服务器之后,输入

yum install -y nginx

其中-y的含义为当安装过程提示选择全部为"yes"。

这时会发现命令走不通
提示:No package nginx available.

原因是缺少nginx.repo文件。需要在/etc/yum.repos.d/文件目录下创建nginx.repo

[nginx]
 
name=nginx repo
 
baseurl=http://nginx.org/packages/OS/OSRELEASE/$basearch/
 
gpgcheck=0
 
enabled=1

注意:上述下载链接中OSRELEASE应替换为系统的版本5,6或“7”
下面是查看centos版本的方式:

cat /etc/centos-release

系统为7.6.1810版本。
在这里插入图片描述
上述代码应为:
baseurl=http://nginx.org/packages/OS/7/$basearch/

这时候用yum install -y nginx就可以安装成功。

用yum info nginx命令可查看nginx的版本。

在这里插入图片描述

此时nginx服务器就搭建好了.
执行命令启动服务器

systemctl start nginx

执行以下命令,设置 Nginx 为开机自启动。

systemctl enable nginx 

用浏览器访问公网地址,就会出现一下界面
在这里插入图片描述

编辑nginx.conf文件

vim /etc/nginx/nginx.conf

找到 server{…},并将 server 大括号中相应的配置信息替换为如下内容。
用于取消对 IPv6 地址的监听,同时配置 Nginx,实现与 PHP 的联动。若 nginx.conf 文件中未找到 server{…},请在 include /etc/nginx/conf.d/*conf;上方添加如下内容。

server {
 listen       80;
 root   /usr/share/nginx/html;
 server_name  localhost;
 #charset koi8-r;
 #access_log  /var/log/nginx/log/host.access.log  main;
 #
 location / {
       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;
 }
 #pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
 #
 location ~ .php$ {
   fastcgi_pass   127.0.0.1:9000;
   fastcgi_index  index.php;
   fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
   include        fastcgi_params;
 }
}

安装mariadb

1.查看是否安装

rpm -qa | grep -i mariadb

若已安装为避免安装版本不同造成冲突,请执行yum -y remove 命令移除已安装的 MariaDB
[root@VM_0_15_centos ~]# rpm -qa | grep -i mariadb
mariadb-libs-5.5.64-1.el7.x86_64
[root@VM_0_15_centos ~]# yum -y remove mariadb-libs-5.5.64-1.el7.x86_64

执行以下命令,在 /etc/yum.repos.d/ 下创建 MariaDB.repo 文件

vi /etc/yum.repos.d/MariaDB.repo

写下以下内容

# MariaDB 10.4 CentOS repository list - created 2019-11-05 11:56 UTC
# http://downloads.mariadb.org/mariadb/repositories/
[mariadb]
name = MariaDB
baseurl = http://yum.mariadb.org/10.4/centos7-amd64
gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB
gpgcheck=1

执行以下命令,安装 MariaDB

yum -y install MariaDB-client MariaDB-server

执行以下命令,启动 MariaDB 服务

systemctl start mariadb

执行以下命令,设置 MariaDB 为开机自启动。

systemctl enable mariadb

执行以下命令,验证 MariaDB 是否安装成功。

mysql

安装php

依次执行以下命令,更新 yum 中 PHP 的软件源。

rpm -Uvh https://mirrors.cloud.tencent.com/epel/epel-release-latest-7.noarch.rpm
rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm

执行以下命令,安装 PHP 7.2 所需要的包。

yum -y install mod_php72w.x86_64 php72w-cli.x86_64 php72w-common.x86_64 php72w-mysqlnd php72w-fpm.x86_64

执行以下命令,启动 PHP-FPM 服务。

systemctl start php-fpm

执行以下命令,设置 PHP-FPM 服务为开机自启动。

systemctl enable php-fpm

验证环境配置

执行以下命令,创建测试文件

echo "<?php phpinfo(); ?>" >> /usr/share/nginx/html/index.php

执行以下命令,重启 Nginx 服务。
systemctl restart nginx

访问配置文件

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值