Php 简明教程

PHP - Installation

你可以在互联网上免费获取任何一个 PHP 在线编译器来学习 PHP 编程的基本知识。这有助于熟悉 PHP 的特性,而无需在电脑上安装 PHP。之后,在本地计算机上安装一个成熟的 PHP 环境。

You can start learning the basics of programming in PHP with the help of any of the online PHP compilers freely available on the Internet. This will help in getting acquainted with the features of PHP without installing it on your computer. Later on, install a full-fledged PHP environment on your local machine.

Tutorialpoint 的 “Coding Ground for Developers” 提供了一个这样的在线 PHP 编译器。访问 https://www.tutorialspoint.com/codingground.htm ,输入 PHP 脚本并执行。

One such online PHP compiler is provided by Tutorialpoint’s "Coding Ground for Developers". Visit https://www.tutorialspoint.com/codingground.htm, enter PHP script and execute it.

php installation 1

不过,要能够学习 PHP 的高级特性,特别是与服务器变量、使用后端数据库等网络概念相关的特性,你需要在本地计算机上安装 PHP 环境。

However, to be able to learn the advanced features of PHP, particularly related to the web concepts such as server variables, using backend databases, etc., you need to install the PHP environment on your local machine.

为了开发并运行 PHP 网页,你需要在你的计算机系统上安装三个至关重要的组成部分。

In order to develop and run PHP Web pages, you neeed to install three vital components on your computer system.

  1. Web Server − PHP will work with virtually all Web Server software, including Microsoft’s Internet Information Server (IIS), NGNIX, or Lighttpd etc. The most often used web server software is the freely available Apache Server. Download Apache for free here − https://httpd.apache.org/download.cgi

  2. Database − PHP will work with virtually all database software, including Oracle and Sybase but most commonly used is freely available MySQL database. Download MySQL for free here − [role="bare"]https://www.mysql.com/downloads/

  3. PHP Parser − In order to process PHP script instructions a parser must be installed to generate HTML output that can be sent to the Web Browser.

虽然可以单独安装这三个组成部分并正确配置安装,但这是一个有点复杂的过程,特别是对于初学者来说。相反,使用包含预编译的 Apache、MySQL 和 PHP 二进制文件的所有一体化打包分发版更为方便。

Although it is possible to install these three components separately, and configure the installation correctly, it is a little complex process, particularly for the beginners. Instead, using any all-in-one packaged distribution that contains precompiled Apache, MySQL and PHP binaries is convenient.

XAMPP Installation

