linux-安装环境

安装PHP

本文将介绍如何在 CentOS 7 服务器上使用 yum 命令安装 PHP7.2

安装 PHP7.2

# 查看systemctl的所有进程
systemctl list-dependencies

安装 EPEL 软件包:
yum install epel-release -y

安装 remi 源:
# https://dl.fedoraproject.org/pub/epel/
yum install http://rpms.remirepo.net/enterprise/remi-release-7.rpm -y

安装 yum 扩展包:
yum install yum-utils -y

启用 remi 仓库:
yum-config-manager --enable remi-php72 -y
yum update -y

安装 PHP7.2
yum install php72 -y

yum list | grep redis

安装 php-fpm 和一些其他模块

yum install -y php72-php-fpm \
php72-php-gd \
php72-php-json \
php72-php-mbstring \
php72-php-mysqlnd \
php72-php-xml \
php72-php-xmlrpc \
php72-php-opcache \
php72-php-pecl-redis

输入 php72 -v 查看安装结果

php-fpm 服务

设置开机自启

systemctl enable php72-php-fpm && systemctl enable nginx
systemctl stop php72-php-fpm && systemctl stop nginx
systemctl start php72-php-fpm && systemctl start nginx
systemctl status php72-php-fpm && systemctl status nginx

常用 php-fpm 命令

# 开启服务

systemctl start php72-php-fpm

# 停止服务

systemctl stop php72-php-fpm

# 查看状态

systemctl status php72-php-fpm
通过 egrep 查询 nginx 服务器的用户和用户组:

$ egrep '^(user|group)' /etc/nginx/nginx.conf
结果示例:

user nginx;

编辑 /etc/opt/remi/php72/php-fpm.d/www.conf,修改执行 php-fpm 的权限:

vi /etc/opt/remi/php72/php-fpm.d/www.conf
设置用户和用户组为 nginx:

user = nginx
group = nginx
保存并关闭文件,重启 php-fpm 服务:

systemctl stop php72-php-fpm && systemctl start php72-php-fpm && systemctl status php72-php-fpm


路径整理
# php 安装路径
/etc/opt/remi/php72

# nginx 配置文件
/etc/nginx/nginx.conf

# nginx 默认项目路径
/usr/share/nginx/html

php安装pgsql pdp_pgsql扩展


yum search *pgsql*  -y


yum install centos-release-scl-rh -y

yum install php72-php-pgsql -y
或者
yum install rh-php72-php-pgsql -y

获取pgsql.so 扩展所在地址

find / -name *pgsql.so

php安装redis扩展

#先知道自己的php的版本 
php -v 

#在市场搜索当前版本适用的redis
yum list | grep php72-php-pecl-re* -y

#在列表挑一个redis安装  
yum install php72-php-pecl-redis -y

#安装好了之后全局搜索 redis.so文件的位置
find / -name *redis.so

#找到so的位置之后  在php.ini里开启扩展。如果不知道php.ini在哪里 可以先find / -name php.ini
extension=/opt/remi/php72/root/usr/lib64/php/modules/redis.so


#打开任意项目的phpinfo  或者  直接执行 php -m  查看已开启的扩展

修改php.ini

extension=/opt/remi/php72/root/usr/lib64/php/modules/pgsql.so
extension=/opt/remi/php72/root/usr/lib64/php/modules/pdo_pgsql.so
extension=/opt/remi/php72/root/usr/lib64/php/modules/redis.so


#开启短标签
short_open_tag = On

安装nginx

CentOS7 安装 Nginx

nginx centos7


YUM 安装
1.下载nginx包

yum install -y wget
wget http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm

2.建立nginx的yum仓库
rpm -ivh nginx-release-centos-7-0.el7.ngx.noarch.rpm


3.下载并安装nignx
yum install nginx -y

4.启动nginx服务
systemctl start nginx && systemctl enable nginx 

5.如果在浏览器中输入部署nginx环境的IP不能访问,可能是端口没有开启
firewall-cmd --zone=public --add-port=80/tcp --permanent


重启防火墙
systemctl stop firewalld   
systemctl start firewalld

命令含义:

--zone #作用域

--add-port=80/tcp #添加端口,格式为:端口/通讯协议

--permanent #永久生效,没有此参数重启后失效

编译安装nginx

源码编译安装

下载 Nginx 安装包

访问 Nginx 下载页面,这里下载固定版本:wget http://nginx.org/download/nginx-1.14.2.tar.gz。
检查是否已经YUM安装
如果已安装,使用 yum remove nginx 命令删除。

