服务器:阿里云ECS
系统:centos7.4 64位
先更新yum源:
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
rpm -Uvh http://dev.mysql.com/get/mysql57-community-release-el7-9.noarch.rpm
然后安装Nginx:
yum -y install nginx
Nginx安装成功后,安装MySQL:
yum -y install mysql-community-server
MySQL安装好后,安装PHP7:
yum -y install php70w-devel php70w.x86_64 php70w-cli.x86_64 php70w-common.x86_64 php70w-gd.x86_64 php70w-ldap.x86_64 php70w-mbstring.x86_64 php70w-mcrypt.x86_64 php70w-pdo.x86_64 php70w-mysqlnd php70w-fpm php70w-opcache
如果要安装php7.4,这段修改为:
yum -y install php74-php-devel php74-php.x86_64 php74-php-cli.x86_64 php74-php-common.x86_64 php74-php-gd.x86_64 php74-php-ldap.x86_64 php74-php-mbstring.x86_64 php74-php-mcrypt.x86_64 php74-php-pdo.x86_64 php74-php-mysqlnd php74-php-fpm php74-php-opcache
这样,环境基本安装完毕。接下来是配置:
启动MySQL
systemctl start mysqld
设置开机启动:
systemctl enable mysqld
MySQL安装的时候会生成一个默认的密码,查看默认密码:
grep 'temporary password' /var/log/mysqld.log
用这个默认密码登录MySQL,修改root密码为自己的密码:
mysql -uroot -p
mysql> set password for 'root'@'localhost'=password('123abc');
修改完成后重启MySQL。
默认配置文件路径:
配置文件:/etc/my.cnf
日志文件:/var/log/mysqld.log
服务启动脚本:/usr/lib/systemd/system/mysqld.service
socket 文件:/var/run/mysqld/mysqld.pid
接下来是Nginx的配置,先查看防火墙:
systemctl status firewalld
如果显示 active (running),则需要调整防火墙规则的配置(请自行百度)。
然后在/etc/nginx/conf.d/里面创建自己的站点解析配置:
server {
listen 80;
server_name www.abc.com;
root /home/www/abc;
index index.php index.html index.htm;
location / {
if (!-e $request_filename) {
rewrite ^/(.*)$ /index.php?$1 last;#去除url中的index.php
}
}
location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
如果担心写的不对,可以用
/usr/sbin/nginx -t
来检查Nginx配置是否正确。
保存后重启Nginx,然后启动PHP-FPM,设置PHP-FPM、Nginx开机启动:
systemctl enable nginx
访问自己的网址,如果出现一下页面,说明环境搭建成功:
然后在网址根目录里新建一个info.php,里面写phpinfo();,之后再访问:域名/info.php如果出现一下页面,说明PHP-FPM没有问题:
至此,简单的LNMP环境搭建成功!
参考:
https://blog.csdn.net/lovemyself196221/article/details/79491602
https://www.cnblogs.com/phpshen/p/6222935.html
vue2 Implicit conversion from float int loses precision php8Implicit Mysql8新增用户,mysql8配置权限,mysql8配置,mysql8配置文件 Linux命令,scp,scp命令,Linux复制 git commit git add centos git 搭建FTP,Linux FTP,禁止FTP登录ssh 上传文件,阿里云OSS上传,文件上传到OSS,OSS文件上传,OSS上传 微信支付,微信支付V3,PHP微信支付,微信nativePay支付,微信jsapi支付 微信支付,微信支付V3,PHP微信支付 bootstrap4 modal, lavarel The subversion command line tools are no longer provided by Xcode. 银联支付,tp5.1银联支付 支付宝即时到账,PHP支付宝 system libzip must be upgraded to version >= 0.11 CMake 3.0.2 or higher is required