Felayman ----- PHP environment setup

Source: Internet
Author: User
Tags php development environment

PHP is a server-side embedded scripting language. It is a server-side, cross-platform, object-oriented, and HTML embedded scripting language. This chapter will introduce you to PHP Development Environment setup and common configuration problems and solutions. Through this chapter, you can learn the following content.

Change Verification Code

: Windows -- AppserV integrated installation package to build a PHP Environment

: Linux -- XAMPP integrated installation package to build a PHP Environment

: Key configuration information of the PHP development environment

: Solve common PHP configuration problems

1.1 PHP environment construction 1.1.1 AppServ-Windows PHP Integrated Installation Package

AppServ packages Apache, PHP, MySQL, phpMyAdmin, and other server software and tools after installation and configuration. Developers can quickly build a PHP development environment by downloading the software on the website and installing it. It is very suitable for beginners.

Note: When Using AppServ to build a PHP development environment, make sure that Apache, PHP, and MySQL are not installed in the system. Otherwise, uninstall the software and then apply the AppServ.

The following describes how 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 shown in 1.1.


(2) Click the Next button in Figure 1.1 to open the AppServ installation protocol page 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 E: \ AppServ). After AppServ is installed, Apache, MySQL, and PHP are stored in subdirectories.


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



Note: In the procedure shown in figure 1.4, if the MySQL Database is already installed on the local machine, you can still use the existing MySQL Database on the local machine without selecting the MySQL Database option.

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


Tip: Setting the port number of the Apache server is directly related to whether the Apache server can be started normally. If port 80 in the local machine is occupied by IIS or thunder, You need to modify the Apache port number or the IIS or thunder port number to complete the configuration of the Apache server. If a port conflict occurs, the installation will fail and the Apache service cannot be started.

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

TIPS: MySQL database character set settings, you can choose UTF-8, GBK or GB2312. Here, the character set is set to UTF-8 Unicode, indicating that the character set of the MySQL database will be UTF8 encoded.


Note: the password of the root user of the MySQL database set in Figure 1.6 must be kept in mind because the program must use this password when connecting to the database.

To change the password of the database. If you forget to set the password during installation, the most effective solution is to reinstall AppServ.

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


(8) after the installation is complete, you can start 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 the PHP development environment

The preceding section describes the configuration of the PHP development environment. In addition to the installation steps, the configuration of PHP and server is also very important. The following describes the configuration of PHP and Apache servers.

1.2.1 basic configuration of Apache server

The configuration file of the Apache server is located in the/usr/local/apache/conf/directory in the Linux operating system ("/etc/httpd/conf" in the Windows operating system, basically, the following three 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.

Tip: http. conf is the configuration file of the Apache server. Common 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 the PHP. ini file

The php. ini file is the configuration file automatically read by PHP at startup. Php. ini is an ASCLL text file. It consists of multiple parts, each of which includes relevant parameters. The name of each part is placed in square brackets at the beginning, followed by the name-to-number, each name exclusive line. The PHP code in the rule is very sensitive to parameter names and cannot contain spaces. However, a parameter can be a number, string, or Boolean logical number. The semicolon is located at the beginning of each row and serves as the specified tag. This makes it easy to choose to use or not use these features of PHP, instead of deleting the row. If you annotate a feature (that is, add a semicolon), this row will not be compiled and executed. After modifying the php. ini file, you must restart the Apache server to make the new settings take effect.

Tip: php. ini is the configuration file of PHP. It is used to load various function libraries, set the error level, and set the server time. In Linux, php. ini is stored in/opt/lampp/etc/php. in the ini folder, and in the Windwos operating system, php. ini is stored in a 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 the php. ini file

Parameters

Description

Default Value

Error_reporting

Sets the error handling level. Recommended Value: E_ALL &~ E_NOTICE &~ E_STRICT: displays all error messages except the reminder and encoding standard warning.

E_ALL &~ E_NOTICE &~ E_STRICT

Register_globals

This variable can usually be set to Off to provide more security measures for script attacks through forms.

Register_globals = On

Include_path

Set the PHP search path. This parameter can receive directories of the series. When PHP encounters a file prompt with no path, it will automatically detect these directories. Note that when some options allow multiple values, the system list separator should be used, use the Semicolon ";" in Windows and the colon ":" in Linux

; UNIX: "/path1:/path2"

; Include_path = ".:/php/shortdes"

; Windows: "\ path1; \ path2"

; Include_path = ".; c: \ php \ shortdes"

Extension_dir

Specifies the directory of the PHP dynamic connection extension Library

Under the "\ ext" Directory

Extension

Specify the dynamic connection extension library loaded when PHP starts. For more information about common PHP extension libraries, see table 1.2.

Common PHP extension libraries are commented out after the initial installation and configuration, which must be manually changed

File_uploads

Set whether to allow file upload over HTTP

File_uploads = On

Upload_tmp_dir

Sets the temporary directory when files are uploaded over HTTP. If it is null, the temporary directory of the system is used.

Upload_tmp_dir = NULL

Upload_max_filesize

Set the size of the file to be uploaded, such as "50 m". The unit is required.

Upload_max_filesize = 2 M

Post_max_size

Control the maximum capacity that PHP can receive in a form submission using the POST method. To upload a larger file, the value must be greater than the value of upload_max_filesize.

For example, if upload_max_filesize = 10 M, the value of upload_max_filesize must be greater than 10 M.

Post_max_size = 8 M

Max_input_time

The time for receiving data through POST, GET, and PUT is limited in seconds.

Max_input_time = 60

Table 1.2 common PHP extension libraries and descriptions

Expansion Library

Description

Php_ftp.dll

Supports FTP function libraries to implement standard transfer protocol (FTP) between the client and the server)