➜  ~ yum list installed | grep nginx
nginx.x86_64                           1:1.12.2-2.el7                 @epel
nginx-all-modules.noarch               1:1.12.2-2.el7                 @epel
nginx-filesystem.noarch                1:1.12.2-2.el7                 @epel
nginx-mod-http-geoip.x86_64            1:1.12.2-2.el7                 @epel
nginx-mod-http-image-filter.x86_64     1:1.12.2-2.el7                 @epel
nginx-mod-http-perl.x86_64             1:1.12.2-2.el7                 @epel
nginx-mod-http-xslt-filter.x86_64      1:1.12.2-2.el7                 @epel
nginx-mod-mail.x86_64                  1:1.12.2-2.el7                 @epel
nginx-mod-stream.x86_64                1:1.12.2-2.el7                 @epel

安装 Nginx
# 解压缩
➜  tar -xvf nginx-1.14.2.tar.gz
# 进入解压后的文件夹cd nginx-1.14.2
# 检查环境依赖,最后会提供如下的配置信息
➜  ./configure
# 编译安装
➜  make && make install
./configure 执行后提示的 nginx 配置信息:

nginx path prefix: "/usr/local/nginx"
nginx binary file: "/usr/local/nginx/sbin/nginx"
nginx modules path: "/usr/local/nginx/modules"
nginx configuration prefix: "/usr/local/nginx/conf"
nginx configuration file: "/usr/local/nginx/conf/nginx.conf"
nginx pid file: "/usr/local/nginx/logs/nginx.pid"
nginx error log file: "/usr/local/nginx/logs/error.log"
nginx http access log file: "/usr/local/nginx/logs/access.log"
nginx http client request body temporary files: "client_body_temp"
nginx http proxy temporary files: "proxy_temp"
nginx http fastcgi temporary files: "fastcgi_temp"
nginx http uwsgi temporary files: "uwsgi_temp"
nginx http scgi temporary files: "scgi_temp"
运行 Nginx
/usr/local/nginx 中包含四个主要的目录:

conf:配置文件
html:默认的 nginx 访问路径
logs:各种日志信息
sbin:二进制启动脚本
# 运行 nginx
/usr/local/nginx/sbin/nginx
# 查看运行进程
ps -ef | grep nginx

nginx( 1.18 配置ssl )

server {
    listen       80;
    #    server_name  localhost;

    #配置ssl
    listen       443 ssl;
    server_name  visit.taijisemi.com #你们的域名,如www.abc.com;
    ssl                  on;
    ssl_certificate      /etc/nginx/USSL_TBDgfz1p3/USSL_TBDgfz1p3/Nginx/public.pem; #根据实际的路径和文件名配置
    ssl_certificate_key  /etc/nginx/USSL_TBDgfz1p3/USSL_TBDgfz1p3/Nginx/private.key; #根据实际的路径和文件名配置
    ssl_session_timeout  5m;
    ssl_protocols TLSv1 TLSv1.1 TLSv1.2; #按照这个协议配
    ssl_ciphers  ECDHE-RSA-AES128-GCM-SHA256:HIGH:!aNULL:!MD5:!RC4:!DHE;#按照这个套件配
    ssl_prefer_server_ciphers   on;

    if ($server_port = 80) {
        rewrite ^(.*)$ https://$host$1 permanent;
    }

    #charset koi8-r;
    #access_log  /var/log/nginx/host.access.log  main;

    location / {
        root   /usr/share/nginx/taiji;
        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/taiji;
    }

    # 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   /usr/share/nginx/taiji;
        fastcgi_pass   127.0.0.1:9000;
        fastcgi_index  index.php;
        # fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
        # fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        # fastcgi_param  SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_param  SCRIPT_FILENAME    /var/www/html$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;
    #}
}

安装postgres 9.6


yum install https://download.postgresql.org/pub/repos/yum/reporpms/EL-7-x86_64/pgdg-redhat-repo-latest.noarch.rpm  -y

yum install postgresql96 -y

yum install postgresql96-server -y

安装postgres 9.6

https://www.postgresql.org/download/linux/redhat/

安装postgresql之后

#初始化一个数据库
/usr/pgsql-9.6/bin/postgresql96-setup initdb

#启用服务
systemctl enable postgresql-9.6

#开启服务
systemctl start postgresql-9.6

#查看服务状态
systemctl status postgresql-9.6

postgres 后期配置

pg_hba.conf文件 (或许存在多个 find / -name 寻找一下)

# TYPE  DATABASE        USER            ADDRESS                 METHOD

# "local" is for Unix domain socket connections only
#local   all             all                                     peer
local   all             all                                     ident
# IPv4 local connections:
host    all             all             127.0.0.1/32            ident
# IPv6 local connections:
host    all             all             ::1/128                 ident
# Allow replication connections from localhost, by a user with the
# replication privilege.
#local   replication     postgres                                peer
#host    replication     postgres        127.0.0.1/32            ident
#host    replication     postgres        ::1/128                 ident
host    all             all              0.0.0.0/0              md5

postgresql.conf文件

 listen_addresses = '*'

文档支持

https://segmentfault.com/u/donne/articles

results matching ""

    No results matching ""