Ubuntu搭建LNMP环境

1. 安装PHP7.1

安装前如已有其他PHP版本

sudo a2dismod php5
sudo a2enmod php7.1

执行安装

sudo apt-get install software-properties-common
sudo add-apt-repository ppa:ondrej/php
sudo apt update
sudo apt install php7.1-fpm php7.1-mcrypt php7.1-cli php7.1-xml php7.1-mysql php7.1-gd php7.1-imagick php7.1-recode php7.1-tidy php7.1-xmlrpc php7.1-mbstring php7.1-zip php7.1-curl

 

2. 安装Mysql

sudo apt install mysql-server
// 查看是否安装成功
netstat -tap | grep mysql

// 初始化mysql
mysql_secure_installation
// 1. 不安装验证密码插件
Press y|Y for Yes, any other key for No:N
// 2. 设置root管理员数据库密码
Please set the password for root here.
New password:   # 输入密码
Re-enter new password:   # 再次输入密码
// 3. 删除匿名账户
Remove anonymous users? (Press y|Y for Yes, any other key for No) : y
// 4. 不禁止root管理员从远程登录
Disallow root login remotely? (Press y|Y for Yes, any other key for No) : N
// 5. 删除test数据库并取消对它的访问权限
Remove test database and access to it? (Press y|Y for Yes, any other key for No) : y
// 6. 刷新授权表,让初始化后的设定立即生效
Reload privilege tables now? (Press y|Y for Yes, any other key for No) : y

// 检查mysql服务状态:
systemctl status mysql

// 修改mysqld.cnf
vim /etc/mysql/mysql.conf.d/mysqld.cnf
bind-address = 127.0.0.1 改为 # bind-address = 127.0.0.1
// 进入mysql
sudo mysql -u root -p
// 设置远程访问授权命令
mysql> grant all on *.* to root@'%' identified by '你的密码' with grant option;
// 刷新权限
mysql> flush privileges;

// 重启Mysql
sudo systemctl restart mysql

 

3. 安装Nginx

sudo apt-get install ngnix

配置域名时候

fastcgi_pass unix:/run/php/php7.1-fpm.sock;

 

4. 安装Redis

sudo apt-get install redis-server

修改redis.conf

sudo vi /etc/redis/redis.conf
bind 127.0.0.1 ::1 改为 bind 127.0.0.1

 

5. 重启命令

sudo service php7.1-fpm restart // 重启php-fpm
systemctl restart mysql // 重启mysql
sudo service nginx restart // 重启nginx
sudo /etc/init.d/redis-server restart // 重启redis

 

posted @ 2019-10-22 19:50  苦瓜糖水  阅读(152)  评论(0编辑  收藏  举报