Php_gd2.dll

Supports image processing libraries and multiple image formats such as .gif?.jpg=.png.

Php_imap.dll

Supports the imap email processing function library

Php_mssql.dll

Support for MsSQL Databases

Php_msql.dll

Support for mSQL Databases

Php_MySQL.dll

Support for MySQL Databases

Php_oracle.dll

Support for Oracle databases

Php_cmd.dll

Support PDF file processing function library

Php_sockets.dll

Support for Sockets processing function libraries

Php_zlib.dll

Supports zlib File compression function library

Php_pdo.dll

Support PDO database abstraction layer

Php_pdo_mysql.dll

Support for MySQL Databases

Php_pdo_mssql.dll

Support for ms SQL Server databases

Php_pdo_oci8.dll

Support for Oracle databases

Php_pdo_odbc.dll

Support for ODBC Databases

Php_pdo_pgsql.dll

Support for PostgreSQL databases

1.3 solve common PHP configuration problems

Program running errors are the biggest headache for many programmers. The following describes common PHP configuration problems. Through this section, you can identify which errors are caused by improper configuration of the PHP environment, so as to avoid unnecessary waste of time resources and efficiently complete Web application development.

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 Apache server. Because the same port number is used, a conflict occurs when the webpage is running.

If IIS is installed on your machine, you need to modify the default port of IIS. Otherwise, the Apache server will not work properly. Modify the default listening port 80 of IIS. You can set it in the IIS manager or stop IIS services.

You can also change the default port number when installing the Apache server, so that the two servers share a port number and conflict occurs.

Tip: If you set Apache port to 82 when setting up a PHP environment, you should enter http: // 127.0.0.1: 82/or http: // localhost: 82 /.

1.3.2 set the current time of the PHP System

Because php 5.0 overwrites the date () function, the current date and time function is eight hours less than the system time. In PHP, the standard Greenwich Mean Time (Zero Time Zone) is set by default. To obtain the current local time, you must change the time zone settings in PHP. The method is as follows:

In php. in the INI file, find "; date." Under [date. timezone = "option, change this item to" date. timezone = Asia/Hong_Kong ", and then restart the Apache server.

After the settings are complete, the current time of the output system will not experience time difference.

1.3.3 added the PHP extension module

The added PHP extension module is also called dynamic extension. It is used to dynamically load a module. It contains a command: extension.

In a Windows operating system, the method for loading a module is as follows. Open the php. ini file, locate the following location, and remove the; tension = php_java.dll; Save and restart the Apache server to load the extension module.

; Tension = php_java.dll

In Linux, the method for loading a module is as follows.

Extension = php_java.so

It should be noted that loading only this line of code does not necessarily enable the relevant extension package, and sometimes it is necessary to ensure that the relevant software is installed in the operating system. For example, to enable java support, you must install JDK.


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.