Table of Contents
环境搭建
  web运行流程:" >  web运行流程:
 命令行运行php脚本" >  命令行运行php脚本
  apache,mysql,php安装" >  apache,mysql,php安装
  apache配置 : 访问php" >  apache配置 : 访问php
  PHP配置:" >  PHP配置:
  时区配置
  模块配置
站点配置
 单站点配置" >  单站点配置
  多站点配置" >  多站点配置
  虚拟目录设置
Home Backend Development PHP Tutorial PHP的环境搭建 的方法

PHP的环境搭建 的方法

Jul 04, 2018 pm 02:55 PM

这篇文章主要介绍了关于PHP的环境搭建 的方法,有着一定的参考价值,现在分享给大家,有需要的朋友可以参考一下

主要:

  1.  环境搭建

  2. 站点配置

  


环境搭建

  web运行流程:

1. 浏览器输入地址,回车(发送请求)
2. 根据规则找到对应web服务器。规则如下:
        首先在本机hosts文件中找对应IP
        hosts位置: 操作系统 /system32/drivers/etc/  
                 【管理员身份打开编辑器,才能保存这个文件】
        如果host没有找到,则到互联网找对应IP(DNS服务器中)
        如果还是没有找到,则终止请求,返回“找不到服务器”提示
3.    web服务器取得对应文件(就是请求的文件).如有需要对该文件进行一定的处理
4)    将文件(或执行结果)返回给浏览器(返回应答)
5)    浏览器接收文件,显示结果
Copy after login

  命令行运行php脚本

1 php安装目录/php.exe  -f    “php文件路径              #运行php文件
2 php安装目录/php.exe  -r    “php脚本代码”             #运行php代码
Copy after login

  apache,mysql,php安装

  规划软件安装目录: 如d:/amp/

  apache下载: http://www.apache.org/dyn/closer.cgi

  apache安装:同安装一般windows软件类似 【略】

  php安装: 直接解压即可使用

  mysql安装: 同安装一般windows软件类似 【略】

  apache配置 : 访问php

 配置文件中加入配置:【apache安装目录/config/httpd.conf】

# 装载PHP模块,即是PHP语言包中的一个文件LoadModule php5_module "D:/amp/php/php5apache2_4.dll"#以.php结尾的文件,找php语言模块   【方式1】
<FilesMatch "\.php$">
    SetHandler application/x-httpd-php
</FilesMatch>

#指定后缀使用php语言模块解析: 【方式2】:AddType application/x-httpd-php .php .pap .phtml
Copy after login

重启apache,可以测试访问php文件

apache配置检测命令:在cmd中运行

apache安装位置/bin/httpd.exe   -t      
#没有语法错误,显示/返回: syntax OK
Copy after login

  PHP配置:

  时区配置

   step1 : php目录/php.ini-development 复制修改为 php.ini

step 2: 打开php.ini 搜索【ctrl+f 快捷键】“timezone”

[Date]
; Defines the default timezone used by the date functions
; http://php.net/date.timezone;date.timezone =;配置时区date.timezone = PRC
Copy after login

  setp 3: apache配置文件中加入【apache安装目录/config/httpd.conf】

#php.ini所在的位置PHPIniDir "D:/amp/php"
Copy after login

  step 4: 重启apache, 使用ph脚本文件测试时间显示

  模块配置

  打开php配置文件php.ini , 搜索extension_dir 指定配置模块目录 【模块默认在php目录下的ext目录下】

; Directory in which the loadable extensions (modules) reside.
; http://php.net/extension-dir
; extension_dir = "./"
; On windows:
; extension_dir = "ext"extension_dir = "D:/amp/php/ext"
Copy after login

在php.ini中搜索 extension=, 开启mysql, pdo模块

extension=php_mysql.dll
extension=php_mysqli.dll
extension=php_pdo_mysql.dll
Copy after login

站点配置

  单站点配置

  在apache的配置文件httpd.conf中进行配置 【apache安装目录/config/httpd.conf】

  端口监听 默认是80端口 : Listen

Listen 80
Copy after login

  站点名: ServerName

ServerName   www.demo.io
Copy after login

  站点路径:DocumentRoot 目录自定义位置

 "D:/amp/www/"
< "D:/amp/www/">
  #当一个请求中没有给定请求的文件名有没有默认网页(首页)的时候,显示文件列表
    Options indexes FollowSymLinks
   #允许分布式权限配置  既站点中编写 .htaccess文件
    AllowOverride All
    Require all granted
  #设置该文件夹下的“默认网页”(首页)
    DirectoryIndex index.php index.html
</>
Copy after login

重启apache, 在站点【D:/amp/www/】目录中的文件可以同过浏览器:www.demo.io 进行访问

  多站点配置

  在apache配置文件httpd.conf中 开启多站点配置

# Virtual hosts
Include conf/extra/httpd-vhosts.conf
Copy after login

在httpd-vhosts.conf文件中配置虚拟站点 【apache目录/conf/extra/目录下】

