|
|
(未显示4个用户的106个中间版本) |
第1行: |
第1行: |
| PHP是一种通用的适合Web开发的脚本语言。PHP脚本可以嵌入到HTML。这一节介绍如何在一个已安装Apache2和MySQL的Ubuntu系统中安装及配置PHP.
| | [[文件:14.png]] |
| | |
| 这一节假定你已经在Ubuntu中安装并配置了Apache2 Web Server及MySQL Database Server。你可以引用有关Apache2和MySQL的相关章节以安装和配置Apache2及MySQL。
| |
| | |
| =Installation (安装)=
| |
| | |
| PHP可用于Ubuntu Linux。不像python和perl,他们岁基础系统一同安装,PHP必须是之后添加的。
| |
| | |
| 要安装PHP和Apache PHP模块,你可以在终端提示符下键入下列指令:
| |
| | |
| <pre>
| |
| sudo apt install php libapache2-mod-php
| |
| </pre>
| |
| | |
| 你也可以在终端提示符下运行PHP脚本。为了运行PHP脚本,你需要在终端提示符下安装php-cli包。要安装php-cli you你可以在终端提示符下输入下列指令:
| |
| | |
| <pre>
| |
| sudo apt install php-cli
| |
| </pre>
| |
| | |
| You can also execute PHP scripts without installing the Apache PHP module. To accomplish this, you should install the php-cgi package. You can run the following command at a terminal prompt to install the php-cgi package:
| |
| | |
| <pre>
| |
| sudo apt install php-cgi
| |
| </pre>
| |
| | |
| To use MySQL with PHP you should install the php-mysql package. To install php-mysql you can enter the following command at a terminal prompt:
| |
| | |
| <pre>
| |
| sudo apt install php-mysql
| |
| </pre>
| |
| | |
| Similarly, to use PostgreSQL with PHP you should install the php-pgsql package. To install php-pgsql you can enter the following command at a terminal prompt:
| |
| | |
| <pre>
| |
| sudo apt install php-pgsql
| |
| </pre>
| |
| | |
| =Configuration=
| |
| | |
| If you have installed the libapache2-mod-php or php-cgi packages, you can run PHP scripts from your web browser. If you have installed the php-cli package, you can run PHP scripts at a terminal prompt.
| |
| | |
| By default, when libapache2-mod-php is installed, the Apache 2 Web server is configured to run PHP scripts. In other words, the PHP module is enabled in the Apache Web server when you install the module. Please verify if the files /etc/apache2/mods-enabled/php7.0.conf and /etc/apache2/mods-enabled/php7.0.load exist. If they do not exist, you can enable the module using the a2enmod command.
| |
| | |
| Once you have installed the PHP related packages and enabled the Apache PHP module, you should restart the Apache2 Web server to run PHP scripts. You can run the following command at a terminal prompt to restart your web server:
| |
| | |
| <pre>
| |
| sudo systemctl restart apache2.service
| |
| </pre>
| |
| | |
| =Testing=
| |
| | |
| To verify your installation, you can run the following PHP phpinfo script:
| |
| | |
| <pre>
| |
| <?php
| |
| phpinfo();
| |
| ?>
| |
| </pre>
| |
| | |
| You can save the content in a file phpinfo.php and place it under the DocumentRoot directory of the Apache2 Web server. Pointing your browser to http://hostname/phpinfo.php will display the values of various PHP configuration parameters.
| |
| | |
| =References=
| |
| | |
| # For more in depth information see the php.net documentation.
| |
| # There are a plethora of books on PHP. A good book from O'Reilly is Learning PHP. PHP Cook Book is also good, but has no yet been updated for PHP7.
| |
| # Also, see the Apache MySQL PHP Ubuntu Wiki page for more information.
| |