CentOS7安装LNMP环境
以下配置主要用于本地测试,部署服务器请自行优化。centos7.0 64位 关闭SELINUX #vi /etc/selinux/config 修改 SELINUX=disabled systemctl disable firewalld.service#禁止firewall开机启动 (需要重启才生效)一、安装mariadb
·
2016.7.19更新
说明:本安装记录为阿里云香港空间,CentOS7.064位
关闭SELINUX
#vi /etc/selinux/config
修改 SELINUX=disabled
开启端口 需要开启80 3306 9000 6379 1723
#firewall-cmd --zone=public --add-port=80/tcp --permanent
#firewall-cmd --zone=public --add-port=80/udp --permanent
#firewall-cmd --zone=dmz --add-port=80/tcp --permanent
#firewall-cmd --zone=dmz --add-port=80/udp --permanent
#firewall-cmd --zone=public --add-port=3306/tcp --permanent
#firewall-cmd --zone=public --add-port=3306/udp --permanent
#firewall-cmd --zone=dmz --add-port=3306/tcp --permanent
#firewall-cmd --zone=dmz --add-port=3306/udp --permanent
#firewall-cmd --zone=public --add-port=9000/tcp --permanent
#firewall-cmd --zone=public --add-port=9000/udp --permanent
#firewall-cmd --zone=dmz --add-port=9000/tcp --permanent
#firewall-cmd --zone=dmz --add-port=9000/udp --permanent
#firewall-cmd --zone=public --add-port=6379/tcp --permanent
#firewall-cmd --zone=public --add-port=6379/udp --permanent
#firewall-cmd --zone=dmz --add-port=6379/tcp --permanent
#firewall-cmd --zone=dmz --add-port=6379/udp --permanent
#firewall-cmd --zone=public --add-port=1723/tcp --permanent
#firewall-cmd --zone=public --add-port=1723/udp --permanent
#firewall-cmd --zone=dmz --add-port=1723/tcp --permanent
#firewall-cmd --zone=dmz --add-port=1723/udp --permanent
#firewall-cmd --reload
#firewall-cmd --zone=public --list-ports
#firewall-cmd --zone=dmz --list-ports
#systemctl restart firewalld.service
一、安装mariadb
#yum install mariadb mariadb-server #询问是否要安装,输入Y即可自动安装,直到安装完成
#systemctl start mariadb.service #启动MariaDB
#systemctl stop mariadb.service #停止MariaDB
#systemctl restart mariadb.service #重启MariaDB
#systemctl enable mariadb.service #设置开机启动
#cp /usr/share/mysql/my-huge.cnf /etc/my.cnf #拷贝配置文件(注意:如果/etc目录下面默认有一个my.cnf,直接覆盖即可)
mysql_secure_installation
回车,根据提示输入Y
输入2次密码,回车
根据提示一路输入Y
最后出现:Thanks for using MySQL!
MySql密码设置完成,重新启动 MySQL:
#systemctl restart mariadb.service
允许远程连接 进入mysql
#mysql -uroot -p
>use mysql;
>GRANT ALL ON *.* TO root@'%' IDENTIFIED BY 'MariaDBPassword' WITH GRANT OPTION;
>quit
重启mariadb
#systemctl restart mariadb.service
二、安装 NginX
#yum install nginx
启动
#systemctl start nginx.service
自动启动
#systemctl enable nginx.service
#mkdir /data
#mkdir /data/logs
#mkdir /data/logs/nginx
#chown -R nginx:nginx /data/logs/nginx
配置
#vi /etc/nginx/nginx.conf
error_log /data/logs/nginx/error.log;
events {
worker_connections 1024;
use epoll; //增加此行 如果你使用Linux 2.6+,你应该使用epoll。
}
http {
access_log /data/logs/nginx/access.log main;
三、安装php
#yum install php php-fpm php-mysql php-gd libjpeg* php-ldap php-odbc php-pear php-xml php-xmlrpc php-mbstring php-bcmath php-mhash
启动php-fpm
#systemctl start php-fpm.service
自动启动php-fpm
#systemctl enable php-fpm.service
四、配置PHP、NginX
1、配置PHP
# vi /etc/php.ini
修改如下内容 (可根据情况修改)
memory_limit = 256M
upload_max_filesize = 8M
-----------------------------------
session.save_path = "/tmp"
将其改为
session.save_path = "/data/sessions"
修改
session.auto_start = 1
保存,
然后
#mkdir /data/sessions
#chown -R daemon:daemon /data/sessions
#chmod -R 777 /data/sessions
#chown -R daemon:daemon /data/logs
#chmod -R 777 /data/logs
2、配置NginX
#vi /etc/nginx/nginx.conf
修改server
#phplee.com
server {
listen 80;
server_name www.phplee.com phplee.com;
root /data/www/phplee.com/www;
index index.html index.htm index.php;
error_page 404 /404.html;
location = /404.html {
return 404 'Sorry, File not Found!';
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html; # windows dir
}
location / {
try_files $uri @rewrite;
}
location @rewrite {
set $static 0;
if ($uri ~ \.(css|js|jpg|jpeg|png|gif|ico|woff|eot|svg|css\.map|min\.map)$) {
set $static 1;
}
if ($static = 0) {
rewrite ^/(.*)$ /index.php?s=/$1;
}
}
location ~ /Uploads/.*\.php$ {
deny all;
}
location ~ \.php/ {
if ($request_uri ~ ^(.+\.php)(/.+?)($|\?)) { }
fastcgi_pass 127.0.0.1:9000;
include fastcgi_params;
fastcgi_param SCRIPT_NAME $1;
fastcgi_param PATH_INFO $2;
fastcgi_param SCRIPT_FILENAME $document_root$1;
}
location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
location ~ /\.ht {
deny all;
}
}
五、安装 redis
更新源
#wget -r --no-parent -A 'epel-release-*.rpm' http://dl.fedoraproject.org/pub/epel/7/x86_64/e/
#rpm -Uvh dl.fedoraproject.org/pub/epel/7/x86_64/e/epel-release-*.rpm
安装
#yum -y install redis php-redis
启动及开机启动
#systemctl start redis.service
#systemctl enable redis.service
进入测试
#redis-cli
127.0.0.1:6379> set foo bar
OK
127.0.0.1:6379> get foo
"bar"
127.0.0.1:6379> quit
编辑
#vi /etc/redis.conf
maxmemory 100mb //最大内存
appendonly yes //启用持久化
更多推荐
已为社区贡献1条内容
所有评论(0)