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

该文章转载于http://www.linuxidc.com/Linux/2016-10/136327.htm

当我们在各大平台买来的云服务器之后,服务器就是一个空机,我们需要按照自己的需求配置。下面就记录一下如何搭建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
deb http://mirrors.aliyun.com/ubuntu/ xenial main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ xenial-security main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ xenial-updates main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ xenial-backports main restricted universe multiverse
##测试版源
deb http://mirrors.aliyun.com/ubuntu/ xenial-proposed main restricted universe multiverse
# 源码
deb-src http://mirrors.aliyun.com/ubuntu/ xenial main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ xenial-security main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ xenial-updates main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ xenial-backports main restricted universe multiverse
##测试版源
deb-src http://mirrors.aliyun.com/ubuntu/ xenial-proposed main restricted universe multiverse
# Canonical 合作伙伴和附加
deb http://archive.canonical.com/ubuntu/ xenial partner
deb http://extras.ubuntu.com/ubuntu/ xenial main

4、更新

sudo apt-get update
sudo apt-get upgrade
更多配置请看原文 点击进去

1.安装Apache

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

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

3.安装PHP

sudo apt-get install php7.0

测试:php7.0 -v

4.安装其他模块

sudo apt-get install libapache2-mod-php7.0
sudo apt-get install php7.0-mysql
重启服务
service apache2 restart
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
环境下的数据库是一致的。
创建phpMyAdmin快捷方式:sudo ln -s /usr/share/phpmyadmin /var/www/html
启用Apache mod_rewrite模块:sudo a2enmod rewrite
重启服务:
service php7.0-fpm restart
service apache2 restart
测试:浏览器访问:http://ubuntu地址/phpmyadmin

7.配置Apache

vim /etc/apache2/apache2.conf
添加:
AddType application/x-httpd-php .php .htm .html
AddDefaultCharset UTF-8

重启Apache服务

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


其他文章



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值