CentOS安装LNMP步骤
注意: 要安装wget工具
若提示以下错误信息
Cannot find a valid baseurl for repo: base/7/x86_64
这表示无法链接到网线,解决办法如下:
cd /etc/sysconfig/network-scripts
ls -a
vi ifcfg-en文件
修改ONBOOT=yes,重启服务器网络service network restart
-
MySQL安装
- wget
- rpm -ivh mysql-community-release-el7-5.noarch.rpm
- yum update
- yum install mysql-server
完成后,MySQL默认安装到/var/lib/mysql目录下。
systemctl start mysqld # 启动 MySQL
systemctl enable mysqld # 开机启动ySMySQL
-
安装Nginx
若有安装Apache,先卸载
- service httpd stop
- systemctl disable httpd
- yun remove httpd
再安装Nginx并且设置为开机启动
- yum install epel-release
- yum -y install niginx
- systemcrl start nginx #启动nginx
- systemctl enable nginx #开机启动
开放CentOs防火墙端口
firewall-cmd –zone=public –add-port=80/tcp –permanent
-
安装PHP7.*
- rpm -ivh # 安装 EPEL 源 可以用yum -y install epel-release
- rpm -Uvh # 安装 Webstatic 源
- yum install php70w php70w-common php70w-fpm php70w-opcache php70w-mysqlnd php70w-gd php70w-mbstring # PHP 5.3.0以上推荐使用mysqlnd驱动,而不是msyql
- 要PHP7.1把php70w 改成php71w
-
配置PHP-FPM
- 打开/etc/php.ini,删除cgi.fix_pathinfo前面的;注释符,再赋值为0
-
打开/etc/php-fpm.d/www.conf
- 将 127.0.0.1:9000 改为 php-fpm.sock 文件
- 取消 listen.owner和listen.group前面的注释
- 将user和group的值由apache改为nginx
-
启动PHP-FPM,并且设置为开机启动
- systemctl start php-fpm
- systemctl enable php-fpm
-
修改生成socket文件权限
- chmod go+rw /var/run/php-fpm/php-fpm.sock
-
配置NGINX
- Nginx 的配置文件是:/etc/nginx/nginx.conf,使用 vi 打开
- 根据情况调整worker_processes和keepalive_timeout
- 设置默认主页index index.php index.html index.htm;
-
PHP脚本转发至PHP-FPM解析
location ~ \.php$ { try_files $uri =404; fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; fastcgi_index index.php; include fastcgi_params; }
- 重启Nginx
nginx -t # 检查配置文件语法 systemctl reload nginx
-
TCP链接
- 只要把sock全部替换127.0.0.1:9000即可( /etc/php-fpm.d/www.conf,设置 listen 值)
- 修改 /etc/nginx/nginx.conf 如上即可
- 重启nginx就可以了