在CentOS6上搭建LNMP环境(上)

搭建环境:

操作系统:CentOS 6.7

nginx软件:nginx-1.8.1.tar.gz

mysql软件:mysql-5.5.51-linux2.6-x86_64.tar.gz

PHP软件:php-5.6.11.tar.gz

一、LNMP安装前环境准备

1、设置linux防火墙

1)在iptables上开放80,3306,443端口

[[email protected] ~]# vim /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 ESTABLISHED,RELATED -j ACCEPT

-A INPUT -p icmp -j ACCEPT

-A INPUT -i lo -j ACCEPT

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

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

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

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

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

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

COMMIT

[[email protected] ~]# service iptables restart-----重启iptables服务

2)关闭selinux防火墙

[[email protected] ~]# vim /etc/sysconfig/selinux

# This file controls the state of SELinux on the system.

# SELINUX= can take one of these three values:

#     enforcing - SELinux security policy is enforced.

#     permissive - SELinux prints warnings instead of enforcing.

#     disabled - No SELinux policy is loaded.

SELINUX=disabled

# SELINUXTYPE= can take one of these two values:

#     targeted - Targeted processes are protected,

#     mls - Multi Level Security protection.

SELINUXTYPE=targeted

[[email protected] ~]#setenforc 0

3)安装依赖包

[[email protected] ~]#yum -y install gcc gcc-c++ autoconf libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel zlib zlib-devel glibc glibc-devel glib2 glib2-devel bzip2 bzip2-devel ncurses ncurses-devel curl curl-devel e2fsprogs e2fsprogs-devel krb5 krb5-devel libidn libidn-devel openssl openssl-devel openldap openldap-devel openldap-clients openldap-servers make  libtool* git tree bison pcre-devel perl gd gd-devel

4)编译安装其他软件

A:安装libiconv软件(该软件支持编码转换为函数)

[[email protected] software]# tar xf libiconv-1.14.tar.gz

[[email protected] libiconv-1.14]# ./configure --prefix=/usr/local

[[email protected] libiconv-1.14]# make && make install

[[email protected] libiconv-1.14]# echo $?

0

(显示0,表示软件编译安装成功了)

B:安装libmcrypt  (加密算法扩展库,支持DES, 3DES, RIJNDAEL, Twofish, IDEA, GOST, CAST-256, ARCFOUR, SERPENT, SAFER+等算法)

[[email protected] software]# tar xf libmcrypt-2.5.7.tar.gz

[[email protected] software]# cd libmcrypt-2.5.7

[[email protected] libmcrypt-2.5.7]# ./configure

[[email protected] libmcrypt-2.5.7]# cd libltdl/

[[email protected] libltdl]# ./configure --enable-ltdl-install

[[email protected] libltdl]# make && make install

C: 安装mhash(mhash的可以用于创建校验数值,消息摘要,消息认证码,以及无需原文的关键信息保存)

[[email protected] software]# tar xf mhash-0.9.9.9.tar.gz

[[email protected] software]# cd mhash-0.9.9.9

[[email protected] mhash-0.9.9.9]# ./configure && make && make install

D:安装mcript(mcrypt 是 php 里面重要的加密支持扩展库,Mcrypt扩展库可以实现加密解密功能,就是既能将明文加密,也可以密文还原。)

[[email protected] software]# tar xf mcrypt-2.6.8.tar.gz

[[email protected] software]# cd mcrypt-2.6.8

[[email protected] mcrypt-2.6.8]# export LD_LIBRARY_PATH=/usr/local/lib:$LD_LIBRARY_PATH

[[email protected] mcrypt-2.6.8]# ./configure && make && make install

E:增加库文件

[[email protected] software]# ln -s /usr/local/lib/libmcrypt.la /usr/lib/libmcrypt.la 

[[email protected] software]# ln -s /usr/local/lib/libmcrypt.so /usr/lib/libmcrypt.so 

[[email protected] software]# ln -s /usr/local/lib/libmcrypt.so.4 /usr/lib/libmcrypt.so.4 

[[email protected] software]# ln -s /usr/local/lib/libmcrypt.so.4.4.8 /usr/lib/libmcrypt.so.4.4.8 

[[email protected] software]# ln -s /usr/local/lib/libmhash.a /usr/lib/libmhash.a 

[[email protected] software]# ln -s /usr/local/lib/libmhash.la /usr/lib/libmhash.la 

