Table of Contents
1.1  PHP环境搭建
1.2  PHP开发环境的关键配置信息
1.3  解决PHP的常见配置问题
解决Apache服务器端口冲突" >1.3.1  解决Apache服务器端口冲突
Home Backend Development PHP Tutorial felayman-PHP环境搭建

felayman-PHP环境搭建

Jun 13, 2016 am 11:55 AM
apache mysql nbsp php

felayman-----PHP环境搭建

PHP是一种服务器端的嵌入式脚本语言,是一种服务器端、跨平台、面向对象、HTML嵌入式的脚本语言。本章将向读者介绍PHP开发环境搭建,常用的配置问题和解决方案。通过本章的学习,读者能够学到以下内容。

 

更换验证码

: Windows——AppserV集成安装包搭建PHP环境

:  Linux——XAMPP集成安装包搭建PHP环境

:  PHP开发环境的关键配置信息

:  解决PHP的常见配置问题

1.1  PHP环境搭建

1.1.1  AppServWindowsPHP集成化安装包

AppServApachePHPMySQLphpMyAdmin等服务器软件和工具安装配置完成后打包处理。开发人员只要到网站上下载该软件,然后安装,即可完成PHP开发环境的快速搭建。非常适合初学者使用。

注意:在使用AppServ搭建PHP开发环境时,必须确保在系统中没有安装ApachePHPMySQL。否则,要先将这些软件卸载,然后应用AppServ

下面讲解AppServ集成化安装包搭建PHP开发环境的具体操作步骤:

1)双击AppServ-win32-2.5.10.exe文件,打开如图1.1所示的AppServ启动页面。


2)单击图1.1中的Next按钮,打开如图1.2所示的AppServ安装协议页面。

3)单击图1.2中的I Agree按钮打开如图1.3所示的页面。设置AppServ的安装路径(默认安装路径一般为:E:\AppServ),AppServ安装完成后ApacheMySQLPHP都将以子目录的形式存储到该目录下。


4)单击图1.3中的Next按钮打开如图1.4所示的页面。选择要安装的程序和组件(默认为全选)。



注意:在图1.4的操作步骤中,如果本机中已经安装MySQL数据库,那么在这里可以不勾选MySQL Database选项,仍使用本机已经存在的MySQL数据库。

5)在图1.4中单击Next按钮,打开如图1.5所示的页面。填写计算机名称,添加邮箱地址,设置Apache的端口号,默认为80端口。


技巧:Apache服务器端口号的设置,直接关系到Apache服务器是否能够正常启动。如果本机中的80端口被IIS或者迅雷占用,那么这里就需要修改Apache的端口号,或者将IIS、迅雷的端口号修改,才能完成Apache服务器的配置。如果出现端口冲突,那么将导致安装失败,Apache服务不能启动。

6)单击图1.5中的Next按钮,打开如图1.6所示的页面。设置MySQL数据库root用户的登录密码及字符集。

技巧:MySQL数据库字符集的设置,可以选择UTF-8GBK或者GB2312。这里将字符集设置为“UTF-8 Unicode”,表示MySQL数据库的字符集将采用UTF8编码。


注意:对于在图1.6中设置的MySQL数据库root用户的密码必须牢记,因为程序在连接数据库时必须使用这个密码。

的程序时,要修改连接数据库的密码。如果忘记安装时设置密码,最直接有效的解决方式是重新安装AppServ

7)单击图1.6中的Install按钮开始安装,如图1.7所示。


8)安装完成后可以在开始菜单的AppServ相关操作列表中启动ApacheMySQL服务,如图1.8所示。


1.2  PHP开发环境的关键配置信息

前面介绍了PHP开发环境的配置方法,除了安装步骤本身之外,PHP与服务器的配置也是十分重要的。下面将主要介绍PHPApache服务器的配置。

1.2.1  Apache服务器的基本配置

Apache服务器的设置文件Linux操作系统中位于/usr/local/apache/conf/(在Windows操作系统中位于“/etc/httpd/conf”)目录下,基本上使用以下3个配置文件来配置Apache服务器的行为。

? access.conf:用于配置服务器的访问权限,控制不同用户和计算机的访问限制

? httpd.conf:用于设置服务器启动的基本环境

? srm.conf:主要用于作文件资源上的设定。

技巧:http.confApache服务器的配置文件,其常用的配置包括:Apache服务器的端口号、服务器的访问路径和伪静态的设置。

ServerName localhost:80

DocumentRoot "/xampp/htdocs"

LoadModule rewrite_module modules/mod_rewrite.so

1.2.2  PHP.INI文件的基本配置

