一个LEMP软件环境是通常安装在一起,使一台服务器主机动态网站和网络应用的一组开源软件。该术语实际上是其表示的缩写Linux下操作系统,与È Nginx的Web服务器(其取代了LAMP环境的Apache的角色)。该网站的数据存储在一个MySQL数据库(使用MariaDB的),以及动态内容通过处理PHP。
在本教程中,我们将得到一个堆栈LEMP安装在CentOS的VPS 7。CentOS的将履行我们的第一个要求:Linux操作系统
添加CentOS的7 EPEL库,打开终端,并使用下面的命令:sudo yum install epel-release
安装Nginxsudo yum install nginx
在VPS启动Nginxsudo systemctl start nginx
验证是否成功
打开浏览器,输入的的iphttp://server_domain_name_or_IP/
您将看到默认的CentOS 7 Nginx的网页,其中有提供信息和测试目的。
它应该是这个样子:
成功启动后,设置开机自动启动sudo systemctl enable nginx
MariaDB的是MySQL关系数据库的一个社区开发分支,MySql被Oracl收购后闭源,MySql的开发者拉取其分支继续开源。
安装MariaDBsudo yum install mariadb-server mariadb
启动MariaDBsudo systemctl start mariadb
运行安全脚本,激活MariaDBsudo mysql_secure_installation
要求您输入当前root密码
已经刚刚安装MariaDB,因此直接enter
然后按Y,要你设置密码时,输入你想设置的数据库密码
mysql_secure_installation prompts:
Enter current password for root (enter for none):
OK, successfully used password, moving on...
Setting the root password ensures that nobody can log into the MariaDB
root user without the proper authorisation.
New password:
password
Re-enter new password:
password
Password updated successfully!
Reloading privilege tables..
... Success!
对于剩余的问题,您应该简单地通过每一个提示,点击“ENTER”键接受默认值。
设置开机启动MariaDBsudo systemctl enable mariadb
sudo yum install php70u-fpm-nginx php70u-cli php70u-mysqlnd
配置php-fpmsudo nano /etc/php-fpm.d/www.conf
查找包含listen = 127.0.0.1:9000
这行,用;
注释掉
并打开listen = /run/php-fpm/www.sock
这行
; The address on which to accept FastCGI requests.
; Valid syntaxes are:
; 'ip.add.re.ss:port' - to listen on a TCP socket to a specific IPv4 address on
; a specific port;
; '[ip:6:addr:ess]:port' - to listen on a TCP socket to a specific IPv6 address on
; a specific port;
; 'port' - to listen on a TCP socket to all addresses
; (IPv6 and IPv4-mapped) on a specific port;
; '/path/to/unix/socket' - to listen on a unix socket.
; Note: This value is mandatory.
; listen = 127.0.0.1:9000
; WARNING: If you switch to a unix socket, you have to grant your webserver user
; access to that socket by setting listen.acl_users to the webserver user.
listen = /run/php-fpm/www.sock
退出并保存文件。在nano
,你可以通过按做到这一点按Ctrl-X退出,y 确认
设置listen.acl_users = nginx
; When POSIX Access Control Lists are supported you can set them using
; these options, value is a comma separated list of user/group names.
; When set, listen.owner and listen.group are ignored
;listen.acl_users = apache,nginx
;listen.acl_users = apache
listen.acl_users = nginx
listen.acl_groups = nginx
退出并保存文件。在nano
,你可以通过按做到这一点按Ctrl-X退出,y 确认
重启php-fpm和nginxsudo systemctl restart php-fpm
sudo systemctl restart nginx
设置开机启动php-fpmsudo systemctl enable php-fpm
编辑nginx 默认站点配置文件sudo nano /etc/nginx/conf.d/default.conf
寻找开头的块location ~ \.php$ {
。在此块中,查找fastcgi_pass
指令。注释或删除这条线,并将其替换为fastcgi_pass php-fpm
,这将参考中所定义的上php-fpm.conf
location ~ \.php$ {
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
#
fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock;
fastcgi_pass php-fpm;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
重启php-fpm和nginxsudo systemctl restart php-fpm
sudo systemctl restart nginx