centos搭建LNMP环境
来源:互联网 发布:三菱plc3u编程手册 编辑:程序博客网 时间:2024/04/25 02:55
欢迎访问我的个人博客网站:http://www.yanmin99.com/
一、LNMP介绍
- LNMP是Linux、Nginx、MySQL和PHP的缩写,这个组合是最常见的WEB服务器的运行环境之一
二、Nginx安装
1、通过yum安装Nginx
sudo yum install nginx
2、启动Nginx
service nginx start
3、查看Nginx是否启动成功
A、通过netstat查看80端口是否监听
[root@iZrj98p4hhys0y9fdxmcy4Z yanmin]# netstat -ntlpActive Internet connections (only servers)Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program nametcp 0 0 0.0.0.0:8989 0.0.0.0:* LISTEN 1415/pythontcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 11295/nginx
B、通过浏览器访问
http://<外网IP地址>
,确定Nginx是否启动
5、通过chkconfig设置开机启动
sudo chkconfig nginx on
4、查看Nginx版本
[root@iZrj98p4hhys0y9fdxmcy4Z yanmin]# nginx -vnginx version: nginx/1.12.1
三、MySQL安装
1、通过yum直接安装MySQL
sudo yum install mysql-server
2、(可以跳过这个步骤)启动MySQL默认脚本,初始化MySQL,安装提示进行设置
A、执行
mysql_secure_installation
sudo /usr/bin/mysql_secure_installation
B、首先提示输入当前的root密码
Enter current password for root (enter for none):
C、初始root密码为空,我们直接敲回车进行下一步
Set root password? [Y/n]
D、设置root密码,默认选项为Yes,我们直接回车,提示输入密码,在这里设置您的MySQL的root账户密码
Remove anonymous users? [Y/n]
E、是否移除匿名用户,默认选项为Yes,建议按默认设置,回车继续。
Remove test database and access to it? [Y/n]
F、是否禁止root用户远程登录?如果您只在本机内访问MySQL,建议按默认设置,回车继续
Disallow root login remotely? [Y/n]
G、是否删除test用的数据库和权限? 建议按照默认设置,回车继续
Remove test database and access to it? [Y/n]
H、是否重新加载权限表?因为我们上面更新了root的密码,这里需要重新加载,回车
Reload privilege tables now? [Y/n]
3、启动MySQL
mysql -uroot -p
4、查看MySQL是否启动,查看3306端口是否监听
[root@iZrj98p4hhys0y9fdxmcy4Z yanmin]# netstat -ntlpProto Recv-Q Send-Q Local Address Foreign Address State PID/Program nametcp 0 0 0.0.0.0:8989 0.0.0.0:* LISTEN 1415/pythontcp 0 0 0.0.0.0:3306 0.0.0.0:* LISTEN 11532/mysqld
5、查看MySQL的版本
[root@iZrj98p4hhys0y9fdxmcy4Z yanmin]# mysql -Vmysql Ver 14.14 Distrib 5.1.73, for redhat-linux-gnu (x86_64) using readline 5.1
四、PHP安装
1、通过yum安装php-mysql、php-fpm
sudo yum install php php-fpm php-mysql
2、安装以后启动php-fpm
sudo service php-fpm start
3、查看php-fpm是否启动,查看9000端口是否启动
[root@iZrj98p4hhys0y9fdxmcy4Z yanmin]# netstat -ntlpProto Recv-Q Send-Q Local Address Foreign Address State PID/Program nametcp 0 0 0.0.0.0:8989 0.0.0.0:* LISTEN 1415/pythontcp 0 0 127.0.0.1:9000 0.0.0.0:* LISTEN 11642/php-fpm
4、设置开机启动
sudo chkconfig php-fpm on
五、验证LNMP
1、在Nginx的
/etc/nginx/conf.d
文件夹中创建php.conf文件,设置端口为8000,如下:通过
vim /etc/nginx/conf.d/php.conf
打开文件,输入一下内容保存。server { listen 8000; # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000 # location ~ \.php$ { root /usr/share/php; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; }}
Nginx修改配置,需要重启
sudo service nginx reload
或者service nginx restart
2、在php的目录
/usr/share/php
文件夹中创建phpinfo.php文件- 通过
vim /etc/nginx/conf.d/php.conf
打开文件,输入以下上内容保存。<?php echo phpinfo(); ?>
- 通过
3、验证防火墙是否开启,如果请把8000端口加入白名单
//测试可以直接关闭防火墙[root@iZrj98p4hhys0y9fdxmcy4Z yanmin]# service iptables stopiptables: Setting chains to policy ACCEPT: filter nat [ OK ]iptables: Flushing firewall rules: [ OK ]iptables: Unloading modules: [ OK ]//查看防火墙状态[root@iZrj98p4hhys0y9fdxmcy4Z yanmin]# service iptables statusiptables: Firewall is not running.
4、通过浏览器验证,打开
http://<外网IP地址>:8000/phpinfo.php
,看是否显示php信息
- CentOS LNMP环境搭建
- Centos搭建LNMP环境
- Centos搭建lnmp环境
- centos搭建LNMP环境
- CentOS搭建LNMP环境
- centos搭建lnmp环境
- CentOS LNMP 环境搭建记录
- centos 6.5 搭建lnmp环境
- CentOS 6.6搭建LNMP环境
- centOS 7 lnmp环境搭建
- centos之lnmp环境搭建
- centos 7 搭建LNMP环境
- CentOS下LNMP环境搭建
- Centos 中搭建LNMP环境
- Centos 7.3搭建LNMP环境
- Centos 7.3搭建LNMP环境
- Centos下搭建LNMP环境
- centos下快速搭建LNMP开发环境
- mysql与eclipse连接以及封装过程
- 题目5 发工资遇到的最优问题 。
- centos安装gitlab详解-2017
- JSP 中EL表达式用法详解
- 机器学习
- centos搭建LNMP环境
- netty实现websocket
- Struts2项目实战 微云盘 效果展示
- POJ3692:Kindergarten(最大团)
- Java多线程(上篇)
- 函数式编程(2) 高阶函数(转自: 周见智)
- 机器学习
- PHP POSIX扩展正则表达式函数
- logistic regression 处理鸢尾花数据集