ubuntu 上安装 apache,mysql,php记录

安装 mysql php apache

sudo apt-get install mysql-server mysql-common

先用管理员密码登入,下面查询管理员密码
sudo cat /etc/mysql/debian.cnf

mysql -u debian-sys-maint -p
Enter password: #输入文件中的密码即可成功登陆(password)

修改密码:
mysql> update mysql.user set authentication_string=password('password') where user='root'and Host = 'localhost';

退出后一定要重启服务
sudo /etc/init.d/mysql restart

然后再重新登入(务必前面带sudo)
sudo mysql -u root -p

安装apache

sudo apt-get install apache2

sudo apt-get install mysql-server
sudo apt-get install mysql-client

sudo apt-get install php

安装mysql扩展

sudo apt-get install php-mysql

安装必要扩展

sudo apt-get install php-pear

sudo apt-get install php-curl

sudo apt-get install php-json

sudo apt-get install php-cgi

修改配置后要重启apache
sudo /etc/init.d/apache2 restart

注意:只有本机能访问,要防火墙开放80或者8080端口,根据需要来

修改端口 所有 80 改 8080,如果需要的话
sudo nano /etc/apache2/ports.conf
sudo nano /etc/apache2/sites-enabled/000-default.conf

修改根目录
sudo nano /etc/apache2/apache2.conf
复制一个节点
将/var/www/ 改为 /home/zmy/www(这个不改,会提示没有权限访问)
然后在节点中添加DirectoryIndex index.php index.phtml index.html index.htm
这个index.php放前面优先级最高
<Directory /home/zmy/www/>
        Options Indexes FollowSymLinks
        AllowOverride None
        Require all granted
        DirectoryIndex index.php index.phtml index.html index.htm
</Directory>

同样在/etc/apache2/sites-enabled/000-default.conf中
修改  DocumentRoot /home/zmy/www/html

chmod -R 775 /home/zmy/www/html


关于防火墙配置
用命令iptables -L -n 查看防火墙配置规则,看看想要的那个端口是不是开放了
开放下面端口:
iptables -A INPUT -p tcp -m tcp --dport 8080 -j ACCEPT
但是通常不会做add操作,因为accept规则必须在reject规则前,否则这个accept无效
用插入指令
sudo iptables -I INPUT 3 -p tcp -m tcp --dport 8080 -j ACCEPT (表示在第三行插入这条规则)

当添加错了可以用删除操作
iptables -D INPUT 3(表示要删除第三条) 

最后保存添加的规则
sudo iptables-save > /etc/iptables.up.rules  (但是这个会提示权限不够,哪怕sudo)
需要切换成root用户

设置root密码 sudo passwd
然后通过命令 su root进入
再执行就ok了iptables-save > /etc/iptables.up.rules


https://www.aliyun.com/jiaocheng/166105.html
https://yq.aliyun.com/articles/517339
http://blog.51yip.com/linux/1404.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值