LNMP是Linux、Nginx、MySQL和PHP的缩写,这个组合是最常见的WEB服务器的运行环境之一。
本文适用于CentOS 6.x版本。
安装准备
使用最新的epel-release源安装
yum install epel-release -y yum install nginx php-fpm php-mysql mysql-server -y
服务启动
- 重启服务
service mysqld restart service nginx restart service php-fpm start
- 开机启动
chkconfig nginx on chkconfig mysqld on chkconfig php-fpm on
配置Nginx
- 配置文件
Nginx默认配置文件在/etc/nginx/目录下,默认日志路径是/var/log/nginx/error.log,默认网站目录在/usr/share/nginx/html
- 目录索引
Apache默认是开启目录索引,如果需要Nginx开启目录索引,需要修改配置文件/etc/nginx/conf.d/default.conf,在需要开启索引的路径,添加如下参数:
location /td/ {
autoindex on;
autoindex_exact_size on;
autoindex_localtime on;
alias /var/lib/transmission/Downloads/;
}
配置PHP
- 设置php session的目录
mkdir /var/lib/php/session/ chown -R apache:apache /var/lib/php/session/ - 修改Nginx配置,让Nginx把php文件交给php-fpm处理
- 重启Nginx,配置生效
编辑 /etc/nginx/conf.d/default.conf 文件,在需要的地方添加如下代码:
location ~ .php$ {
root /usr/share/nginx/html;
try_files $uri =404;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
nginx -s reload
#或者
service nginx restart
配置Mysql
- 启动Mysql设置向导,设置root密码和权限
- 登录mysql
- 关闭外网3306端口的监听
- 配置文件
service mysqld restart
/usr/bin/mysql_secure_installation
mysql -uroot -p
MySQL安装完成后默认监听外网的3306端口,有一定的安全隐患,我们通过编辑MySQL的配置文件,将MySQL服务修改为监听内网的3306端口,这样就不会被外界探测到,编辑/etc/my.cnf文件,在[mysqld]中增加一行:
bind-address=127.0.0.1
再重启服务,使得文件生效
参数配置:/etc/my.cnf
错误日志:/var/log/mysqld.log
原创文章,转载请注明:转载自Web开发笔记 | CentOS6搭建LNMP环境
本文链接地址:https://www.magentonotes.com/centos6-install-configure-lnmp.html
Comments on this entry are closed.