洛杉矶MC机房 高速低价18元起

尊云,给你尊贵体验!

全手工搭建LNMP环境(CentOS7.2 PHP7.0)

提示:如果官网是英文页面,建议使用谷歌浏览器能同步翻译页面。点击下载【谷歌浏览器最新绿色便携版】
注意:部分文章发布时间较长,可能存在未知因素,购买时建议在本站搜索商家名称,先充分了解商家动态。
交流:唯一投稿QQ80059284、唯一投稿邮箱:admin@bkvps.com、网友交流QQ群号640669696。

对于不想使用各种面板的老鸟玩家,本文主要介绍了在VPS云服务器上如何手工搭建LNMP平台的web环境。具体操作以CentOS 7.2 64位操作系统为例。Linux实例手工部署LNMP环境具体操作步骤如下:安装nginx。安装MySQL。安装PHP。浏览器访问测试。前提条件VPS云服务器已绑定弹性公网IP。VPS云服务器所在安全组添加了如下表所示的安全组规则,具体步骤参见为安全组添加安全组规则。注意不同服务商有不同操作。很多国外商家也没有限制,默认全开的。安全组规则方向协议/应用端口/范围源地址入方向HTTP(80)800.0.0.0/0操作步骤安装nginx。登录VPS云服务器。执行以下命令,下载对应当前系统版本的nginx包。wget http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm执行以下命令,建立nginx的yum仓库。rpm -ivh nginx-release-centos-7-0.el7.ngx.noarch.rpm执行以下命令,安装nginx。yum -y install nginx执行以下命令,启动nginx并设置开机启动。systemctl start nginxsystemctl enable nginx使用浏览器访问 “http://服务器IP地址”,显示如下页面,说明nginx安装成功。安装MySQL。依次执行以下命令,安装MySQL。rpm -Uvh http://dev.mysql.com/get/mysql57-community-release-el7-8.noarch.rpmyum -y install mysql-community-server依次执行以下命令,启动MySQL服务并设置开机自启动。systemctl start mysqldsystemctl enable mysqld执行以下命令,获取安装MySQL时自动设置的root用户密码。grep ‘temporary password’ /var/log/mysqld.log回显如下类似信息。2018-08-29T07:27:37.541944Z 1 [Note] A temporary password is generated for root@localhost: 2YY?3uHUA?Ys执行以下命令,并按照回显提示信息进行操作,加固MySQL。mysql_secure_installationSecuring the MySQL server deployment.Enter password for user root: #输入上一步骤中获取的安装MySQL时自动设置的root用户密码The existing password for the user account root has expired. Please set a new password.New password: #设置新的root用户密码Re-enter new password: #再次输入密码The ‘validate_password’ plugin is installed on the server.The subsequent steps will run with the existing configuration of the plugin.Using existing password for root.Estimated strength of the password: 100Change the password for root ? ((Press y|Y for Yes, any other key for No) : N #是否更改root用户密码,输入N … skipping.By default, a MySQL installation has an anonymous user,allowing anyone to log into MySQL without having to havea user account created for them. This is intended only fortesting, and to make the installation go a bit smoother.You should remove them before moving into a productionenvironment.Remove anonymous users? (Press y|Y for Yes, any other key for No) : Y #是否删除匿名用户,输入YSuccess.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? (Press y|Y for Yes, any other key for No) : Y #禁止root远程登录,输入YSuccess.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? (Press y|Y for Yes, any other key for No) : Y #是否删除test库和对它的访问权限,输入Y – Dropping test database…Success. – Removing privileges on test database…Success.Reloading the privilege tables will ensure that all changesmade so far will take effect immediately.Reload privilege tables now? (Press y|Y for Yes, any other key for No) : Y #是否重新加载授权表,输入YSuccess.All done!安装PHP。依次执行以下命令,安装PHP 7和一些所需的PHP扩展。rpm -Uvh https://mirror.webtatic.com/yum/el7/epel-release.rpmrpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpmyum -y install php70w-tidy php70w-common php70w-devel php70w-pdo php70w-mysql php70w-gd php70w-ldap php70w-mbstring php70w-mcrypt php70w-fpm执行以下命令,验证PHP的安装版本。php -v回显如下类似信息:PHP 7.0.31 (cli) (built: Jul 20 2018 08:55:22) ( NTS )Copyright (c) 1997-2017 The PHP GroupZend Engine v3.0.0, Copyright (c) 1998-2017 Zend Technologies执行以下命令,启动PHP服务并设置开机自启动。systemctl start php-fpmsystemctl enable php-fpm修改nginx配置文件以支持PHP。执行以下命令打开配置文件“default.conf”。vim /etc/nginx/conf.d/default.conf按i键进入编辑模式。修改打开的“default.conf”文件。在所支持的主页面格式中添加php格式的主页,如下所示: location / { root /usr/share/nginx/html; index index.php index.html index.htm; }取消如下内容的注释,并设置字体加粗部分为nginx的默认路径,如下图所示: location ~ \.php$ { root html; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME /usr/share/nginx/html$fastcgi_script_name; include fastcgi_params; }按Esc键退出编辑模式,并输入:wq保存后退出。执行以下命令,重新载入nginx的配置文件。service nginx reload浏览器访问测试。在/usr/share/nginx/html/目录下创建“info.php”的测试页面。执行以下命令创建并打开“info.php”的测试文件。vim /usr/share/nginx/html/info.php按i键进入编辑模式。修改打开的“info.php”文件,将如下内容写入文件。<?php phpinfo();?>按Esc键退出编辑模式,并输入:wq保存后退出。使用浏览器访问“http://服务器IP地址/info.php”,显示如下页面,说明环境搭建成功。

 收藏 (0) 打赏

您可以选择一种方式赞助本站

支付宝扫一扫赞助

微信钱包扫描赞助

未经允许不得转载:贝壳主机网 » 全手工搭建LNMP环境(CentOS7.2 PHP7.0)

分享到: 生成海报
香港/美国/国内高速VPS
切换注册

登录

忘记密码 ?

您也可以使用第三方帐号快捷登录

切换登录

注册

我们将发送一封验证邮件至你的邮箱, 请正确填写以完成账号注册和激活