使用云服务器做网站,怎么手动搭建LNMP环境? | ||||||||
产品推荐: 1、安全稳定的云服务器租用,2核/2G/5M仅37元,点击抢购>>>; 2、高防物理服务器20核/16G/50M/500G防御仅350元,点击抢购>>> 3、百度智能建站(五合一网站)仅880元/年,点击抢购>>> 模板建站(PC+手机站)仅480元/年,点击抢购>>> 4、阿里云服务器2核2G3M仅99元/年、2核4G5M仅199元/年,新老同享,点击抢购>>> 5、腾讯云服务器2核2G4M仅99元/年、新老同享,点击抢购>>> 使用云服务器做网站,怎么手动搭建LNMP环境? 本文主要介绍了在天翼云上如何使用弹性云主机的Linux实例手工搭建LNMP平台的web环境。该指导具体操作以CentOS 7.2 64位操作系统为例。 Linux实例手工部署LNMP环境具体操作步骤如下
前提条件
1. 安装nginx。
wget http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm
rpm -ivh nginx-release-centos-7-0.el7.ngx.noarch.rpm
yum -y install nginx
systemctl start nginx systemctl enable nginx
2.安装MySQL
rpm -Uvh http://dev.mysql.com/get/mysql57-community-release-el7-8.noarch.rpm yum -y install mysql-community-server
systemctl start mysqld systemctl enable mysqld
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_secure_installation Securing 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: 100 Change 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 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? (Press y|Y for Yes, any other key for No) : Y #是否删除匿名用户,输入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? (Press y|Y for Yes, any other key for No) : Y #禁止root远程登录,输入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? (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 changes made so far will take effect immediately. Reload privilege tables now? (Press y|Y for Yes, any other key for No) : Y #是否重新加载授权表,输入Y Success. All done! 3. 安装PHP
rpm -Uvh https://mirror.webtatic.com/yum/el7/epel-release.rpm rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm yum -y install php70w-tidy php70w-common php70w-devel php70w-pdo php70w-mysql php70w-gd php70w-ldap php70w-mbstring php70w-mcrypt php70w-fpm
php -v 回显如下类似信息: PHP 7.0.31 (cli) (built: Jul 20 2018 08:55:22) ( NTS ) Copyright (c) 1997-2017 The PHP Group Zend Engine v3.0.0, Copyright (c) 1998-2017 Zend Technologies
systemctl start php-fpm systemctl enable php-fpm
执行以下命令打开配置文件“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保存后退出。
4.浏览器访问测试 1)/usr/share/nginx/html/目录下创建“info.php”的测试页面。
vim /usr/share/nginx/html/info.php
<?php phpinfo(); ?>
2)使用浏览器访问 http://服务器IP地址/info.php ,显示如下页面,说明搭建环境成功。
|