该文章转载于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/www6.安装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服务