LNMP代表的就是:Linux系统下Nginx+MySQL+PHP这种网站服务器架构。
Linux是一类Unix计算机操作系统的统称,是目前最流行的免费操作系统。代表版本有:debian、centos、ubuntu、fedora、gentoo等。
Nginx是一个高性能的HTTP和反向代理服务器,也是一个IMAP/POP3/SMTP代理服务器。
Mysql是一个小型关系型数据库管理系统。
PHP是一种在服务器端执行的嵌入HTML文档的脚本语言。
这四种软件均为免费开源软件,组合到一起,成为一个免费、高效、扩展性强的网站服务系统。
LNMP是什么?
是多个服务的一个组合:
L --- linux
N --- nginx 处理用户的静态请求
M --- mysql 存储数据信息(文字字符)
P --- PHP 处理用户的动态请求
yum安装LNMP:
系统:CentOS-7.5
软件:PHP-7.1 MySQL-5.7
IP地址:10.0.0.30
更新源:
yum -y install epel-release && yum update -y
安装nginx源:
yum localinstall -y http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm
安装nginx:
yum -y install nginx
启动nginx:
systemctl start nginx
systemctl enable nginx
安装mysql源:
yum -y localinstall http://dev.mysql.com/get/mysql57-community-release-el7-7.noarch.rpm
安装mysql-5.7:
yum -y install mysql-community-server mysql-community-devel
启动mysql:
systemctl start mysqld
systemctl enable mysqld
查看mysql的随机密码:
grep 'temporary password' /var/log/mysqld.log
进入mysql更改密码:
mysql -uroot -p'eZa?x2q;&;l%'
set global validate_password_policy=0;
set global validate_password_length=1;
ALTER USER 'root'@'localhost' IDENTIFIED BY 'newpassword';
安装PHP源:
rpm -Uvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm
安装PHP及依赖包:
yum install -y php71w php71w-cli php71w-common php71w-devel php71w-embedded php71w-gd php71w-mcrypt php71w-mbstring php71w-pdo php71w-xml php71w-fpm php71w-mysqlnd php71w-opcache php71w-pecl-memcached php71w-pecl-redis php71w-pecl-mongodb
查看PHP版本:
php -v
配置PHP:
#修改php工作进程由nginx用户启动
vim /etc/php-fpm.d/www.conf
user = nginx
group = nginx
启动PHP:
systemctl start php-fpm.service
systemctl enable php-fpm.service
配置nginx:
cat /etc/nginx/nginx.conf
user nginx;
worker_processes 1;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
log_format main '$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.log main;
error_log /var/log/nginx/error.log warn;
server {
listen 80;
server_name 10.0.0.30;
location / {
root html;
index index.html index.php;
}
location ~ \.php$ {
root html;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_pass 127.0.0.1:9000;
include fastcgi_params;
}
}
}
重启nginx:
systemctl restart nginx
测试PHP是否正常:
mkdir /etc/nginx/html && vim /etc/nginx/html/index.php
<?php
// Show all information, defaults to INFO_ALL
phpinfo();
// Show just the module information.
// phpinfo(8) yields identical results.
phpinfo(INFO_MODULES);
?>
浏览器访问:http://10.0.0.30/