腾讯云下搭建LNMP开发环境

nginxs 2017-05-18

趁着还是学生,花了一元钱在租了个腾讯云主机,打算在服务器上搭建个LNMP环境玩玩。

一、前提准备

1、检查主机运行情况

hostname

hostname -f

腾讯云下搭建LNMP开发环境

2、 更新系统

sudo yum update

腾讯云下搭建LNMP开发环境

腾讯云下搭建LNMP开发环境

输入y,回车,等待加载,中间加载截图省略了,这边直接给出最后更新完成的截图。

腾讯云下搭建LNMP开发环境

到这里系统更新完成。

二、安装Nginx

这里先说明一下,安装完后nginx是出现在/etc/nginx中的

在安装前看一下该文件夹,是没有发现nginx的踪迹的

腾讯云下搭建LNMP开发环境

开始安装

yum install nginx

腾讯云下搭建LNMP开发环境

腾讯云下搭建LNMP开发环境

腾讯云下搭建LNMP开发环境

回车等待加载,加载过程中提示部分直接输入y,回车后继续等待加载,加载完后是下面界面。

到上面位置nginx安装完成。

再来看一下安装位置,在/etc目录下发现了nginx的文件夹,者还不足以证明nginx安装成功。

腾讯云下搭建LNMP开发环境

启动nginx

systemctl start nginx

设置开机自动启动

systemctl enable nginx.service

腾讯云下搭建LNMP开发环境

测试: 在浏览器中输入公网IP可看到nginx的页面。

腾讯云下搭建LNMP开发环境

到这里nginx安装成功。

三、安装社区版MySQL

  1. 下载并添加存储库,然后更新

wgethttp://repo.mysql.com/mysql-community-release-el7-5.noarch.rpm

腾讯云下搭建LNMP开发环境

腾讯云下搭建LNMP开发环境

sudorpm -ivh mysql-community-release-el7-5.noarch.rpm

腾讯云下搭建LNMP开发环境

腾讯云下搭建LNMP开发环境

更新

yum update

腾讯云下搭建LNMP开发环境

等待加载

腾讯云下搭建LNMP开发环境

腾讯云下搭建LNMP开发环境

腾讯云下搭建LNMP开发环境

腾讯云下搭建LNMP开发环境

腾讯云下搭建LNMP开发环境

完成

下面开始安装

sudoyum install mysql-server

腾讯云下搭建LNMP开发环境

腾讯云下搭建LNMP开发环境

腾讯云下搭建LNMP开发环境

腾讯云下搭建LNMP开发环境

安装完成

启动服务

sudo systemctl start mysqld

腾讯云下搭建LNMP开发环境

mysql安全安装,root密码初始为空,自己设置

mysql_secure_installation

腾讯云下搭建LNMP开发环境

腾讯云下搭建LNMP开发环境

输入初始密码,默认为空,直接回车

腾讯云下搭建LNMP开发环境

设置root密码,回车

腾讯云下搭建LNMP开发环境

输入y,回车

腾讯云下搭建LNMP开发环境

输入mysql的登录密码 ,回车后输入确认密码

腾讯云下搭建LNMP开发环境

腾讯云下搭建LNMP开发环境

腾讯云下搭建LNMP开发环境

腾讯云下搭建LNMP开发环境

腾讯云下搭建LNMP开发环境

腾讯云下搭建LNMP开发环境

腾讯云下搭建LNMP开发环境

腾讯云下搭建LNMP开发环境

腾讯云下搭建LNMP开发环境

腾讯云下搭建LNMP开发环境

腾讯云下搭建LNMP开发环境

腾讯云下搭建LNMP开发环境

腾讯云下搭建LNMP开发环境

安装过程

[root@VM_68_173_centos ~]# mysql_secure_installation

NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MySQL

SERVERS IN PRODUCTION USE! PLEASE READ EACH STEP CAREFULLY!

In order to log into MySQL to secure it, we'll need the current

password for the root user. If you've just installed MySQL, and

you haven't set the root password yet, the password will be blank,

so you should just press enter here.

Enter current password for root (enter for none):

OK, successfully used password, moving on...

Setting the root password ensures that nobody can log into the MySQL

root user without the proper authorisation.

Set root password? [Y/n] y

New password:

Re-enter new password:

Password updated successfully!

Reloading privilege tables..

... Success!

By default, a MySQL installation has an anonymous user, allowing anyone

to log into MySQL without having to have a user account created for

them. This is intended only for testing, and to make the installation

go a bit smoother. You should remove them before moving into a

production environment.

Remove anonymous users? [Y/n] y

... Success!

Normally, root should only be allowed to connect from 'localhost'. This

ensures that someone cannot guess at the root password from the network.

Disallow root login remotely? [Y/n] y

... Success!

By default, MySQL comes with a database named 'test' that anyone can

access. This is also intended only for testing, and should be removed

before moving into a production environment.

Remove test database and access to it? [Y/n] y

- Dropping test database...

ERROR 1008 (HY000) at line 1: Can't drop database 'test'; database doesn't exist

... Failed! Not critical, keep moving...

- Removing privileges on test database...

... Success!

Reloading the privilege tables will ensure that all changes made so far

will take effect immediately.

Reload privilege tables now? [Y/n] y

... Success!

All done! If you've completed all of the above steps, your MySQL

installation should now be secure.

Thanks for using MySQL!

Cleaning up...

到这里已经安装完成,测试一下。

登录测试

腾讯云下搭建LNMP开发环境

没有问题

Exit退出

四、安装PHP

sudoyum install php php-mysql php-fpm

腾讯云下搭建LNMP开发环境

回车等待加载,然后输入y回车,继续等待加载

腾讯云下搭建LNMP开发环境

腾讯云下搭建LNMP开发环境

到这里php安装完成

启动php-fpm

systemctl start php-fpm # 启动php-fpm

设置开机启动

systemctl enable php-fpm

腾讯云下搭建LNMP开发环境

腾讯云下搭建LNMP开发环境

创建www文件夹并赋予权限

腾讯云下搭建LNMP开发环境

打开/etc/nginx下的nginx.conf文件

修改后

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/ {

indexindex.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_logoff; log_not_found off; expires max;

}

location~ \.php$ {

try_files$uri =404;

fastcgi_split_path_info^(.+\.php)(/.+)$;

fastcgi_pass127.0.0.1:9000;

fastcgi_indexindex.php;

fastcgi_paramSCRIPT_FILENAME $document_root$fastcgi_script_name;

includefastcgi_params;

}

}

保存后重新加载nginx

腾讯云下搭建LNMP开发环境

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

输入下面内容

腾讯云下搭建LNMP开发环境

测试

腾讯云下搭建LNMP开发环境

到这里环境搭建完成。

相关推荐