有许多已预先编译的包在开源和专有发行版中可用。来自 Apache Friends ( https://www.apachefriends.org/ ) 的 XAMPP 是最流行的 PHP 启用 Web 服务器包之一。我们将在本教程中使用 XAMPP。

There are many precompiled bundles available both in open-source as well as proprietary distributions. XAMPP, from Apache Friends (https://www.apachefriends.org/) is one of the most popular PHP enabled web server packages. We shall be using XAMPP in this tutorial.

XAMPP 是一个易于安装的 Apache 发行版,它包含 A*pache, *M*ariaDB, *P*HP and *P*erl. The letter *X 缩写表示它是一项跨平台软件,可在 Windows、Linux 和 OS X 上使用。请注意,XAMPP 包含 MariaDB,它是 MySQL 的一个派生,但功能没有区别。

XAMPP is an easy to install Apache distribution that contains A*pache, *M*ariaDB, *P*HP and *P*erl. The letter *X in the acronym indicates that it is a cross-platform software, available for use on Windows, Linux and OS X. Note that XAMPP includes MariaDB, which is a fork of MySQL, with no difference in its functionality.

要下载适用于你操作系统的安装程序,请访问 https://www.apachefriends.org/download.html ,并下载以下之一:

To download the respective installer for your operating system, visit https://www.apachefriends.org/download.html, and download one of the following −

  1. Windows − link:https://sourceforge.net/projects/xampp/files/XAMPP%20Windows/8.0.28/xampp-windows-x64-8.0.28-0-VS16-installer.exe [[role="bare"]https://sourceforge.net/projects/]

  2. Linuxhttps://sourceforge.net/projects/

  3. OS X − link:https://sourceforge.net/projects/xampp/files/XAMPP%20Mac%20OS%20X/8.0.28/xampp-osx-8.0.28-0-installer.dmg [[role="bare"]https://sourceforge.net/projects/]

在 Windows 上使用安装程序是一个完全基于向导的安装。你需要提供的是管理员访问权限和安装目录的位置,默认为“c:\xampp”。

Using the installer on Windows is a completely wizard based installation. All you need to provide is an administrator access and the location of the installation directory which is "c:\xampp" by default.

要在 Linux 上安装 XAMPP,请使用以下步骤:

To install XAMPP on Linux, use the following steps −

Step 1 - 更改安装程序的权限:

Step 1 − Change the permissions to the installer −

chmod 755 xampp-linux-*-installer.run

运行安装程序:

Run the installer −

sudo ./xampp-linux-*-installer.run

XAMPP 现在安装在“/opt/lamp”目录下面。

XAMPP is now installed below the "/opt/lamp" directory.

Step 2 - 要启动 XAMPP,只需调用此命令:

Step 2 − To start XAMPP simply call this command −

sudo /opt/lampp/lampp start

你现在应该在屏幕上看到类似此内容的内容:

You should now see something like this on your screen −

Starting XAMPP ...
LAMPP: Starting Apache...
LAMPP: Starting MySQL...
LAMPP started.
Ready. Apache and MySQL are running.

你还可以使用图形工具轻松管理服务器。你可以使用以下命令来启动此工具:

You can also use a graphical tool to manage your servers easily. You can start this tool with the following commands −

cd /opt/lampp
sudo ./manager-linux.run (or manager-linux-x64.run)

Step 3 - 要停止 XAMPP,只需调用此命令:

Step 3 − To stop XAMPP simply call this command −

sudo /opt/lampp/lampp stop

你现在应该在屏幕上看到类似此内容的内容:

You should now see something like this on your screen −

Stopping XAMPP ...
LAMPP: Stopping Apache...
LAMPP: Stopping MySQL...
LAMPP stopped.

此外,请注意,有一个可以轻松启动/停止服务器的图形工具。你可以使用以下命令来启动此工具:

Also, note that there is a graphical tool that you can use to start/stop your servers easily. You can start this tool with the following commands −

cd /opt/lampp
sudo ./manager-linux.run (or manager-linux-x64.run)

如果你使用的是 OS X,请按照以下步骤操作:

If you are using OS X, follow these steps −

  1. To start the installation, Open the DMG-Image, and double-click the image to start the installation process.

  2. To start XAMPP simply open XAMPP Control and start Apache, MySQL and ProFTPD. The name of the XAMPP Control is "manager-osx".

  3. To stop XAMPP simply open XAMPP Control and stop the servers. The name of the XAMPP Control is "manager-osx".

  4. The XAMPP control panel is a GUI tool from which the Apache server, and MySQL can be easily started and stopped.

php installation 2

启动 Apache 模块后按下 Admin 按钮。XAMPP 主页会像下面这样显示−

Press the Admin button after starting the Apache module. The XAMPP homepage appears like the one shown below −

php installation 3

PHP Parser Installation

在你继续之前,务必确保在你的机器上设置了适当的环境,以便使用 PHP 开发你的网络程序。

Before you proceed it is important to make sure that you have proper environment setup on your machine to develop your web programs using PHP.

在您的浏览器的地址框中输入以下地址。

Type the following address into your browser’s address box.

http://127.0.0.1/info.php

如果显示一个显示你的 PHP 安装相关的信息的页面,则意味着你的 PHP 和网络服务安装正确。否则,你必须遵循以下步骤在你的电脑上安装 PHP。

If this displays a page showing your PHP installation related information then it means you have PHP and Webserver installed properly. Otherwise you have to follow given procedure to install PHP on your computer.

本部分将指导您在以下四个平台上安装和配置 PHP −

This section will guide you to install and configure PHP over the following four platforms −

Apache Configuration

如果你使用 Apache 作为网络服务器,那么本节将指导你编辑 Apache 配置文件。

If you are using Apache as a Web Server then this section will guide you to edit Apache Configuration Files.

只需在此处检查− @ {s4}

Just Check it here − PHP Configuration in Apache Server

PHP.INI File Configuration

PHP 配置文件 php.ini 是影响 PHP 功能的最直接的最终方式。

The PHP configuration file, php.ini, is the final and most immediate way to affect PHP’s functionality.

只需在此处检查− @ {s5}

Just Check it here − PHP.INI File Configuration

Windows IIS Configuration

要配置你 Windows 机器上的 IIS,你可以参阅随 IIS 一起提供的 IIS 参考手册。

To configure IIS on your Windows machine you can refer your IIS Reference Manual shipped along with IIS.

现在,你的本地机器上有一个完整的 PHP 开发环境。

You now have a complete PHP development environment on your local machine.