felayman-----PHP environment setup_PHP tutorial

WBOY
Release: 2016-07-13 10:32:28
Original
869 people have browsed it

PHP is a server-side embedded scripting language. It is a server-side, cross-platform, object-oriented, HTML-embedded scripting language. This chapter will introduce readers to the establishment of a PHP development environment, common configuration problems and solutions. By studying this chapter, readers can learn the following contents.

Change verification code

: Windows - AppserV integrated installation package to build PHP environment

: Linux - XAMPP integrated installation package to build PHP environment

: Key configuration information of PHP development environment

: Solve common configuration problems of PHP

1.1 PHP environment setup

1.1.1 AppServ—Windows version PHP integrated installation package

AppServ packages server software and tools such as Apache, PHP, MySQL and phpMyAdmin after they are installed and configured. Developers only need to download the software from the website and then install it to quickly build a PHP development environment. Very suitable for beginners.

Note: When using AppServ to build a PHP development environment, you must ensure that Apache, PHP and MySQL are not installed in the system. Otherwise, uninstall these software first and then apply AppServ.

The following explains the specific steps to build a PHP development environment using the AppServ integrated installation package:

(1) Double-click the AppServ-win32-2.5.10.exe file to open the AppServ startup page as shown in Figure 1.1.


(2) Click the Next button in Figure 1.1 to open the AppServ installation agreement page as shown in Figure 1.2.

(3) Click the I Agree button in Figure 1.2 to open the page shown in Figure 1.3. Set the installation path of AppServ (the default installation path is generally: E:AppServ). After the AppServ installation is completed, Apache, MySQL, and PHP will be stored in this directory in the form of subdirectories.


(4) Click the Next button in Figure 1.3 to open the page shown in Figure 1.4. Select programs and components to install (select all by default).



Note: In the operation steps in Figure 1.4, if the MySQL database is already installed on this machine, you can uncheck the MySQL Database option here and still use the MySQL database that already exists on this machine.

(5) Click the Next button in Figure 1.4 to open the page shown in Figure 1.5. Fill in the computer name, add an email address, and set the Apache port number. The default is port 80.


Tips: The setting of the Apache server port number is directly related to whether the Apache server can start normally. If port 80 on this machine is occupied by IIS or Thunder, then you need to modify the port number of Apache, or modify the port number of IIS or Thunder to complete the configuration of the Apache server. If a port conflict occurs, the installation will fail and the Apache service will not start.

(6) Click the Next button in Figure 1.5 to open the page shown in Figure 1.6. Set the login password and character set of the MySQL database root user.

Tip: To set the character set of MySQL database, you can choose UTF-8, GBK or GB2312. Here, the character set is set to "UTF-8 Unicode", which means that the character set of the MySQL database will use UTF8 encoding.


Note: The password for the MySQL database root user set in Figure 1.6 must be remembered because the program must use this password when connecting to the database.

When executing the program, you need to change the password to connect to the database. If you forget to set the password during installation, the most direct and effective solution is to reinstall AppServ.

(7) Click the Install button in Figure 1.6 to start the installation, as shown in Figure 1.7.


(8) After the installation is completed, you can start the Apache and MySQL services in the AppServ related operation list in the start menu, as shown in Figure 1.8.


1.2 Key configuration information of PHP development environment

The configuration method of the PHP development environment was introduced earlier. In addition to the installation steps themselves, the configuration of PHP and the server is also very important. The following will mainly introduce the configuration of PHP and Apache server.

1.2.1 Basic configuration of Apache server

The setting file of the Apache server is located in the /usr/local/apache/conf/ directory in the Linux operating system (located in "/etc/httpd/conf" in the Windows operating system). Basically, the following 3 configuration files are used to configure the behavior of the Apache server.

t access.conf: used to configure server access permissions and control access restrictions for different users and computers.

t httpd.conf: used to set the basic environment for server startup.

t srm.conf: Mainly used for setting file resources.

Tips: http.conf is the configuration file of the Apache server. Its commonly used configurations include: the port number of the Apache server, the access path of the server and pseudo-static settings.

ServerName localhost:80

DocumentRoot "/xampp/htdocs"

LoadModule rewrite_module modules/mod_rewrite.so

1.2.2 Basic configuration of PHP.INI file

The php.ini file is a configuration file that PHP automatically reads when it starts. php.ini is an ASCLL text file, divided into multiple parts, each part includes related parameters. The name of each part is placed in the first square bracket, followed by the name and number, each name on its own line. Use regular PHP code, which is very sensitive to parameter names and cannot contain spaces, but parameters can be numbers, strings or Boolean logical numbers. A semicolon is placed at the beginning of each line as a designation mark, which makes it easy to choose to use or not use these features of PHP without having to delete the line. Commenting out a feature (that is, adding a semicolon) will not compile and execute the line. Each time you modify the php.ini file, you must restart the Apache server for the new settings to take effect.

Tips: php.ini is the PHP configuration file, used to load various function libraries, set error levels, set server time, etc. In the Linux operating system, php.ini is stored in the /opt/lampp/etc/php.ini folder, while in the Windwos operating system, php.ini is stored in the windows file on the system disk. The basic configuration of the php.ini file is shown in Table 1.1.

Table 1.1 Basic configuration of php.ini file

参数

