惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

MyScale Blog
MyScale Blog
C
CXSECURITY Database RSS Feed - CXSecurity.com
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
阮一峰的网络日志
阮一峰的网络日志
罗磊的独立博客
博客园 - 叶小钗
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
美团技术团队
酷 壳 – CoolShell
酷 壳 – CoolShell
雷峰网
雷峰网
宝玉的分享
宝玉的分享
大猫的无限游戏
大猫的无限游戏
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
Last Week in AI
Last Week in AI
爱范儿
爱范儿
小众软件
小众软件
K
Kaspersky official blog
P
Proofpoint News Feed
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
博客园 - Franky
V
Vulnerabilities – Threatpost
博客园_首页
Microsoft Security Blog
Microsoft Security Blog
C
Cybersecurity and Infrastructure Security Agency CISA
V
V2EX
C
Check Point Blog
S
Schneier on Security
P
Palo Alto Networks Blog
IT之家
IT之家
GbyAI
GbyAI
T
Threat Research - Cisco Blogs
Hugging Face - Blog
Hugging Face - Blog
D
Darknet – Hacking Tools, Hacker News & Cyber Security
Apple Machine Learning Research
Apple Machine Learning Research
C
Cyber Attacks, Cyber Crime and Cyber Security
T
Tailwind CSS Blog
Project Zero
Project Zero
Y
Y Combinator Blog
V
Visual Studio Blog
Simon Willison's Weblog
Simon Willison's Weblog
T
Threatpost
Scott Helme
Scott Helme
L
LINUX DO - 热门话题
S
Securelist
C
CERT Recently Published Vulnerability Notes
A
Arctic Wolf
M
MIT News - Artificial intelligence
人人都是产品经理
人人都是产品经理

博客园 - sekihin

【SQLSERVER】备份还原除当前数据库~之外的其他数据库的bak备份 【前端】常用VsCode插件 React席哪个能优化 20 GitHub 仓库帮助你成为 React专家 Export a named export for each HTTP method instead.(Next.js 15) Error occurred prerendering page "/_not-found".(Next.js 15) Error: Attempted to call generateViewport() from the server (Next.js 15) [cause]: TypeError: e_.createContext is not a function (Next.js 15) Cursor - AI代码编辑器的使用指南 Next.js项目中.prettierrc.json的配置 Next.js项目中.eslintrc.js的配置 nvm: Node Version Manager NestJS 部署Apache - sekihin NestJS导出API文档 ChatGPT plugins Obisidian plugins Build nest.js by tsconfig.json Data Transfer Objects (DTOs) in NestJS TypeError: stringWidth is not a function
PHP slim 部署Apache
sekihin · 2024-12-18 · via 博客园 - sekihin

Step 1: Install XAMPP

XAMPP 是一个集成了 Apache 服务器、MySQL 数据库和 PHP 的开放源代码软件包。

Step 2: Configure the Apache

打开Apache的配置文件httpd.conf,有效化 Apache Rewrite (mod_rewrite) 模块。
去掉#,#代表注释

LoadModule rewrite_module modules/mod_rewrite.so
LoadModule headers_module modules/mod_headers.so

允许.htaccess文件中的指令覆盖主配置文件中的设置。
允许所有主机访问。

《注意》apache的配置文件httpd.conf中,httpd-slim.conf要正确引用,否则Apache服务器会返回Not found 404错误

《注意》路径一定要包括public,否则Apache服务器会返回Forbidden 403错误

Alias "/slim" "C:/xamapp/htdocs/[my-app-name]/public"
<Directory "C:/xamapp/htdocs/[my-app-name]/public">
    Options -Indexes +FollowSymLinks
    AllowOverride All
    Require all granted
    DirectoryIndex index.php
</Directory>

Step 3: Install Composer

 下载 Composer并安装。
更改为阿里源。

composer config -g repo.packagist composer https://mirrors.aliyun.com/composer/

Step 4: Install Slim

composer require --with-all-dependencies slim/slim:"4.*" slim/psr7 selective/basepath


创建Slim项目。

Composer create-project slim/slim-skeleton [my-app-name]

Step 5: Create .htaccess File

File: public/.htaccess

Options -Indexes
IndexIgnore *

<Files ~ "\.(env|json|config.js|md|gitignore|gitattributes|lock|log)$">
    Order allow,deny
    Deny from all
</Files>

<IfModule mod_headers.c>
    Header set X-Robots-Tag "noindex,nofollow,noarchive,nosnippet"
</ifModule>

<ifModule mod_rewrite.c>
    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ $1 [R=200,L]

    RewriteRule .* - [env=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
</ifModule>

Step 6: Hello World

File: public/index.php

<?php
use Psr\Http\Message\ResponseInterface as Response;
use Psr\Http\Message\ServerRequestInterface as Request;
use Slim\Factory\AppFactory;

require __DIR__ . '/../vendor/autoload.php';

$app = AppFactory::create();

$app->get('/', function (Request $request, Response $response, $args) {
    $response->getBody()->write("Hello world!");
    return $response;
});

$app->run();

Step 7: Start Slim Application

systemctl restart apache2
php -S localhost:8080 -t public public/index.php