Centos7.2搭建LAMP

1、关闭firewall:

systemctl stop firewalld.service #停止firewall

systemctl disable firewalld.service #禁止firewall开机启动

2、安装iptables防火墙

yum -y install iptables-services #安装

vi /etc/sysconfig/iptables #编辑防火墙配置文件

# Firewall configuration written by system-config-firewall

# Manual customization of this file is not recommended.

*filter

: :INPUT ACCEPT [0:0]

:FORWARD ACCEPT [0:0]

:OUTPUT ACCEPT [0:0]

-A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT

-A INPUT -p icmp -j ACCEPT

-A INPUT -i lo -j ACCEPT

-A INPUT -p tcp -m state --state NEW -m tcp --dport 22 -j ACCEPT

-A INPUT -p tcp -m state --state NEW -m tcp --dport 80 -j ACCEPT

-A INPUT -p tcp -m state --state NEW -m tcp --dport 3306 -j ACCEPT

-A INPUT -j REJECT --reject-with icmp-host-prohibited

-A FORWARD -j REJECT --reject-with icmp-host-prohibited

COMMIT

:wq! #保存退出

3.重启服务

systemctl restart iptables.service #最后重启防火墙使配置生效

systemctl enable iptables.service #设置防火墙开机启动

4.关闭SELINUX

vi /etc/selinux/config

#SELINUX=enforcing #注释掉

#SELINUXTYPE=targeted #注释掉

SELINUX=disabled #增加

:wq! #保存退出

5.临时关闭防火墙

setenforce 0 #使配置立即生效

6.安装Apache

yum -y install httpd #根据提示,输入Y安装即可成功安装

7.重启服务

systemctl start httpd.service #启动apache

systemctl stop httpd.service #停止apache

systemctl restart httpd.service #重启apache

systemctl enable httpd.service #设置apache开机启动

8.在客户端浏览器中打开服务器IP地址,进行测试

二、安装MariaDB

CentOS 7.0中,已经使用MariaDB替代了MySQL数据库

1.安装MariaDB

yum -y install mariadb mariadb-server #询问是否要安装,输入Y即可自动安装,直到安装完成

2.重启服务

systemctl start mariadb.service #启动MariaDB

systemctl stop mariadb.service #停止MariaDB

systemctl restart mariadb.service #重启MariaDB

systemctl enable mariadb.service #设置开机启动

3.拷贝

cp /usr/share/mysql/my-huge.cnf /etc/my.cnf #拷贝配置文件(注意:如果/etc目录下面默认有一个my.cnf,直接覆盖即可)

4.为root用户设置权限

mysql_secure_installation

回车,根据提示输入Y

输入2次密码,回车

根据提示一路输入Y

最后出现:Thanks for using MariaDB!

MariaDB密码设置完成,重新启动 MariaDB:

systemctl restart mariadb.service #重启MariaDB

数据库的一些常见操作:

删除数据库和数据表

mysql>drop database 数据库名;

mysql>drop table 数据表名

删除账户及权限:

>drop user 用户名@‘%‘;

>drop user 用户名@ localhost;

(上述Disallow root login remotely? [Y/n],输入n则允许远程登录root密码。

如果远程还是没法访问数据库则执行:

GRANT ALL PRIVILEGES ON *.* TO ‘root‘@‘%‘ IDENTIFIED BY ‘yunjisuan‘;

flush privileges;)

三、安装PHP

安装PHP5.4版本

yum -y install php #根据提示输入Y直到安装完成

2、安装PHP组件,使PHP支持 MariaDB

yum -y install php-mysql php-gd libjpeg* php-ldap php-odbc php-pear php-xml php-xmlrpc php-mbstring php-bcmath php-mhash

#这里选择以上安装包进行安装,根据提示输入Y回车

重启服务

systemctl restart mariadb.service #重启MariaDB

systemctl restart httpd.service #重启apache

安装PHP5.6.30版本

执行下面的命令升级软件仓库

rpm -Uvh https://mirror.webtatic.com/yum/el7/epel-release.rpm

rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm

执行下面的命令删除php

yum remove php-common

然后像安装那样问你是否继续的,输入yes即可php

安装php 5.6版本(php56w-devel这个不是必需的)

