您的位置:首页 > 运维架构 > Apache

Ubuntu安装PHP,MySQL,Apache

2017-01-19 20:24 337 查看
LAMP:开源软件的集合,包括Linux, Apache, MySQL, PHP.

详细 https://www.digitalocean.com/community/tutorials/how-to-install-linux-apache-mysql-php-lamp-stack-on-ubuntu-16-04
安装

安装环境 : Ubuntu 16.04

1,Install Apache

a
sudo apt-get update

sudo apt-get install apache2


Y+Enter

b 设置全局服务名,去掉语法警告
sudo nano /etc/apache2/apache2.conf

   /etc/apache2/apache2.conf 文件末尾添加 ... ServerName server_domain_or_IP

   server_domain_or_IP get : ip addr show eth0 | grep inet | awk '{ print $2; }' | sed 's/\/.*$//'
sudo apache2ctl configtest // Syntax OK

c restart
sudo systemctl restart apache2

d 设置防火墙

sudo ufw app list

 Output

 Available applications:

   Apache

   Apache Full

   Apache Secure

   OpenSSH

sudo ufw app info "Apache Full"

 Output

 Profile: Apache Full

 Title: Web Server (HTTP,HTTPS)

 Description: Apache v2 is the next generation of the omnipresent Apache web

 server.

 Ports:

   80,443/tcp

 

sudo ufw allow in "Apache Full"

http://your_server_IP_address   //default page

2,Install MySQL

a

sudo apt-get install mysql-server

b 安全脚本

sudo mysql_secure_installation

设置 MySQL root password

     VALIDATE PASSWORD PLUGIN:https://dev.mysql.com/doc/refman/5.6/en/validate-password-plugin.html

3,Install PHP

a

sudo apt-get install php libapache2-mod-php php-mcrypt php-mysql

b,设置Apache先找indec.php

sudo nano /etc/apache2/mods-enabled/dir.conf

 /etc/apache2/mods-enabled/dir.conf

 //index.php放在index.html前面

 <IfModule mod_dir.c>

  DirectoryIndex index.html index.cgi index.pl index.php index.xhtml index.htm

 </IfModule>

c 重启Apache

sudo systemctl restart apache2

sudo systemctl status apache2 // just check

d 查看PHP的可安装组件

apt-cache search php- | less

apt-cache show php-cli  //php-cli的详细信息

sudo apt-get install php-cli //安装php-cli

4,Test PHP on Web Server

sudo nano /var/www/html/info.php

 info.php

 //编辑php界面显示信息

 <?php

 phpinfo();
http://your_server_IP_address/info.php  //也可以浏览器查看

sudo rm /var/www/html/info.php   //删除文件

使用sudo进行安装时可能遇到问题

E: Could not open lock file /var/lib/dpkg/lock - open (13: Permission denied)

E: Unable to lock the administration directory (/var/lib/dpkg/), are you root?

ubuntu系统默认root用户不能登陆,密码也是空的。

解决

1,用root用户登录。

terminal:sudo passwd root,

回车,当前登录用户密码

回车,root用户密码,两边,千万记住!

2,更新软件

因为是刚安装unbuntu,所以选择了升级下

terminal:sudo su //切换到root, su user 切换回用户

su:switch user

terminal:sudo apt-get update && sudo apt-get upgrade //然后y
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: