ubuntu安装lamp环境
Ubuntu 16.04搭建LAMP开发环境
(这些命令都可以复制粘贴的哈右键,不对的话就自己敲)
打开Ubuntu后,右键,选择open-terminal进入终端命令行


下面的操作都在这里面输哈
基本设置:
1.设置root密码
sudo passwd
切换到root用户:su 或 su - 或 su root 切换到普通用户:su 用户名 或 logout
2.更新源
sudo apt-get update
源保存的文件为:/etc/apt/sources.list

(如果出现了让你输入密码的情况,就请输你之前设置的那个,按下回车,密码都是不显示在屏幕上的哈,然后如果出现了E:Invalid operation updata,没关系,重新输入sudo apt-get updata回车就好了,出现了下面那一堆就好了)
安装常用软件
1.SSH
sudo apt-get install openssh-server
查看状态:service ssh status/start/stop/restart 或:/etc/init.d/ssh status/start/stop/retsrt 实际上,service命令就是执行/etc/init.d脚本,二者功能是一样的

(这些工具以后可能会用,现在不晓得也没关系,输入命令后,出现上图,敲个y按回车就好)
2.Vim
sudo apt-get install vim

(同样输入命令按回车,按步骤就好,如果已经装了的话,会提示,像上图,这个时候,英语尤其的重要哈哈)
3.Tree
sudo apt-get install tree

4.Git
sudo apt-get install git

搭建LAMP【这才是重点】
1.安装Apache
sudo apt-get install apache2

测试: 浏览器访问的IP(即http://localhost),出现It Works!网页。 (打开火狐浏览器,在搜索栏中输入网址)



(出现上图就ok)
查看状态: service apache2
status/start/stop/restartWeb目录:/var/www 安装目录: /etc/apache2/ 全局配置: /etc/apache2/apache2.conf 监听端口: /etc/apache2/ports.conf 虚拟主机:
/etc/apache2/sites-enabled/000-default.conf
(这些以后可能会用,先不管)
2.安装MySQL
sudo apt-get install mysql-server mysql-client
1

按y
测试:mysql -u root -p


(如果安装成功的话,就会进入mysql命令行,mysql>这个样子,退出就敲quit;就ok)查看状态:service mysql status/start/stop/retart 查看监听端口的情况:netstat -tunpl或 netstat -tap
3.安装PHP
sudo apt-get install php7.0
1

(我应该是安装好了的,没安装就按步骤来就好了)
测试:php7.0 -v

4.安装其他模块
sudo apt-get install libapache2-mod-php7.0
sudo apt-get install php7.0-mysql
1


重启服务 service apache2 restart

(重启时会让你输密码,就请输入你之前设置的那个就好了)

service mysql restart


测试Apache能否解析PHP sudo vim /var/www/html/phpinfo.php

进去之后是这样

按下i 进入插入模式

然后文件中写:<?php echo phpinfo();?>,输完了按下Esc这个键

再按下Shift+: 输入一个:后输wq回车

浏览器访问:地址/phpinfo.php(即
http://localhost/phpinfo.php),出现PHP Version网页



(出现这个就ok)
5.修改权限
sudo chmod 777 /var/www

6.安装phpMyAdmin
sudo apt-get install phpmyadmin

安装:选择apache2,点击确定。下一步选择是要配置数据库,并输入密码。
(中间会让你选择,就选apache2,然后选ok那些,设置个密码,再次输入密码,就好了,记得设置个不会忘的密码哦) 创建phpMyAdmin快捷方式:sudo ln -s /usr/share/phpmyadmin /var/www/html 启用Apache mod_rewrite模块:sudo a2enmod rewrite

重启服务: service php7.0-fpm restart service apache2 restart

(依然会让你输入密码,输就好了)
测试:浏览器访问:地址/phpmyadmin(即
http://localhost/phpmyadmin)


(出现这个就ok)
7.配置Apache
Sudo vim /etc/apache2/apache2.conf
1

打开文件后
先按下i然后滑到页尾
添加: AddType application/x-httpd-php .php .htm .html AddDefaultCharset UTF-8

再按下Esc 输入:wq回车退出(w是保存q是退出)

重启Apache服务
service apache2 restart
lamp就搭建好了
相关推荐
-
PHP8种变量类型的详细讲解2025-02-22 00:32:24
-
php+apache 和 php+nginx的区别2025-02-22 00:21:27
-
PHP:与workerman结合实现定时任务2025-02-22 00:15:57
-
Nginx的Rewrite规则与实例2025-02-22 00:15:39
-
MySql中身份证字段的简单脱敏介绍2025-02-22 00:15:36