Это старая версия документа.


PHP5 - язык сценариев

PHP - это универсальный макроязык, подходящий для интернет разработки. Программа на PHP может быть встроена в HTML. Этот раздел показывает как установить и настроить PHP5 в системе Ubuntu с Apache2 и MySQL.

В этом разделе подразумевается, что вы установили и настроили интернет сервер Apache2 и сервер базы данных MySQL. Вы можете обратиться к разделам по Apache2 и MySQL в этом руководстве для установки и настройки Apache2 и MySQL соответственно.

Установка

The PHP5 is available in Ubuntu Linux. Unlike python and perl, which are installed in the base system, PHP must be added.

  To install PHP5 you can enter the following command in the terminal prompt:
  sudo apt-get install php5 libapache2-mod-php5
  You can run PHP5 scripts from command line. To run PHP5 scripts from command line you should install php5-cli package. To install php5-cli you can enter the following command in the terminal prompt:
  sudo apt-get install php5-cli
  You can also execute PHP5 scripts without installing PHP5 Apache module. To accomplish this, you should install php5-cgi package. You can run the following command in a terminal prompt to install php5-cgi package:
  sudo apt-get install php5-cgi
  To use MySQL with PHP5 you should install php5-mysql package. To install php5-mysql you can enter the following command in the terminal prompt:
  sudo apt-get install php5-mysql
  Similarly, to use PostgreSQL with PHP5 you should install php5-pgsql package. To install php5-pgsql you can enter the following command in the terminal prompt:
  sudo apt-get install php5-pgsql

Настройка

Once you install PHP5, you can run PHP5 scripts from your web browser. If you have installed php5-cli package, you can run PHP5 scripts from your command prompt.

By default, the Apache 2 Web server is configured to run PHP5 scripts. In other words, the PHP5 module is enabled in Apache2 Web server automatically when you install the module. Please verify if the files /etc/apache2/mods-enabled/php5.conf and /etc/apache2/mods-enabled/php5.load exist. If they do not exists, you can enable the module using a2enmod command.

Once you install PHP5 related packages and enabled PHP5 Apache 2 module, you should restart Apache2 Web server to run PHP5 scripts. You can run the following command at a terminal prompt to restart your web server:

sudo service apache2 restart

Проверка

To verify your installation, you can run following PHP5 phpinfo script:

<?php

phpinfo();

?>

You can save the content in a file phpinfo.php and place it under DocumentRoot directory of Apache2 Web server. When point your browser to http://hostname/phpinfo.php, it would display values of various PHP5 configuration parameters.

Ссылки

  For more in depth information see php.net documentation.
  There are a plethora of books on PHP. Two good books from O'Reilly are Learning PHP 5 and the PHP Cook Book.
  Also, see the Apache MySQL PHP Ubuntu Wiki page for more information.