VPS?云主机?自家做事器,启动
做事器系统哪家强 Ubuntu Server与CentOS
做事器虚拟化与ESXi安装

LNMP,即Linux Nginx MySQL PHP,是搭建动态网站的一套常用环境。还有一种叫法是LEMP。
The E in LEMP comes from the pronunciation of Nginx: Engine-X (en-juhn-ecks).The importance is the sound of the first letter rather than its written representation.Besides, LEMP is actually pronounceable and doesn’t sound like you’re just reciting letters of the alphabet.即Nginx的原意是Engine-X,取LEMP能够精确表达Nginx的读音,而且LEMP本身也可以作为一个单词发音,而LNMP则不能。
此外还有用Apache来处理HTTP要求的LAMP环境。关于Nginx和Apache的差异和优缺陷在另一篇文章进行了谈论
Nginx与Apache-HTTP引擎哪家强
这里把把稳力集中在搭建操作本身,不再过多阐述。
LinuxLinux我选用了Ubuntu Server 18.04 LTS,也可以选用centOS。关于Ubuntu Server和CentOS的谈论拜会这里。
做事器系统哪家强 Ubuntu Server与CentOS
Nginx
得益于Ubuntu出色的软件包管理软件apt-get,在Ubuntu上安装nginx非常大略。
sudo apt-get updatesudo apt-get install nginx
安装完成之后Nginx会自动启动。通过浏览器访问自己的ip,看到以下画面解释配置成功。
此时做事器已经可以相应http通信了。
把稳要通过IP进行访问,如果利用域名的话在局域网内通过域名访问可能会涌现问题,我在另一篇文章中阐明了缘故原由和解决方法。
只缘身在此山中?内网域名解析问题
Nginx配置文件
Nginx的配置文件模板保存在/etc/nginx/sites-available/default,按照nginx的设计,配置并启动一个web做事分两步:
在sites-available中给每个web做事创建一个单独的配置文件在/etc/nginx/sites-enabled中为想要启动的web做事创建链接。假设想要启动做事的网站域名是example.com,首先通过default模板在/sites-avialable下创建文件。
sudo cp /etc/nginx/sites-available/deault /etc/nginx/sites-available/example.com
创建完成后按照以下步骤编辑文件中的server{}代码块。
由于wordpress是基于php的,以是在默认起始页面中添加index.php。将server_name指定为自己的域名把php部分的代码注释取消掉,启用php忽略.htaccess文件修正完之后该当是这样:
server{ listen 80 default_server listen [::]:80 default_server root /var/www/html; index index.php index.html index.htm index.nginx-debian.html; server_name example.com location / { try_files $uri $uri/ =404; } location ~ \.php$ { include snippets/fastcgi-php.conf; fastcgi_pass unix:/run/php/php7.2-fpm.sock; } location ~ /\.ht { deny all; }}
把稳factcgi_pass后的php版本要修正本钱身的环境中实际安装的版本。我在ubuntu18.04下配置的时候nginx的default文件中给出的是php7.0-fpm.sock,而实际上通过apt安装的php是7.2。安装wordpress时涌现了形如connect() to unix:/run/php/php7.0-fpm.sock failed (11: Resource temporarily unavailable) while connecting to upstream的缺点信息。
末了在sites-available中创建链接启用配置,重启nginx。
sudo ln -s /etc/nginx/sites-available/example.com /etc/nginx/sites-enabled/example.comsudo service nginx restart
MySQL
sudo apt-get install mysql-server
安装完成之后为wordpress创建一个数据库和一个用户。如果要在不同目录下安装多个wordpress也是同理,为每一个wordpress创建一个独立的数据库和用户即可。假设要创建的数据库信息如下
数据库名wordpressDB用户名wpuser密码password
sudo mysql -u root -pcreate database wordpressDB;create user 'wpuser'@'localhost' identified by 'password';grant all on wordpressDB. to 'wpadmin'@'localhost'
之后安装wordpress的时候会哀求输入这些信息。
PHPsudo apt-get install php-fpm php-mysql
这样动态网站所须要的环境就搭建完成了。下一节:安装WordPress。