yum install -y php56w php56w-opcache php56w-xml php56w-mcrypt php56w-gd php56w-devel php56w-mysql php56w-intl php56w-mbstring

重启httpd

systemctl restart httpd.service

查看最新的版本

php -v

现在应该是5.6了!

php网站运行不正常,发现上面遗漏

yum install -y php56w-fpm

systemctl restart php-fpm.service

Apache配置  !这里可以不用配置!可以忽略

vi /etc/httpd/conf/httpd.conf #编辑文件

ServerTokens = ProductOnly

ServerSignature On  #添加,在错误页中显示Apache的版本,Off为不显示

Options Indexes FollowSymLinks  #修改为:Options Includes ExecCGI FollowSymLinks(允许服务器执行CGI及SSI,禁止列出目录)

#AddHandler cgi-script .cgi #修改为:AddHandler cgi-script .cgi .pl (允许扩展名为.pl的CGI脚本运行)

AllowOverride None  #修改为:AllowOverride All (允许.htaccess)

AddDefaultCharset UTF-8 #修改为:AddDefaultCharset GB2312 (添加GB2312为默认编码)

#Options Indexes FollowSymLinks   #修改为 Options FollowSymLinks(不在浏览器上显示树状目录结构)

DirectoryIndex index.html   #修改为:DirectoryIndex index.html index.htm Default.html Default.htmindex.php(设置默认首页文件,增加index.php)

MaxKeepAliveRequests 500  #添加MaxKeepAliveRequests 500 (增加同时连接数)

:wq! #保存退出

重启服务

systemctl restart httpd.service #重启apache

删除默认测试页

rm -f /etc/httpd/conf.d/welcome.conf /var/www/error/noindex.html #删除默认测试页

PHP配置   !这里只需要修改时区就可以了!

vi /etc/php.ini #编辑

date.timezone = PRC #把前面的分号去掉,改为date.timezone = PRC

disable_functions = passthru,exec,system,chroot,scandir,chgrp,chown,shell_exec,proc_open,proc_get_status,ini_alter,ini_alter,ini_restore,dl,openlog,syslog,readlink,symlink,popepassthru,stream_socket_server,escapeshellcmd,dll,popen,disk_free_space,checkdnsrr,checkdnsrr,getservbyname,getservbyport,disk_total_space,posix_ctermid,posix_get_last_error,posix_getcwd, posix_getegid,posix_geteuid,posix_getgid, posix_getgrgid,posix_getgrnam,posix_getgroups,posix_getlogin,posix_getpgid,posix_getpgrp,posix_getpid, posix_getppid,posix_getpwnam,posix_getpwuid, posix_getrlimit, posix_getsid,posix_getuid,posix_isatty, posix_kill,posix_mkfifo,posix_setegid,posix_seteuid,posix_setgid, posix_setpgid,posix_setsid,posix_setuid,posix_strerror,posix_times,posix_ttyname,posix_uname

#列出PHP可以禁用的函数,如果某些程序需要用到这个函数,可以删除,取消禁用。

expose_php = Off #禁止显示php版本的信息

short_open_tag = ON #支持php短标签

open_basedir = .:/tmp/  #设置表示允许访问当前目录(即PHP脚本文件所在之目录)和/tmp/目录,可以防止php木马跨站,如果改了之后安装程序有问题(例如:织梦内容管理系统),可以注销此行,或者直接写上程序的目录/data/www.osyunwei.com/:/tmp/

:wq! #保存退出

最后配置

systemctl restart mariadb.service #重启MariaDB

systemctl restart httpd.service #重启apache

测试篇

cd /var/www/html

vi index.php #输入下面内容

<?php

phpinfo();

?>

:wq! #保存退出

在客户端浏览器输入服务器IP地址

注意事项:

apache默认的程序目录是/var/www/html

权限设置:chown apache.apache -R /var/www/html

配置详情相关网站

https://www.itbiji.net/archives/218.html

http://www.cnblogs.com/kylinfish/p/6286345.html

时间: 2024-08-03 19:42:19

Centos7.2搭建LAMP的相关文章

Centos7下搭建LAMP平台环境

