Centos7搭建LEMP
1.Nginx通过源码安装已经启动
[root@localhost conf]# systemctl status nginx
● nginx.service - nginx - high performance web server
Loaded: loaded (/usr/lib/systemd/system/nginx.service; enabled; vendor preset: disabled)
Active: active (running) since 二 2017-07-11 08:36:24 CST; 2h 6min ago
Docs: http://nginx.org/en/docs/
Main PID: 1569 (nginx)
CGroup: /system.slice/nginx.service
├─1569 nginx: master process /usr/local/nginx/sbin/nginx
└─1571 nginx: worker process
7月 11 08:36:23 localhost.localdomain systemd[1]: Starting nginx - high per...
7月 11 08:36:24 localhost.localdomain systemd[1]: PID file /usr/local/nginx...
7月 11 08:36:24 localhost.localdomain systemd[1]: Started nginx - high perf...
Hint: Some lines were ellipsized, use -l to show in full.
2.yun安装MySQL和PHP
[root@localhost conf]# yum install mariadb-server mariadb -y
设置开机自启动和启动Mariadb
[root@localhost conf]# systemctl enable mariadb
[root@localhost conf]# systemctl start mariadb
运行mysql_secure_installation会执行几个设置:
a)为root用户设置密码
b)删除匿名账号
c)取消root用户远程登录
d)删除test库和对test库的访问权限
e)刷新授权表使修改生效
[root@localhost conf]# mysql_secure_installation
测试
[root@localhost conf]# mysql -uroot -p -e"show databases;"
Enter password:
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
+--------------------+
[root@localhost conf]# yum install php php-fpm php-mysql -y
[root@localhost conf]# systemctl enable php-fpm
[root@localhost conf]# systemctl start php-fpm
3.配置LEMP
查看httpd状态
[root@localhost conf]# systemctl status httpd
● httpd.service - The Apache HTTP Server
Loaded: loaded (/usr/lib/systemd/system/httpd.service; disabled; vendor preset: disabled)
Active: inactive (dead)
Docs: man:httpd(8)
man:apachectl(8)
若为开机自启动enable,应禁用掉
[root@localhost conf]# systemctl disable httpd
配置Nginx
配置 nginx 虚拟主机,使得 nginx 可以通过 PHP-FPM 来处理 PHP 的任务
由于我的Nginx是通过源码安装,配置文件目录不同,yum安装文件目录在/etc/nginx/conf.d/default.conf
配置文件进行备份
[root@localhost ~]# cp /usr/local/nginx/conf/nginx.conf{,.bak}
[root@localhost ~]# vim /usr/local/nginx/conf/nginx.conf
server {
listen 80; <-监听地址和端口
server_name localhost; <-网站域名
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
root /usr/local/nginx/html; <-网站根目录
index index.html index.htm;
}
#error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/local/nginx/html;
}
# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
# proxy_pass http://127.0.0.1;
#}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
location ~ \.php$ {
root /usr/local/nginx/html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;;
include fastcgi_params;
}
}
配置PHP
接下来,让我们对 PHP 的配置文件 /etc/php.ini 做自定义设置。在 /etc/php.ini 文件中增加以下两行。
cgi.fix_pathinfo=0
date.timezone ="Asia/shanghai"
[root@localhost conf]# systemctl restart nginx
[root@localhost conf]# systemctl restart php-fpm
测试
[root@localhost conf]# echo "<?php phpinfo();?>" >/usr/local/nginx/html/test.php
打开浏览器,输入 http://nginx的IP地址/test.php


浙公网安备 33010602011771号