纯净linux配置lnmp环境

折腾了好久的环境,终于搭出来了。现在总结一下!!!

先关闭SELinux(不关闭可能会导致编译安装失败)

vim /etc/selinux/config
SELINUX=disabled   * 若安装时没有禁用SELinux ,将enforcing改为disabled。修改后需重新启动Linux方可生效!

允许防火墙80(nginx)、3306(mysql)端口访问

vi /etc/sysconfig/iptables 
-A INPUT -m state –state NEW -m tcp -p tcp –dport 80 -j ACCEPT(允许80端口通过防火墙) 
-A INPUT -m state –state NEW -m tcp -p tcp –dport 3306 -j ACCEPT(允许3306端口通过防火墙) 
特别提示:很多网友把这两条规则添加到防火墙配置的最后一行,导致防火墙启动失败,正确的应该是添加到默认的22端口这条规则的下面

安装nginx

1. 安装拓展:yum install wget gcc gcc-c++ pcre-devel zlib-devel openssl openssl-devel

2.cd /usr/local/

3.下载nginx:wget http://nginx.org/download/nginx-1.1.16.tar.gz

4.解压 tar -zxvf nginx-1.1.16

5.取消Debug编译模式:
    cd nginx-1.1.16
    vi auto/cc/gcc
    #CFLAGS="$CFLAGS -g" #将这句注释掉 取消Debug编译模式 大概在172行

6.预编译:./configure --prefix=/usr/local/nginx --with-http_ssl_module --with-http_v2_module --with-http_stub_status_module --with-pcre --with-http_gzip_static_module --with-http_dav_module --with-http_addition_module --with-http_sub_module --with-http_flv_module --with-http_mp4_module

解释

--with-http_gzip_static_module :支持压缩

--with-http_stub_status_module :支持nginx状态查询

--with-http_ssl_module :支持https

--with-pcre :为了支持rewrite重写功能,必须制定pcre

--with-http_dav_module             #启用支持(增加PUT,DELETE,MKCOL:创建集合,COPY和MOVE方法)                        
--with-http_addition_module         #启用支持(作为一个输出过滤器,支持不完全缓冲,分部分相应请求)
--with-http_sub_module              #启用支持(允许一些其他文本替换Nginx相应中的一些文本)
--with-http_flv_module              #启用支持(提供支持flv视频文件支持)
--with-http_mp4_module              #启用支持(提供支持mp4视频文件支持,提供伪流媒体服务端支持)

7.make && make install 

8.添加系统变量:
  vim /etc/profile
  export PATH=/usr/local/nginx/sbin:$PATH #在末尾添加即可
  重启配置 source /etc/profile
  使用命令nginx -V查看nginx版本信息,能查到就表示安装成功

9.常用命令
  nginx 启动
  nginx -s stop 停止
  nginx -s reload 重启

安装php

cd /usr/local/

wget https://www.php.net/distributions/php-7.2.21.tar.gz

tar -zxvf php-7.2.21.tar.gz

预编译:./configure --prefix=/usr/local/php/ --with-config-file-path=/usr/local/php/etc/ --with-apxs2=/usr/local/apache2/bin/apxs  --with-libxml-dir=/usr/local/libxml2/ --with-jpeg-dir=/usr/local/jpeg6/ --with-png-dir=/usr/local/libpng/ --with-freetype-dir=/usr/local/freetype/ --with-mcrypt=/usr/local/libmcrypt/   --with-mysqli=/usr/local/mysql/bin/mysql_config --enable-soap --enable-mbstring=all --enable-sockets  --with-pdo-mysql=/usr/local/mysql --with-gd   --without-pear
预编译完成后make && makeinstall

安装完成后:
cp php.ini-production /usr/local/php/etc/php.ini
cd /usr/local/php/etc
cp php-fpm.conf.default php-fpm.conf
cd php-fpm.d/
cp www.conf.default www.conf

将php的安装目录也加入到系统的环境变量  在最后一行加入