说明

默认值

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:phpincludes"

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

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

max_input_time = 60

Parameters
Description Default value
error_reporting Set the level of error handling. Recommended values ​​are E_ALL & ~E_NOTICE & ~E_STRICT, which displays all error messages except reminders and encoding standardization warnings. E_ALL & ~E_NOTICE & ~E_STRICT
register_globals Normally, this variable can be set to Off, which can provide more secure protection against script attacks through forms register_globals = On
include_path Set the PHP search path. This parameter can receive a series of directories. When PHP encounters a file prompt without a path, it will automatically detect these directories. It should be noted that when some options allow multiple values, the system list separator should be used. Under Windows, use the semicolon ";" Use colon ":" under Linux ; UNIX: "/path1:/path2" ;include_path = ".:/php/includes" ; Windows: "path1;path2" ;include_path = ".;c:phpincludes"
extension_dir Specify the directory of PHP’s dynamic link extension library Under the "ext" directory
extension Specify the dynamic link extension library loaded when PHP starts. Please refer to Table 1.2 for common PHP extension libraries and their descriptions. PHP’s common extension libraries are commented after the initial installation and configuration, and readers need to manually change them
file_uploads Set whether to allow file upload via HTTP file_uploads=On
upload_tmp_dir Set the temporary directory when uploading files via HTTP. If it is empty, the system's temporary directory will be used upload_tmp_dir=empty
upload_max_filesize Set the size of files allowed to be uploaded, such as "50M", the unit must be filled in upload_max_filesize=2M
post_max_size Control the maximum capacity that PHP can receive during a form submission using the POST method. To upload larger files, this value must be greater than the value of upload_max_filesize. If upload_max_filesize=10M, then the value of upload_max_filesize must be greater than 10M post_max_size = 8M
max_input_time Limit the time of receiving data through POST, GET and PUT in seconds max_input_time = 60

Table 1.2 PHP common extension libraries and their descriptions

扩张库

说明

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数据库

Expansion Library
Description
php_ftp.dll Supports FTP function library, which can implement standard transfer protocol (FTP) between client and server
php_gd2.dll Supports image processing function library, supports various image formats such as .gif, .jpg, .png, etc.
php_imap.dll Support imap email processing function library
php_mssql.dll Support MsSQL database
php_msql.dll Support mSQL database
php_MySQL.dll Support MySQL database
php_oracle.dll Support Oracle database
php_pdf.dll Support PDF file processing function library
php_sockets.dll Supports Sockets processing function library
php_zlib.dll Support zlib file compression function library
php_pdo.dll Supports PDO database abstraction layer
php_pdo_mysql.dll Support MySQL database
php_pdo_mssql.dll Supports MS SQL Server database
php_pdo_oci8.dll Support Oracle database
php_pdo_odbc.dll Support ODBC database
php_pdo_pgsql.dll Support PGSQL database

1.3 Solve common configuration problems of PHP

Program running errors are the most troublesome problem for many programmers. The following introduces common configuration problems of PHP. By studying this section, you can distinguish which errors are caused by improper configuration of the PHP environment, thereby avoiding unnecessary waste of time and resources and completing the development of Web applications efficiently.

1.3.1 Resolve Apache server port conflict

The default port number of IIS is 80, which is the same as the default port number of the Apache server. Since the same port number 80 is used, a conflict will occur when running the web page.

If IIS is installed on the user's machine, you need to modify the default port of IIS, otherwise the Apache server will not work properly. To change the default listening port 80 of IIS, you can set it in the IIS manager or stop the IIS service.

Users can also change the default port number when installing the Apache server, thereby solving the conflict problem caused by two servers sharing the same port number.

Tips: If you set the Apache port number to 82 when building a PHP environment, then when accessing the project through a browser, you should enter http://127.0.0.1:82/ or http://localhost: 82/.

1.3.2 Set the current system time of PHP

Due to the rewriting of the date() function in PHP 5.0, the current date and time function is 8 hours less than the system time. The default setting in the PHP language is standard Greenwich Time (that is, the zero time zone is used), so to obtain the current local time, you must change the time zone setting in the PHP language. Here’s how:

In the php.ini file, find the ";date.timezone=" option under [date], modify it to "date.timezone =Asia/Hong_Kong", and then restart the Apache server.

After the setting is completed, there will be no time difference problem when outputting the current time of the system.

1.3.3 Add PHP extension module

Adding a PHP extension module is also called a dynamic extension, which is used to dynamically load a module. It contains an instruction: extension.

Under the Windows operating system, the method of loading modules is as follows. Open the php.ini file, navigate to the following location, remove the semicolon in front of ;tension=php_java.dll, save it and restart the Apache server to complete the loading operation of the extension module.

;tension=php_java.dll

Under the Linux operating system, the method of loading modules is as follows.

extension=php_java.so

It should be noted that loading only this line of code does not necessarily enable the relevant expansion packs. Sometimes it is also necessary to ensure that the relevant software is installed in the operating system. For example: To enable java support, you need to install JDK.


www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/755761.htmlTechArticlePHP is a server-side embedded scripting language. It is a server-side, cross-platform, object-oriented, HTML Embedded scripting language. This chapter will introduce readers to the construction of PHP development environment, often...
Related labels:
source:php.cn
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template