php.ini文件是PHP在启动时自动读取的配置文件。php.ini是一个ASCLL文本文件,分为多个部分,每一部分包括相关的参数。每一部分的名称位于最前面的方括号内,接着是名称对数字,每一名称都独占一行。使用规则PHP代码,对参数名称非常敏感,不能包含有空格,但是参数可以是数字,字符串或者布尔逻辑数。分号位于每一行的开始,其作为指定标记,这就使选择使用或者不使用PHP的这些特性变得很方便,而无需通过删除该行来实现。对某特性进行注释(即,添加分号),则该行将不会被编译执行。每次修改完php.ini文件,必须重新启动Apache服务器,以使新的设置生效。

技巧:php.iniPHP的配置文件,用于加载各种函数库、设置错误级别和设置服务器的时间等等。在Linux操作系统中,php.ini存储于/opt/lampp/etc/php.ini 文件夹下,而在Windwos操作系统中php.ini存储于系统盘的windows文件下。php.ini文件的基本配置如表1.1所示。

1.1                php.ini文件的基本配置

参数

说明

默认值

error_reporting

设置错误处理的级别。推荐值为E_ALL & ~E_NOTICE & ~E_STRICT,显示所有错误信息,除了提醒和编码标准化警告。

E_ALL & ~E_NOTICE & ~E_STRICT

register_globals

通常情况下可以将此变量设置为Off,这样可以对通过表单进行的脚本攻击提供更为安全的防范措施

register_globals = On

include_path

设置PHP的搜索路径,这一参数可以接收系列的目录。当PHP遇到没有路径的文件提示时,它将会自动检测这些目录,需要注意的是,当某些选项允许多个值,应使用系统列表分隔符,在Windows下使用分号“;”,在Linux下使用冒号“:”

; UNIX: "/path1:/path2"

;include_path = ".:/php/includes"

; Windows: "\path1;\path2"

;include_path = ".;c:\php\includes"

extension_dir

指定PHP的动态连接扩展库的目录

“\ext”目录下

extension

指定PHP启动时所加载的动态连接扩展库。PHP的常用扩展库及其说明请参见表1.2

PHP的常用扩展库在初次安装配置后均被注释,需读者手动更改

file_uploads

设置是否允许通过HTTP上传文件

file_uploads=On

upload_tmp_dir

设置通过HTTP上传文件时的临时目录,如果为空,则使用系统的临时目录

upload_tmp_dir =空

upload_max_filesize

设置允许上传文件的大小,如“50M”,必须填写单位

upload_max_filesize=2M

post_max_size

控制在采用POST方法进行一次表单提交中PHP所能够接收的最大容量。要上传更大的文件,则该值必须大于upload_max_filesize的值。

如upload_max_filesize=10M,那么upload_max_filesize的值必须要大于10M

post_max_size = 8M

max_input_time

以秒为单位对通过POSTGET以及PUT方式接收数据时间进行限制

max_input_time = 60

1.2                    PHP常用扩展库及其说明

扩张库

说明

php_ftp.dll