centos发布7.0版本,新版本带来很多特性,除了内核更新到3.10外,支持 Linux 容器.Open VMware Tools 及 3D 图像能即装即用,转用 systemd.firewalld 及 GRUB2 ,而默认的文件系统为XFS等等,可以说是比较重大的升级.笔者尝试了使用Centos7搭建LAMP服务器平台,记录如下. 1.启用Apache2 Centos7默认已经安装httpd服务,只是没有启动.如果你需要全新安装,可以yum install -y httpd 启动服务:sys

CentOS7 yum搭建lamp

简易搭建lamp 环境说明: server:CentOS7-192.168.230.202 client: win8.1-192.168.230.59 Apache/2.4.6 php Version 5.4.16 5.5.52-MariaDB yum group install Development Tools #安装开发工具,GCC... yum install httpd mariadb mariadb-server php php-mysql php-gd libjpeg* php-i

CentOS7.X 搭建LAMP

第一部分搭建LAMP基础环境 1.检查CentOS是否为7.x版本 2.安装LAMP中的apache,采用yum源方法安装 yum  install httpd httpd-devel       Apache安装完成 启动 Apache:systemctl  start httpd            设置 Apache开机自启动:systemtel  enable   httpd     检查Apache状态:systemctl  status httpd 3..安装LAMP中的mysql

CentOs7下搭建LAMP环境

参考: http://blog.csdn.net/zph1234/article/details/51248124 http://www.jb51.net/os/188488.html 1.配置防火墙CentOS 7.0默认使用的是firewall作为防火墙.1.关闭firewall: systemctl stop firewalld.service #停止firewall systemctl disable firewalld.service #禁止firewall开机启动 2.关闭SELIN

centos7.2搭建lamp(Apache+PHP+Mysql环境)教程

服务器上比较推荐centos,特别对于新手,首选CentOS,并不是centos比Debian和ubuntu好,而是centos是初学者安装vps的首选,它既稳定,占用资源又少此版本生命周期较长,而且网上有关centos的教程很多,方便学习,我们这里选择了Centos7.2,采用yum在线安装. 一. 检查系统环境 1.确认centos版本 [[email protected] ~]# cat /etc/redhat-release CentOS Linux release 7.2.1511 (

Centos7+Apache2.4+php5.6+mysql5.5搭建Lamp环境——为了wordPress

最近想搭建个人博客玩玩,挑来挑去发现口碑不错的博客程序是wordpress,简称wp.虽然是学java路线的程序员,但因入行时间太短,至今没有发现较为称手开源的博客程序,如果各位大神有好的推荐,也希望能在评论中告知. 先上一张效果图: WordPress WordPress是一种使用PHP语言开发的博客平台,用户可以在支持PHP和MySQL数据库的服务器上架设属于自己的网站.也可以把 WordPress当作一个内容管理系统(CMS)来使用. 它的原版是英文的,不过也支持中文版的,据用过的哥们说,

CentOS7上快速搭建LAMP环境

首先 确保CentOS7上网络配置正确,可以正常访问互联网. 确保已经关闭了iptables. CentOS7上是firewall,关闭命令: # systemctl stop firewalld.service    # 停止firewalld服务 # systemctl disable firewalld.service    # 设置开机默认不启动 确保selinux已经关闭. # setenforce 0  # 不重启系统的状态下关闭selinux(permissive状态) # get

基于CentOS7的服务器搭建(LAMP环境)

基于CentOS7的服务器环境搭建(LAMP环境) 一.安装MySQL组件 1.由于在CentOS7中,默认yum安装库中不含有mysql,我们可以下载mysql的分支MariaDB,如果必须要下mysql,可以通过下载mysql官方的yum库,再利用yum install *进行mysql的安装 yum -y install mariadb-server 2.启动服务 service mysqld restart systemctl restart mysqld.service 3.修改mys

centos7.6快速搭建lamp环境调试过程

最小化安装系统后先更新 [[email protected] ~]# yum update -y [[email protected] ~]# cat /etc/redhat-release CentOS Linux release 7.6.1810 (Core) [[email protected] ~]# uname -r3.10.0-957.10.1.el7.x86_64 关闭防火墙systemctl stop firewalld.service 关闭防火墙开机启动systemctl di