[[email protected] software]# ln -s /usr/local/lib/libmhash.so /usr/lib/libmhash.so 

[[email protected] software]# ln -s /usr/local/lib/libmhash.so.2 /usr/lib/libmhash.so.2 

[[email protected] software]# ln -s /usr/local/lib/libmhash.so.2.0.1 /usr/lib/libmhash.so.2.0.1 

[[email protected] software]# ln -s /usr/local/bin/libmcrypt-config /usr/bin/libmcrypt-config

F:安装cmake (MySQL从5.5版本开始,通过./configure进行编译配置方式已经被取消,取而代之的是cmake工具)

[[email protected] ~]# yum -y install cmake

二、安装mysql数据软件

1)创建mysql用户

[[email protected] software]#groupadd -r mysql

[[email protected] software]# useradd -r -g mysql mysql -s /sbin/nologin

2)创建mysql的数据目录

[[email protected] software]# mkdir -p /data/mysqldb

3)安装mysql

[[email protected] ~]# cd /software/

[[email protected] software]# tar xf mysql-5.5.51-linux2.6-x86_64.tar.gz -C /usr/local/

[[email protected] software]# cd /usr/local/

[[email protected] local]# ll

total 48

drwxr-xr-x.  2 root root 4096 Aug 18 11:46 bin

drwxr-xr-x.  2 root root 4096 Sep 23  2011 etc

drwxr-xr-x.  2 root root 4096 Sep 23  2011 games

drwxr-xr-x.  3 root root 4096 Aug 18 11:45 include

drwxr-xr-x.  3 root root 4096 Aug 18 11:45 lib

drwxr-xr-x.  2 root root 4096 Sep 23  2011 lib64

drwxr-xr-x.  2 root root 4096 Sep 23  2011 libexec

drwxr-xr-x.  3 root root 4096 Aug 18 11:41 man

drwxr-xr-x. 13 root root 4096 Aug 18 11:55 mysql-5.5.51-linux2.6-x86_64

drwxr-xr-x.  2 root root 4096 Sep 23  2011 sbin

drwxr-xr-x.  8 root root 4096 Aug 18 11:41 share

drwxr-xr-x.  2 root root 4096 Sep 23  2011 src

[[email protected] local]# ln -sv mysql-5.5.51-linux2.6-x86_64/ mysql

`mysql‘ -> `mysql-5.5.51-linux2.6-x86_64/‘

修改mysql目录权限

[[email protected] mysql]# chown -R mysql:mysql .

[[email protected] mysql]# cd /data/mysqldb/

[[email protected] mysqldb]# chown -R mysql:mysql .

初始化mysql数据库

[[email protected] ~]# cd /usr/local/mysql

[[email protected] mysql]# ./scripts/mysql_install_db --user=mysql --datadir=/data/mysqldb

编辑mysql配置文件/etc/my.cnf

[mysqld]

datadir=/data/mysqldb

socket=/tmp/mysql.sock

user=mysql

# Disabling symbolic-links is recommended to prevent assorted security risks

symbolic-links=0

[mysqld_safe]

log-error=/var/log/mysqld.log

pid-file=/var/run/mysqld/mysqld.pid

复制MySQL启动文件及其命令加入PATH

[[email protected] mysql]# cp support-files/mysql.server  /etc/init.d/mysqld

[[email protected] mysql]# chmod +x /etc/init.d/mysqld

[[email protected] mysql]# chkconfig mysqld on

[[email protected] mysql]# vim /etc/profile.d/mysqld.sh

 PATH=/usr/local/mysql/bin:/usr/local/mysql/lib:$PATH

[[email protected] mysql]# source /etc/profile.d/mysql.sh

启动mysql服务器

[[email protected] etc]# service mysqld start

Starting MySQL..                                           [  OK  ]

修改root用户的密码及授权普通用户test可以远程连接到mysql数据库

mysql> grant all on *.* to ‘root‘@‘localhost‘ identified by ‘test123‘;

Query OK, 0 rows affected (0.00 sec)

mysql> flush privileges;

Query OK, 0 rows affected (0.00 sec)

mysql> grant all on *.* to ‘test‘@‘%‘ identified by ‘test1234‘;

Query OK, 0 rows affected (0.00 sec)

mysql> flush privileges;