#配置第一个站点
<VirtualHost *:80>
    #配置站点管理员的邮箱,500错误时,会在页面上提示错误信息,并列出管理员邮箱
    ServerAdmin abcx@163.com
    #站点根目录    DocumentRoot "D:/www"
    #站点绑定的域名    ServerName www.test.com
    #站点别名(一般是不带www的域名)
    ServerAlias test.com
    #错误日志的存储位置,logs目录在Apache目录下
    ErrorLog "logs/test-error.log"
    #正常访问日志的存储位置,logs目录在Apache目录下,common指日志的记录规则名称
    Customlog "logs/test-access.log" common
    #针对目录的详细配置    <Directory "D:/www">
        #允许所有访问
        #allow from all
        Require all granted
        #允许分布式权限配置(允许重写)(.htacess)
        AllowOverride All
        #表示允许显示站点目录的文件结构(不想显示则可以设置为-)
        Options +indexes
    </Directory></VirtualHost>
Copy after login

host文件中设置域名解析 【C:\Windows\System32\drivers\etc\hosts】 加入

127.0.0.0 www.test.com test.com

重启apache, 浏览器访问www.test.com

  虚拟目录设置

  如 www.test.io/demo 站点目录中存在demo目录, 可以访问

   www.test.io/Test 站点目录中不存在Test目录, 不可访问。为实现该种方式的访问

  方法: 在站点目录中,目录配置前加入: Alias /Test "D:/www/web"

<VirtualHost *:80>
    ServerName localhost
    DocumentRoot "D:/www/web"
    #虚拟目设置    alias /ww  "D:/www/web"
    <Directory "D:/www/web">
        Options indexes FollowSymLinks
        Require all granted
    </Directory>
</VirtualHost>
Copy after login

小结:

  1. 实现访问php脚本文件,包含连接数据库访问

       2. 建立站点  www.test.com

以上就是本文的全部内容,希望对大家的学习有所帮助,更多相关内容请关注PHP中文网!

相关推荐:

php源码之搭建站点实现登录页面的方法

php源码之实现单入口MVC结构的方法

The above is the detailed content of PHP的环境搭建 的方法. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Explain JSON Web Tokens (JWT) and their use case in PHP APIs. Explain JSON Web Tokens (JWT) and their use case in PHP APIs. Apr 05, 2025 am 12:04 AM

JWT is an open standard based on JSON, used to securely transmit information between parties, mainly for identity authentication and information exchange. 1. JWT consists of three parts: Header, Payload and Signature. 2. The working principle of JWT includes three steps: generating JWT, verifying JWT and parsing Payload. 3. When using JWT for authentication in PHP, JWT can be generated and verified, and user role and permission information can be included in advanced usage. 4. Common errors include signature verification failure, token expiration, and payload oversized. Debugging skills include using debugging tools and logging. 5. Performance optimization and best practices include using appropriate signature algorithms, setting validity periods reasonably,

How does session hijacking work and how can you mitigate it in PHP? How does session hijacking work and how can you mitigate it in PHP? Apr 06, 2025 am 12:02 AM

Session hijacking can be achieved through the following steps: 1. Obtain the session ID, 2. Use the session ID, 3. Keep the session active. The methods to prevent session hijacking in PHP include: 1. Use the session_regenerate_id() function to regenerate the session ID, 2. Store session data through the database, 3. Ensure that all session data is transmitted through HTTPS.

Describe the SOLID principles and how they apply to PHP development. Describe the SOLID principles and how they apply to PHP development. Apr 03, 2025 am 12:04 AM

The application of SOLID principle in PHP development includes: 1. Single responsibility principle (SRP): Each class is responsible for only one function. 2. Open and close principle (OCP): Changes are achieved through extension rather than modification. 3. Lisch's Substitution Principle (LSP): Subclasses can replace base classes without affecting program accuracy. 4. Interface isolation principle (ISP): Use fine-grained interfaces to avoid dependencies and unused methods. 5. Dependency inversion principle (DIP): High and low-level modules rely on abstraction and are implemented through dependency injection.

How to debug CLI mode in PHPStorm? How to debug CLI mode in PHPStorm? Apr 01, 2025 pm 02:57 PM

How to debug CLI mode in PHPStorm? When developing with PHPStorm, sometimes we need to debug PHP in command line interface (CLI) mode...

Framework Security Features: Protecting against vulnerabilities. Framework Security Features: Protecting against vulnerabilities. Mar 28, 2025 pm 05:11 PM

Article discusses essential security features in frameworks to protect against vulnerabilities, including input validation, authentication, and regular updates.

How to automatically set permissions of unixsocket after system restart? How to automatically set permissions of unixsocket after system restart? Mar 31, 2025 pm 11:54 PM

How to automatically set the permissions of unixsocket after the system restarts. Every time the system restarts, we need to execute the following command to modify the permissions of unixsocket: sudo...

Explain late static binding in PHP (static::). Explain late static binding in PHP (static::). Apr 03, 2025 am 12:04 AM

Static binding (static::) implements late static binding (LSB) in PHP, allowing calling classes to be referenced in static contexts rather than defining classes. 1) The parsing process is performed at runtime, 2) Look up the call class in the inheritance relationship, 3) It may bring performance overhead.

See all articles