Home > Backend Development > PHP Tutorial > Ubuntu 16.04 apt-get搭建LAMP环境

Ubuntu 16.04 apt-get搭建LAMP环境

PHPz
Release: 2020-08-10 16:26:11
forward
1202 people have browsed it

Ubuntu 的安装就不阐述了,网上有很多。

推荐学习:

Linux服务器环境搭建教程:小皮面板使用视频教程

Apache2

$ sudo apt-get install apache2             // Install Apache2

$ apache2 -v                               // Verify  Apache2
Server version: Apache/2.4.18 (Ubuntu)
Server built:   2016-04-15T18:00:57
Copy after login

上面信息说明 Apache 安装成功,可以通过浏览器访问 Apache 了。如下图所示:

Apache2 默认首页

PHP

$ sudo apt-get install php  // Install php

$ php -v                    // Verify  php
PHP 7.0.8-0ubuntu0.16.04.3 (cli) ( NTS )
Copyright (c) 1997-2016 The PHP Group
Zend Engine v3.0.0, Copyright (c) 1998-2016 Zend Technologies
    with Zend OPcache v7.0.8-0ubuntu0.16.04.3, Copyright (c) 1999-2016, by Zend Technologies

$ sudo apt-get install libapache2-mod-php    // Install libapache2-mod-php

$ cat /etc/apache2/mods-enabled/php7.0.load  // Verify  libapache2-mod-php
# Conflicts: php5
LoadModule php7_module /usr/lib/apache2/modules/libphp7.0.so
Copy after login

上面信息说明 libapache2-mod-php7.0 安装成功,并且 php7 成功加载模块 libphp7.0.so 。

MySQL

$ sudo apt-get install mysql-server         // Install MySQL
...
// Need to Set Password for root
...

$ type mysql                                // Verify MySQL
mysql is hashed (/usr/bin/mysql)

$ sudo apt-get install php7.0-mysql         // Install php7.0-mysql
Copy after login

LAMP 环境测试

通过以下命令重新启动 apache2 和 mysql :

$ sudo service mysql restart                // Restart MySQL
$ sudo service apache2 restart              // Restart Apache2
Copy after login

在网站根目录下,新增一个 phpinfo.php 文件:

$ sudo echo "<?php echo phpinfo(); ?>" > /var/www/html/phpinfo.php
Copy after login

然后通过浏览器访问 http://localhost/phpinfo.php 如下图所示:phpinfo 详情页

Related labels:
source:tuicool
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