ubuntu系统下安装php环境和搭建LAMP

该文章转载于https://blog.csdn.net/itxiaolong3/article/details/77909505

当我们在各大平台买来的云服务器之后,服务器就是一个空机,我们需要按照自己的需求配置。下面就记录一下如何搭建LAMP环境来执行php代码。

前期准备:

更新apt-get安装源,添加阿里的安装源

1、原文件重命名备份

sudo mv /etc/apt/sources.list /etc/apt/source.list.bak

2、编辑源列表文件

sudo vim /etc/apt/source.list

3、用下面的文本作为内容 ubuntu 16

  1.  
    deb http: //mirrors.aliyun.com/ubuntu/ xenial main restricted universe multiverse
  2.  
    deb http: //mirrors.aliyun.com/ubuntu/ xenial-security main restricted universe multiverse
  3.  
    deb http: //mirrors.aliyun.com/ubuntu/ xenial-updates main restricted universe multiverse
  4.  
    deb http: //mirrors.aliyun.com/ubuntu/ xenial-backports main restricted universe multiverse
  5.  
    ##测试版源
  6.  
    deb http: //mirrors.aliyun.com/ubuntu/ xenial-proposed main restricted universe multiverse
  7.  
    # 源码
  8.  
    deb-src http: //mirrors.aliyun.com/ubuntu/ xenial main restricted universe multiverse
  9.  
    deb-src http: //mirrors.aliyun.com/ubuntu/ xenial-security main restricted universe multiverse
  10.  
    deb-src http: //mirrors.aliyun.com/ubuntu/ xenial-updates main restricted universe multiverse
  11.  
    deb-src http: //mirrors.aliyun.com/ubuntu/ xenial-backports main restricted universe multiverse
  12.  
    ##测试版源
  13.  
    deb-src http: //mirrors.aliyun.com/ubuntu/ xenial-proposed main restricted universe multiverse
  14.  
    # Canonical 合作伙伴和附加
  15.  
    deb http: //archive.canonical.com/ubuntu/ xenial partner
  16.  
    deb http: //extras.ubuntu.com/ubuntu/ xenial main

4、更新

  1.  
    sudo apt-get update
  2.  
    sudo apt-get upgrade

更多配置请看原文点击进去

1.安装Apache

sudo apt-get install apache2
测试: 浏览器访问http://Ubuntu的IP,出现It Works!网页。
  1.  
    查看状态: service apache2 status/start/stop/restart
  2.  
    Web目录: /var/www
  3.  
    安装目录: /etc/apache2/
  4.  
    全局配置: /etc/apache2/apache2.conf
  5.  
    监听端口: /etc/apache2/ports.conf
  6.  
    虚拟主机: /etc/apache2/sites-enabled/000-default.conf

2.安装MySQL,看我的另一篇文章,《ubuntu下安装mysql详细图文》

3.安装PHP

sudo apt-get install php7.0
扫描二维码关注公众号,回复: 2324315 查看本文章
测试:php7.0 -v

4.安装其他模块

  1.  
    sudo apt-get install libapache2-mod-php7.0
  2.  
    sudo apt-get install php7.0-mysql
  1.  
    重启服务
  2.  
    service apache2 restart
  3.  
    service mysql restart

测试Apache能否解析PHP

  • vim /var/www/html/phpinfo.php

  • 文件中写:<?php echo phpinfo();?>

  • 浏览器访问:http://ubuntu地址/phpinfo.php,出现PHP Version网页

5.修改权限

sudo chmod 777 /var/www

6.安装phpMyAdmin

sudo apt-get install phpmyadmin
安装:选择apache2,点击确定。下一步选择是要配置数据库,并输入密码,密码设置跟上篇文章的一致。这样php和java
  1.  
    环境下的数据库是一致的。
  2.  
    创建phpMyAdmin快捷方式:sudo ln -s /usr/share/phpmyadmin /var/www/html
  3.  
    启用Apache mod_rewrite模块:sudo a2enmod rewrite
  4.  
    重启服务:
  5.  
    service php7.0-fpm restart
  6.  
    service apache2 restart
  7.  
    测试:浏览器访问:http://ubuntu地址/phpmyadmin

7.配置Apache

vim /etc/apache2/apache2.conf

  1.  
    添加:
  2.  
    AddType application/x-httpd-php .php .htm .html
  3.  
    AddDefaultCharset UTF-8


重启Apache服务

service apache2 restart
就此搭建完毕。更加详细文章请看 原文

猜你喜欢

转载自www.cnblogs.com/lipcblog/p/9354973.html