Query OK, 0 rows affected (0.00 sec

时间: 2024-10-12 00:52:46

在CentOS6上搭建LNMP环境(上)的相关文章

docker下安装centos,并在其上搭建lnmp环境

一.安装CentOs容器 1.进入docker下载CentOs,这里我使用的CentOs6.8 docker pull centos:6.8 2.创建容器 sudo docker run --privileged --cap-add SYS_ADMIN -e container=docker -it --name lnmp -p 80:80 -p 3306:3306  -d -v /Users/qiao/www:/home/www  --restart=always centos:6.8 --p

在CentOS6上搭建LNMP环境(中)

编译安装nginx软件 1)新增nginx用户 [[email protected] software]#groupadd -r nginx [[email protected] software]# useradd -r -g nginxnginx -s /sbin/nologin 2)创建目录 [[email protected] ~]# mkdir -pv/var/tmp/nginx/client mkdir: created directory `/var/tmp/nginx' mkdi

在CentOS6上搭建LNMP环境(下)

编译安装php [[email protected] software]# tar xfphp-5.6.11.tar.gz [[email protected] software]# cd php-5.6.11 [[email protected] php-5.6.11]# ./configure--prefix=/usr/local/php --with-mysql=/usr/local/mysql--with-mysqli=/usr/local/mysql/bin/mysql_config

CentOS6.7搭建LNMP环境

1:查看环境: 1 [[email protected] ~]# cat /etc/redhat-release 2:关掉防火墙 1 #重启后生效开启 2 [[email protected] ~]# chkconfig iptables off 3 4 or 5 6 #即时生效,重启后失效开启 7 [[email protected] ~]# service iptables stop 关闭selinux #即时生效,重启后失效 [[email protected] ~]#setenforce

腾讯云CentOS6.8搭建lnmp环境

一.安装Ngnix 首先查看服务器系统的环境 可以看出我的系统环境是(CentOS6.9  64位) 2. 安装pcre和OpenSSL模块(不安装pcre模块,安装ngnix会报错) 查看pcre模块包 安装pcre模块 查看OpenSSL包

CentOS6.5搭建LNMP环境

配置防火墙 vi /etc/sysconfig/iptables -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT -A INPUT -p icmp -j ACCEPT -A INPUT -i lo -j ACCEPT -A INPUT -m state --state NEW -m tcp -p tcp --dport 22 -j ACCEPT -A INPUT -m state --state NEW -m tcp -p tcp

Ubuntu 18.04.1 下快速搭建 LNMP环境(PHP7.2.5+MySql5.7+Nginx1.14.0)

在Linux环境下,搭建LNMP环境,大家以前或多或少都做过相关的操作,但是随着软件的更新,PHP,MySQL不断的升级,以往很多比较老的教程,都已经无法完成这个搭建环境的任务了,今天偶然有兴趣在最新的Ubuntu18.04上搭建LNMP环境,本来感觉挺容易的,但是在实际操作过程中,遇到一个个坑,真是让人哭笑不得,所以写这篇心得,主要是分享在搭建过程中遇到的一些问题进行了整合,来给后入进行排雷. 首先展示搭建成功后的页面 PHP安装成功 MySQL安装成功 来,现在我们开始进行搭建 1.Ngin

【juincen】mac上搭建php环境

今天是2017年的8月20日,入职云南杜昂网络三天了,因为工作需要,所以看了下PHP,希望在以后能和大家交流学习. Apache是提供http服务的. 在mac上搭建php环境其实是非常简单的,不需要什么集成环境mamp(mac+apache+mysql+php).mac os系统自带了php和apache.我们调出终端工具,敲如下命令: php -v apachectl -v 可以看到我电脑上的php版本是5.6,apache的版本是2.4. 1.配置Apache 然后我们就要修改一个地方,我

Ubuntu上搭建Hadoop环境(单机模式+伪分布模式)【转】

[转自:]http://blog.csdn.net/hitwengqi/article/details/8008203 最近一直在自学Hadoop,今天花点时间搭建一个开发环境,并整理成文. 首先要了解一下Hadoop的运行模式: 单机模式(standalone)       单机模式是Hadoop的默认模式.当首次解压Hadoop的源码包时,Hadoop无法了解硬件安装环境,便保守地选择了最小配置.在这种默认模式下所有3个XML文件均为空.当配置文件为空时,Hadoop会完全运行在本地.因为不