微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

CentOS 7 一步一步搭建LAMP

一、准备环境

1、系统版本

[root@Webserver01~]#cat/proc/version

Linux version 3.10.0-514.16.1.el7.x86_64

2、关防火墙

[root@Webserver01~]#systemctldisablefirewalld

3、准备yum源

[root@Webserver01~]#rpm-ivhhttp://dl.fedoraproject.org/pub/epel/7/x86_64/e/epel-release-7-5.noarch.rpm

[root@Webserver01~]#rpm-ivhhttp://mirrors.aliyun.com/epel/epel-release-latest-7.noarch.rpm

4、安装基础工具

[root@Webserver01~]#yuminstall-ynet-toolsvimlrzsztreescreenlsoftcpdumpncnmap

5、关掉SELINUX

[root@Webserver01~]#vim/etc/sysconfig/selinux
SELINUX=disabled

6、更新并重启

[root@Webserver01~]#yumupdate-y&&reboot

二、开始安装LAMP组建


LAMP至少需要以下组建:

  • httpd (提供 Apache 主程序)

  • MysqL (MysqL 客�舳顺绦�)

  • MysqL-server (MysqL 服务器程序)

  • PHP (PHP 主程序含给 apache 使用的模块)

  • PHP-devel (PHP 的开发工具,这个与PHP 外挂的加速软件有关)

  • PHP-MysqL (提供给PHP 程序读取 MysqL 资料库的模块)

可以用以下命令一次安装;

[root@Webserver01~]#yuminstallhttpdMysqLMysqL-serverPHPPHP-MysqL

为了看的更详细,我们一个一个安装

1、利用yum命令安装Apache

[root@Webserver01~]#yum-yinstallhttpd

启动httpd并且设置为开机启动

[root@Webserver01~]#systemctlstarthttpd.service
[root@Webserver01~]#systemctlenablehttpd.service

输入网址,查看测试页


wKioL1kiuY-AGPapAAWChredF5M390.jpg


2、安装Mariadb

利用yum命令进行安装,并且配置开机启动同样还是利用yum命令进行安装,并且配置开机启动

[root@Webserver01~]#yum-yinstallmariadb-servermariadb
[root@Webserver01~]#systemctlstartmariadb.service
[root@Webserver01~]#systemctlenablemariadb.service

配置root密码

[root@Webserver01~]#MysqL_secure_installation
安装过程中会有几个选项,大家根据自己的需要进行配置就好了
Entercurrentpasswordforroot(enterfornone):(输入原始root密码,若无enter)
OK,successfullyusedpassword,movingon...
SettingtherootpasswordensuresthatnobodycanlogintotheMariaDB
rootuserwithouttheproperauthorisation.
Setrootpassword?[Y/n](是否设置root密码)
Newpassword:
Re-enternewpassword:
Passwordupdatedsuccessfully!
Reloadingprivilegetables..
...Success!
Removeanonymoususers?[Y/n](是否移除匿名用户)
...Success!
disallowrootloginremotely?[Y/n](是否禁止远程root登陆)
...skipping.
Removetestdatabaseandaccesstoit?[Y/n](是否删除测试数据库)
ReloadprivilegetablesNow?[Y/n](重新载入)
...Success!
Cleaningup...
Alldone!Ifyou'vecompletedalloftheabovesteps,yourMariaDB
installationshouldNowbesecure.
ThanksforusingMariaDB!

登录数据库测试一下

[root@Webserver01~]#MysqL-uroot-p
Enterpassword:
WelcometotheMariaDBmonitor.Commandsendwith;or\g.
YourMariaDBconnectionidis13
Serverversion:5.5.52-MariaDBMariaDBServer
copyright(c)2000,2016,Oracle,MariaDBCorporationAbandothers.
Type'help;'or'\h'forhelp.Type'\c'toclearthecurrentinputstatement.
MariaDB[(none)]>showdatabases;
+--------------------+
|Database|
+--------------------+
|information_schema|
|MysqL|
|performance_schema|
+--------------------+
3rowsinset(0.00sec)
MariaDB[(none)]>exit
Bye

3、安装PHP

[root@Webserver01~]#yum-yinstallPHP

安装所需组件

[root@Webserver01~]#yum-yinstallPHP-MysqLPHP-gdPHP-ldapPHP-odbcPHP-pearPHP-xmlPHP-xmlrpcPHP-mbstringPHP-snmpPHP-soapcurlcurl-devel

启动服务并设置开机自动启动

[root@Webserver01~]#systemctlstarthttpd.service
[root@Webserver01~]#systemctlenablehttpd.service

查看80端口和3306端口是否处于监听状态:

[root@Webserver01~]#netstat-ntlp


测试PHP是否正常工作

编辑/etc/httpd/conf/httpd.conf文件,在DirectoryIndex后面填写index.PHP,定义认主页为index.PHP

[root@Webserver01~]#vim/etc/httpd/conf/httpd.conf

wKioL1kiu7HjwB-2AABUjgT8QYE238.jpg

重载httpd配置文件

[root@Webserver01~]#systemctlreloadhttpd.service
[root@Webserver01~]#vim/var/www/html/index.PHP

制作认主页/var/www/html/index.PHP,编写如下内容

<h1>ThisisnewWeb!</h1>
<?PHP
PHPinfo();
?>

重启httpd服务

[root@Webserver01~]#systemctlrestarthttpd.service

好了,该验证最后是否成功了

打开网址 http://x.x.x.x/info.PHP 进行查看

wKioL1kivMCyJrUMAAK5H4vm9zU658.jpg



看到这个页面,我们就可以收工了,LAMP环境搭建结束!

原文地址:https://www.jb51.cc/centos/377497.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。