vim /etc/profile

export PATH=/usr/local/php/bin:$PATH

source /etc/profile 重新加载

php -v查看版本

 安装mysql5.7

原文地址:https://www.cnblogs.com/daemon-/p/9009360.html

1、下载tar包,这里使用wget从官网下载

wget https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.22-linux-glibc2.12-x86_64.tar.gz

2、将mysql安装到/usr/local/mysql下

# 解压

tar -xvf mysql-5.7.22-linux-glibc2.12-x86_64.tar.gz

# 移动

mv mysql-5.7.22-linux-glibc2.12-x86_64 /usr/local/

# 重命名

mv /usr/local/mysql-5.7.22-linux-glibc2.12-x86_64 /usr/local/mysql

3、新建data目录

mkdir /usr/local/mysql/data

4、新建mysql用户、mysql用户组

# mysql用户组

groupadd mysql

# mysql用户

useradd mysql -g mysql

5、将/usr/local/mysql的所有者及所属组改为mysql

chown -R mysql.mysql /usr/local/mysql

6、配置

/usr/local/mysql/bin/mysql_install_db --user=mysql --basedir=/usr/local/mysql/ --datadir=/usr/local/mysql/data

# 如果出现以下错误:

复制代码
2018-07-14 06:40:32 [WARNING] mysql_install_db is deprecated. Please consider switching to mysqld --initialize
2018-07-14 06:40:32 [ERROR]   Child process: /usr/local/mysql/bin/mysqldterminated prematurely with errno= 32
2018-07-14 06:40:32 [ERROR]   Failed to execute /usr/local/mysql/bin/mysqld --bootstrap --datadir=/usr/local/mysql/data --lc-messages-dir=/usr/local/mysql/share --lc-messages=en_US --basedir=/usr/local/mysql
-- server log begin --

-- server log end --
复制代码
# 则使用以下命令:

/usr/local/mysql/bin/mysqld --user=mysql --basedir=/usr/local/mysql/ --datadir=/usr/local/mysql/data --initialize
# 如果出现以下错误:

/usr/local/mysql/bin/mysqld: error while loading shared libraries: libnuma.so.1: cannot open shared object file: No such file or directory
# 则执行以下命令:

yum -y install numactl

# 完成后继续安装:

/usr/local/mysql/bin/mysqld --user=mysql --basedir=/usr/local/mysql/ --datadir=/usr/local/mysql/data --initialize
# 编辑/etc/my.cnf

复制代码
[mysqld]
datadir=/usr/local/mysql/data
basedir=/usr/local/mysql
socket=/tmp/mysql.sock
user=mysql
port=3306
character-set-server=utf8
# 取消密码验证
skip-grant-tables
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
# skip-grant-tables
[mysqld_safe]
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
复制代码
7、开启服务

# 将mysql加入服务

cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysql

# 开机自启

chkconfig mysql on

# 开启

service mysql start

8、设置密码

# 登录(由于/etc/my.cnf中设置了取消密码验证,所以此处密码任意)

/usr/local/mysql/bin/mysql -u root -p

# 操作mysql数据库

>>use mysql;

# 修改密码

>>update user set authentication_string=password('你的密码') where user='root';

>>flush privileges;

>>exit;

9、将/etc/my.cnf中的skip-grant-tables删除

10、登录再次设置密码(不知道为啥如果不再次设置密码就操作不了数据库了)

/usr/local/mysql/bin/mysql -u root -p

 >>ALTER USER 'root'@'localhost' IDENTIFIED BY '修改后的密码';

>>exit;

11、允许远程连接

/usr/local/mysql/bin/mysql -u root -p

>>use mysql;

>>update user set host='%' where user = 'root';

>>flush privileges;

>>eixt;

12、添加快捷方式

ln -s /usr/local/mysql/bin/mysql /usr/bin

猜你喜欢

转载自www.cnblogs.com/rhapsody/p/11322394.html
今日推荐