搭建服务器(2)

                                      搭建服务器(2)

   1.安装GCC(GNU编译器集)

   GCC即GNU编译器集,是一个GNU项目开发的支持多种编程语言。最小化安装的CentOS没有默认安装。运行下面命令安装GCC编译器。

   yum install gcc

   gcc --version(检验版本)

   2.安装Apache HTTP服务器

       不管你因为什么原因使用服务器,大部分情况你都需要一个Http服务器运行网站、多媒体、用户端脚本和很多其他的东西。

  yum install http(我选择默认端口)

可以配置端口:到配置文件中修改你想要的端口。

   允许http服务通过防火墙(永久)

    firewall-cmd --add-service=http

    firewall-cmd --permanent --add-port=你修改的端口/tcp

    firewall-cmd  --reload

    systemctl restart httpd.service (启动服务)

    注:可以将修改http使用ip4协议

          将配置文件中的修改配置文件中的 Listen 0.0.0.0:端口号

  3.安装php

       php是用于web基础服务器脚本语言。它也经常被用于通用编程语言。(本项目中php+Apache+mysql)

        yum install php

        安装php组件,使其支持数据库

          yum install php-mysql php-gd libjeg* php-ldap php-odbc php-pear php-xml php-xmlrpc php-mbstring php-bcmath php-mhash

       安装完,确认apache服务以便在web浏览器中渲染。

        systemctl restart httpd.service

        创建下面文件,检测php是否工作。

          到/var/www/html/

          创建文件phpinfo.php写入<?php phpinfo(); ?>

          测试 php /var/www/html/phpinfo.php

   4.安装MariaDB数据库

    MariaDB是MySQL的一个分支。RHEL以及它的衍生版已经从MySQL迁移到MariaDB.只是一个主流的数据库管理系统,主要原因是MySOL被oracle收购,已经不是开源了,大家都应该选择开源,支持开源。

    yum install mariadb-server mariadb

    设置为随机启动

     systemctl start mariadb.service

     systemctl enable mariadb.service

     允许matiadb服务通过防火墙(不支持开启,不安全)

     firewall-cmd --add-service=mysql

     配置mysql执行

      /usr/bin/mysql_secure_installation

     加入密码,一直y就可以

     systemctl restart mariadb.service #重启数据库

 后续配置工作:关闭SELINUX

                    1.临时关闭 setenforce 0

                       临时启用 setenforce 1

                    2.永久编译

                       vi /etc/selinux/config

                        #SELINUX=enforcing #注释掉

                        #SELINUXTYPE=targeted #注释掉

                        SELINUX=disabled #增加

                         保存,重启机器

                  Apache相关配置

                       vi  /etc/httpd/conf/httpd.conf 编辑文件

                       Options Indexes FollowSymLinks  修改为Options Includes ExecCGI  FollowSymLinks(允许服务器执行CGI及SSI,禁止列出目录)

                       #AddHandler cgi-script .cgi   #修改为:AddHandler cgi-script .cgi .pl(允许拓展名为pl的脚本)

                       AllowOverride None #修改为 AllowOverride All(允许.htaccess)

                       #Options Indexes FollowSymLinks #修改为Options FollowSymLinks(不再浏览器中显示树状目录结构)

                        DiretoryIndex index.html #修改为:DirectoryIndex  index.html index.htm Default.html Default.htm index.php(设置默认首页文件,添加index.php)

                        MaxKeepAliveRequests 500 #添加同时连接数500

                       保存退出

                        systemctl restart httpd.service #重启apache

                        rm -f /etc/httpd/conf.d/welcome.conf #删除默认测试页

                     php配置

                        vi /etc/php.ini

                        data.timezone =PRC #把前面的分号去掉,改为date.timezone = PRC

                        其中php有禁用函数,如果某些程序需要用到这个函数,需要取消禁用

                        expose_php = Off#禁止显示版本信息 

                        short_open_tag = ON #支持php短标签

                         open_basedir = .:/tmp/  #设置表示允许访问当前目录(即PHP脚本文件所在之目录)和/tmp/目录,可以防止php木马跨站,如果改了之后安装程序有问题(例如:织梦内容管理系统),可以注销此行,或者直接写上程序的目录/data/www.osyunwei.com/:/tmp/

                         systemctl restart mariadb.service #重启MariaDB

                         systemctl restart httpd.service #重启apache

                       测试成功!!!

                       

  

    

The future's not set,there is no fate but what we make for ourselves.
原文地址:https://www.cnblogs.com/wang1994/p/4951202.html