lamp 一键部署(LAMP架构部署和动态网站环境的配置)

实验环境:

操作系统:centos 7.5

服务器IP:192.168.10.5

运行用户:root

连接工具:xshell工具

web环境:Linux apache php MariaDB(LAMP架构)

大型动态应用系统平台主要是针对于大流量、高并发网站建立的底层系统架构。大型网站的运行需要一个可靠、安全、可扩展、易维护的应用系统平台做为支撑,以保证网站应用的平稳运行。这些东西都需要依靠web服务器来支撑,里面应用到的技术有单节点web服务器系统、负载均衡系统、数据集群系统、缓存系统、分布式存储系统、分布式服务器管理系统、代码发布系统等,现在企业一般都流行使用自动化系统部署,可以把web业务全部跑在docker容器中,简化了运维配置流程,下面我们简单的介绍下web服务器单节点的部署及使用。

本文属于原创,比较适合企业应用,具体详细的介绍可以参考《Linux就该这么学》里边教程的第20章,里面详细的介绍了LNMP架构,而我这里是介绍LAMP架构,LAMP、LNMP在企业都应用比较广泛,一般大型企业网站都会在Linux服务器上面跑,节约资源、提高web服务器性能及安全性。

# rpm -qa httpd //查看apache是否安装成功

lamp 一键部署(LAMP架构部署和动态网站环境的配置)(1)

# httpd -v //查看apache版本

Server version: Apache/2.4.6 (CentOS)

Server built: Jun 27 2018 13:48:59

# systemctl start httpd.service //启动apache服务

# systemctl status httpd.service //查看apache服务状态

# systemctl stop httpd.service //停止apache服务

# systemctl enable httpd.service //设置开机自动启动apache服务

apache默认配置文件路径:/etc/httpd/

lamp 一键部署(LAMP架构部署和动态网站环境的配置)(2)

apache默认web路径:/var/www/html ,默认里面是空目录

lamp 一键部署(LAMP架构部署和动态网站环境的配置)(3)

PHP 是一种创建动态交互性站点的强有力的服务器端脚本语言;PHP 是开源的,并且使用非常广泛;同时,对于像微软 asp、asp.net服务器脚本语言竞争者来说,PHP 无疑是另一种高效率的选项,PHP有点:开源性、处理快、易上手、跨平台,效率高、适用于大型网站架构,一般PHP都是结合Linux apache nginx MySQL;iis php极少,配置复杂、性能差。下面就简单介绍下php的安装及配置。

2、install php

# yum install php php-common php-fpm php-gd php-soap php-json php-ldap php-mbstring php-mysqlnd php-mysqld php-xml php-xmlrpc php-opcache php-simplexml php-bcmath -y

lamp 一键部署(LAMP架构部署和动态网站环境的配置)(4)

# rpm -qa php* //查看安装的PHP模块

lamp 一键部署(LAMP架构部署和动态网站环境的配置)(5)

# php -v //查看php版本

lamp 一键部署(LAMP架构部署和动态网站环境的配置)(6)

# ll /etc/php.ini //php默认配置文件,配置文件里面详细参数这里就不一一介绍了。

lamp 一键部署(LAMP架构部署和动态网站环境的配置)(7)

MySQL最初也是开源的,后来被Oracle公司收购后5.5后的版本开始收费了,后来又有了MariaDB数据库,MariaDB数据库管理系统是MySQL的一个分支,主要由开源社区在维护,采用GPL授权许可 MariaDB的目的是完全兼容MySQL,包括API和命令行,使之能轻松成为MySQL的代替品,MariaDB开源、跨平台、性能强、易扩展、应用广。

3、install mariadb

# yum install mariadb.x86_64 mariadb-server.x86_64 mariadb-devel.x86_64 -y

lamp 一键部署(LAMP架构部署和动态网站环境的配置)(8)

# rpm -qa mariadb //查看mariadb是否安装成功

lamp 一键部署(LAMP架构部署和动态网站环境的配置)(9)

# systemctl start mariadb.service //启动数据库服务

# systemctl stop mariadb.service //停止数据库服务

# systemctl status mariadb.service //查看数据库服务状态

# systemctl enable mariadb.service //设置开机自动启动数据库服务

mariadb安装后启动服务,数据库root用户是没有密码的,需要进行初始化并设置密码,配置如下:

# mysql_secure_installation

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

SERVERS IN PRODUCTION USE! PLEASE READ EACH STEP CAREFULLY!

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

password for the root user. If you've just installed MariaDB, 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 MariaDB

root user without the proper authorisation.

Set root password? [Y/n] y //y设置root用户密码

New password: //输入密码

Re-enter new password: //确定密码

Password updated successfully!

Reloading privilege tables..

... Success!

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

to log into MariaDB 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 //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 //y禁止root远程登录

... Success!

By default, MariaDB 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] n //n不删除test数据库,根据自己需求定。

... skipping.

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

will take effect immediately.

Reload privilege tables now? [Y/n] y //刷新数据表

... Success!

Cleaning up...

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

installation should now be secure.

Thanks for using MariaDB!

# mysql -h 127.0.0.1 -u root -p //连接数据库

lamp 一键部署(LAMP架构部署和动态网站环境的配置)(10)

4、test web service,apache php mariadb安装启动服务后就开始测试。

4.1、通过浏览器访问web服务器出现如下解密说明apache安装成功。

http://192.168.10.5

lamp 一键部署(LAMP架构部署和动态网站环境的配置)(11)

4.2、测试apache php

# vim /var/www/html/index.php

<?php

phpinfo();

?>

http://192.168.10.5/index.php

lamp 一键部署(LAMP架构部署和动态网站环境的配置)(12)

4.3、测试apache php mariadb

# vim /var/www/html/mysqld.php

<?php

$servername = "localhost";

$username = "root";

$password = "password";

// 创建连接

$conn = new mysqli($servername, $username, $password);

// 检测连接

if ($conn->connect_error) {

die("连接失败: " . $conn->connect_error);

}

echo "连接成功";

?>

http://192.168.10.5/mysqld.php

lamp 一键部署(LAMP架构部署和动态网站环境的配置)(13)

,

免责声明:本文仅代表文章作者的个人观点,与本站无关。其原创性、真实性以及文中陈述文字和内容未经本站证实,对本文以及其中全部或者部分内容文字的真实性、完整性和原创性本站不作任何保证或承诺,请读者仅作参考,并自行核实相关内容。文章投诉邮箱:anhduc.ph@yahoo.com

    分享
    投诉
    首页