支持FTP函数库,可以实现客户机与服务器之间标准传送协议(FTP

php_gd2.dll

支持图像处理函数库,支持对.gif.jpg.png等多种图像格式

php_imap.dll

支持imap电子邮件处理函数库

php_mssql.dll

支持MsSQL数据库

php_msql.dll

支持mSQL数据库

php_MySQL.dll

支持MySQL数据库

php_oracle.dll

支持Oracle数据库

php_pdf.dll

支持PDF文件处理函数库

php_sockets.dll

支持Sockets处理函数库

php_zlib.dll

支持zlib文件压缩函数库

php_pdo.dll

支持PDO数据库抽象层

php_pdo_mysql.dll

支持MySQL数据库

php_pdo_mssql.dll

支持MS SQL Server数据库

php_pdo_oci8.dll

支持Oracle数据库

php_pdo_odbc.dll

支持ODBC数据库

php_pdo_pgsql.dll

支持PGSQL数据库

1.3  解决PHP的常见配置问题

程序运行出错是许多程序员最为头疼的问题,下面介绍PHP常见的配置问题。通过本节的学习,可以分清哪些错误是由于PHP环境配置不当产生的,从而避免不必要的时间资源浪费,高效的完成Web应用程序的开发。

1.3.1  解决Apache服务器端口冲突

IIS的默认端口号为80,同Apache服务器默认端口号相同。由于采用了相同的端口号80,因此,在运行网页时就会发生冲突。

如果用户机器上安装了IIS,就需要修改IIS的默认端口,否则将导致Apache服务器无法正常工作。更改IIS的默认侦听端口80,可以在IIS的管理器中进行设置,或者停止IIS的服务也可以。

用户也可以在安装Apache服务器时将默认的端口号进行更改,从而解决两个服务器共用一个端口号而产生冲突的问题。

技巧:如果在搭建PHP环境时,将Apache的端口号设置为82,那麽在通过浏览器访问项目时,则应该输入http://127.0.0.1:82/或者http://localhost:82/。

1.3.2  设置PHP的系统当前时间

由于php 5.0date()函数进行了重写,因此,目前的日期时间函数比系统时间少8个小时。在PHP语言中默认设置的是标准的格林威治时间(即采用的是零时区),所以要获取本地当前的时间必须更改PHP语言中的时区设置。方法如下: 

php.ini文件中,找到[date]下的“;date.timezone =”选项,将该项修改为“date.timezone =Asia/Hong_Kong”,然后重新启动Apache服务器。

设置完成后,在输出系统当前的时间就不会出现时差问题。

1.3.3  增加PHP扩展模块

增加PHP扩展模块也称为动态扩展,用来动态加载某个模块,它包含一个指令:extension

Windows操作系统下,加载模块的方法如下。打开php.ini文件,定位到如下位置,去掉;tension=php_java.dll前面的分号,保存后重新启动Apache服务器,即完成扩展模块的加载操作。

;tension=php_java.dll

Linux操作系统下,加载模块的方法如下。

extension=php_java.so

需要说明的是,只加载这一行代码并不一定能启用相关的扩展包,有时还需要确保在操作系统中安装相关的软件。例如:为启用java支持,需要安装JDK

 


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)

MySQL and phpMyAdmin: Core Features and Functions MySQL and phpMyAdmin: Core Features and Functions Apr 22, 2025 am 12:12 AM

MySQL and phpMyAdmin are powerful database management tools. 1) MySQL is used to create databases and tables, and to execute DML and SQL queries. 2) phpMyAdmin provides an intuitive interface for database management, table structure management, data operations and user permission management.

How to safely store JavaScript objects containing functions and regular expressions to a database and restore? How to safely store JavaScript objects containing functions and regular expressions to a database and restore? Apr 19, 2025 pm 11:09 PM

Safely handle functions and regular expressions in JSON In front-end development, JavaScript is often required...

The Compatibility of IIS and PHP: A Deep Dive The Compatibility of IIS and PHP: A Deep Dive Apr 22, 2025 am 12:01 AM

IIS and PHP are compatible and are implemented through FastCGI. 1.IIS forwards the .php file request to the FastCGI module through the configuration file. 2. The FastCGI module starts the PHP process to process requests to improve performance and stability. 3. In actual applications, you need to pay attention to configuration details, error debugging and performance optimization.

How to process and display percentage numbers in Java? How to process and display percentage numbers in Java? Apr 19, 2025 pm 10:48 PM

Display and processing of percentage numbers in Java In Java programming, the need to process and display percentage numbers is very common, for example, when processing Excel tables...

Explain the purpose of foreign keys in MySQL. Explain the purpose of foreign keys in MySQL. Apr 25, 2025 am 12:17 AM

In MySQL, the function of foreign keys is to establish the relationship between tables and ensure the consistency and integrity of the data. Foreign keys maintain the effectiveness of data through reference integrity checks and cascading operations. Pay attention to performance optimization and avoid common errors when using them.

How does MySQL differ from Oracle? How does MySQL differ from Oracle? Apr 22, 2025 pm 05:57 PM

MySQL is suitable for rapid development and small and medium-sized applications, while Oracle is suitable for large enterprises and high availability needs. 1) MySQL is open source and easy to use, suitable for web applications and small and medium-sized enterprises. 2) Oracle is powerful and suitable for large enterprises and government agencies. 3) MySQL supports a variety of storage engines, and Oracle provides rich enterprise-level functions.

ZipInputStream failed to decompress Chinese file name? How to set the character set correctly? ZipInputStream failed to decompress Chinese file name? How to set the character set correctly? Apr 19, 2025 pm 04:33 PM

Discussion on ZipInputStream character set settings Many developers use ZipInputStream to decompress zip compressed packages containing Chinese file names or folder names, �...

What is the difference between IS TRUE and =True query conditions in MySQL? What is the difference between IS TRUE and =True query conditions in MySQL? Apr 19, 2025 pm 06:54 PM

The difference between ISTRUE and =True query conditions in MySQL In MySQL database, when processing Boolean values ​​(Booleans), ISTRUE and =TRUE...

See all articles