阿里云服务器ECS部署LEMP实战
阿里云服务器部署LEMP实战2019-06-24
1.云服务器初始化为Linuxserver,牢记密码。SSH登陆后查验服务器版本:
LSBVersion::core-4.1-amd64:core-4.1-noarch
DistributorID:CentOS
Description:CentOSLinuxrelease7.2.1511(Core)
Release:7.2.1511
Codename:Core
至此,LEMP的L部分完成。
2.参考文档中有两项关闭设置,我检查了一下,默认都是关闭状态,所以跳过这一步。详情见下面参考文档。
3.安装Nginx
查看Nginx版本:
nginxversion:nginx/1.12.2
4.因为PHP和Nginx配合用,所以先安装PHP,最后安装MySQL
4.1更新yum源
4.2安装PHP7.0
验证安装版本号:
PHP7.0.33(cli)(built:Dec6201822:30:44)(NTS)
Copyright(c)1997-2017ThePHPGroup
ZendEnginev3.0.0,Copyright(c)1998-2017ZendTechnologies
withZendOPcachev7.0.33,Copyright(c)1999-2017,byZendTechnologies
5.配置Nginx
配置Nginx部分颇费周折,主要是参阅参考文档,但需要做一些更改。我的nginx.conf如下.
/etc/nginx/nginx.conf
usernginx;
worker_processesauto;
error_log/var/log/nginx/error.log;
pid/run/nginx.pid;
#Loaddynamicmodules.See/usr/share/nginx/README.dynamic.
include/usr/share/nginx/modules/*.conf;
events{
worker_connections1024;
}
http{
log_formatmain'$remote_addr-$remote_user[$time_local]"$request"'
'$status$body_bytes_sent"$http_referer"'
'"$http_user_agent""$http_x_forwarded_for"';
access_log/var/log/nginx/access.logmain;
sendfileon;
tcp_nopushon;
tcp_nodelayon;
keepalive_timeout65;
types_hash_max_size2048;
include/etc/nginx/mime.types;
default_typeapplication/octet-stream;
include/etc/nginx/conf.d/*.conf;
server{
listen80default_server;
listen[::]:80default_server;
server_name_;
root/var/www/html;
indexindex.htmlindex.php;
#Loadconfigurationfilesforthedefaultserverblock.
include/etc/nginx/default.d/*.conf;
#setexpirationofassetstoMAXforcaching
location~*\.(ico|css|js|gif|jpe?g|png)(\?[0-9]+)?${
expiresmax;
log_not_foundoff;
}
location/{
#Checkifafileordirectoryindexfileexists,elserouteittoindex.php.
try_files$uri$uri//index.php;
}
location~*\.php${
fastcgi_pass127.0.0.1:9000;
includefastcgi.conf;
}
error_page404/404.html;
location=/40x.html{
}
error_page500502503504/50x.html;
location=/50x.html{
}
}
}
重启nginx
6.最后,写一个index.php放到/var/www/html下面:
<?php echo phpinfo(); ?>
可以测试访问。
7.MySQL安装配置相对简单,略了。
参考:
https://help.aliyun.com/document_detail/97251.html