Centos下搭建LNMP(Linux+MySQL+nginx+PHP)

拿到服务器之后,怎样搭建一个简单的服务器?

如果是Linux的话,putty会很实用,所以建议用putty进行远程登陆


1.安装Nginx

#yum install nginx #配置文件处于/etc/nginx
#systemctl start nginx #启动nginx
#systemctl enable nginx.service # 设置为开机启动

测试:123.206.57.252 打开公网IP可看到nginx的页面。

2.安装MySQL

#yum repolist enabled | grep “mysql.-community.”
#yum -y install mysql-community-server #安装社区版,快可3分钟,慢或40分钟
  
#systemctl start mysqld # 启动mysql
#mysql_secure_installation # mysql安全安装,root密码初始为空,自己设置
  
#mysql -uroot -p
mysql>create database wordpress; #创建wordpress数据库
mysql>use wordpress;
mysql>quit #或者exit

3.安装PHP

3.1安装php-fpm

#yum install php-fpm php-mysql
#systemctl start php-fpm # 启动php-fpm
#systemctl enable php-fpm # 设置开机启动
  
#mkdir /usr/www
#chown -R apache:apache /usr/www

3.2在Winscp登录主机

winscp菜单-选项-编辑器-默认编码,选择UTF-8。
设置好ssh:高级-ssh-验证-密钥文件。
密码是云主机的密码,修改密码要先关机。

3.3修改Nginx配置文件

打开/etc/nginx下的nginx.conf,其中server部分修改如下:

server {     listen       80 default_server;     listen       [::]:80 default_server;     server_name  ffflipped.cn;     root         /usr/www;         # Load configuration files for the default server block.     include /etc/nginx/default.d/*.conf;         location / {         index index.php;         try_files $uri $uri/ /index.php?$args;     }         rewrite /wp-admin$ $scheme://$host$uri/ permanent;         location ~* ^.+\.(ogg|ogv|svg|svgz|eot|otf|woff|mp4|ttf|rss|atom|jpg|jpeg|gif|png|ico|zip|tgz|gz|rar|bz2|doc|xls|exe|ppt|tar|mid|midi|wav|bmp|rtf)$ {                 access_log off; log_not_found off; expires max;     }         location ~ \.php$ {         try_files $uri =404;         fastcgi_split_path_info ^(.+\.php)(/.+)$;         fastcgi_pass 127.0.0.1:9000;         fastcgi_index index.php;         fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;         include fastcgi_params;     }     } 

保存后重载nginx

#systemctl reload nginx

在/usr/www 目录中创建 index.php

测试:123.206.57.252 或者解析好的域名http://ffflipped.cn 可以看到hello world!



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值