环境搭建

docker pull centos:centos7.9.2009


docker run -itd -p 9092:8080 centos:centos7.9.2009 bash


docker exec -it 95ad9c506ad9 bash

#安装必须软件
yum install -y gcc gcc-c++ make epel-release httpd

#PHP高版本源yum
rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm

yum install -y mod_php72w.x86_64 php72w-cli.x86_64 php72w-common.x86_64 php72w-mbstring.x86_64 php72w-common.x86_64 php72w-ldap.x86_64  php72w-xml.x86_64 php72w-xmlrpc.x86_64 php72w-mysql.x86_64  php72w-pdo.x86_64  php72w-pear.noarch  php72w-process.x86_64  php72w-gd.x86_64  php72w-devel.x86_64 

yum install -y vim

# 启动apache
apachectl

# php配置
php i | grep php.ini

# composer 安装
php -r "copy('https://install.phpcomposer.com/installer', 'composer-setup.php');"

php composer-setup.php

mv composer.phar /usr/local/bin/composer

# 更改composer源
composer config -g repo.packagist composer https://mirrors.aliyun.com/composer/

composer selfupdate

composer create-project topthink/think tp

自建框架

/* /var/www/html/index.php*/

<?php
use controller\SiteController;

defined('APP_PATH') or define('APP_PATH',__DIR__);


try {
        $route = isset($_GET['r']) ? $_GET['r'] : 'site/index';
//      $pathinfo = explode('/',str_replace('.html','',$_SERVER['PATH_INFO']));
        $arr = explode('/',$route);
        $controller = 'controller\\' . ucfirst($arr[0]) . 'Controller';
        $method = $arr[1];

//      $c = new $controller();
//      $c->$method();

        call_user_func_array(array($controller, $method), array());
} catch (\Exception $e) {
        echo $e->getMessage();
}


function __autoload($classname) {
        $filename = APP_PATH . DIRECTORY_SEPARATOR . str_replace('\\',DIRECTORY_SEPARATOR,$classname) . '.php';
        if(!file_exists($filename)) {
                throw new \RuntimeException('class file not found'.$filename);
        }
        include_once($filename);
}

/* ///var/www/html/controller/SiteController.php */

<?php
namespace controller;

class SiteController{
        public function index() {
                echo 12345;
        }

        public function test() {
                echo 'test';
        }

        /**
         * @param string $anme
         *
         * @return array
         */
        public function doc($name) {
                return array($name);
        }
}

Scroll to Top