阿里云-云小站(无限量代金券发放中)
【腾讯云】云服务器、云数据库、COS、CDN、短信等热卖云产品特惠抢购

CentOS 6.x下LNMP环境源码编译安装及配置

228次阅读
没有评论

共计 8053 个字符,预计需要花费 21 分钟才能阅读完成。

一:环境介绍

1. 操作系统:CentOS 6.x (双核 4G、硬盘至少 20G)
2. 应用软件:nginx-1.8.1、MySQL-5.6.29、php-5.6.30

二:源码编译安装配置 nginx、mysql、php

1. 源码编译安装 nginx-1.8.1

官网下载 nginx-1.8.1.tar.gz

http://nginx.org/en/download.html

下载 pcre-8.40.tar.gz

https://ftp.pcre.org/pub/pcre/

yum 安装依赖包

yum install perl gcc-c++ make elinks zlib-devel openssl openssl-devel -y

pcre 解压即可

tar -zxf pcre-8.4.0.tar.gz

开始编译安装 nginx-1.8.1

tar -zxf nginx-1.8.1.tar.gz

cd nginx-1.8.1

./configure --prefix=/usr/local/nginx --with-pcre=/root/pcre-8.40 --with-http_stub_status_module --with-http_ssl_module

make

make install

修改 nginx 主配置文件,让其包含 /usr/local/nginx/conf/conf.d 下的所有 *.conf 文件

mkdir /usr/local/nginx/conf/conf.d

sed -i '116s/$/include \/usr\/local\/nginx\/conf\/conf.d\/*.conf;/g' /usr/local/nginx/conf/nginx.conf

至此 nginx 安装完毕

启动 nginx

/usr/local/nginx/sbin/nginx

查看 80 端口

netstat -ntpl |grep "80"

关闭防火墙 /etc/init.d/iptables stop 或者防火墙打开 80 端口

(关闭 nginx)

killall nginx
2. 源码编译安装 mysql-5.6.29

官网下载 mysql-5.6.29.tar.gz

https://downloads.mysql.com/archives/community/

CentOS 6.x 下 LNMP 环境源码编译安装及配置 

下载 cmake-3.4.0

https://cmake.org/files/v3.4/cmake-3.4.0.tar.gz

yum 安装依赖包

yum install gcc-c++ ncurses-devel perl-Module-Install.noarch libtool openssl-devel make -y

安装 cmake

tar -zxf cmake-3.4.0.tar.gz

cd cmake-3.4.0

./configure && make && make install

cmake 安装完毕

开始编译安装 mysql-5.6.29

tar -zxf mysql-5.6.29.tar.gz

cd mysql-5.6.29

cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DSYSCONFDIR=/usr/local/mysql/data -DMYSQL_DATADIR=/usr/local/mysql/data -DMYSQL_UNIX_ADDR=/usr/local/mysql/mysqld.sock -DWITH_MYISAM_STORAGE_ENGINE=1 -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_PARTITION_STORAGE_ENGINE=1 -DWITH_ARCHIVE_STORAGE_ENGINE=1 -DWITH_BLACKHOLE_STORAGE_ENGINE=1 -DWITH_FEDERATED_STORAGE_ENGINE=1 -DWITH_PERFSCHEMA_STORAGE_ENGINE=1 -DENABLED_LOCAL_INFILE=1 -DMYSQL_TCP_PORT=3306 -DWITH_EXTRA_CHARSETS=all -DWITH_DEBUG=0 -DENABLE_DEBUG_SYNC=0 -DWITH_SSL=system -DWITH_ZLIB=system -DWITH_READLINE=1 -DZLIB_INCLUDE_DIR=/usr -DWITH_READLINE=1
make
make install

创建 mysql 系统用户组和用户,并将 mysql 安装目录赋予 root 组和 root 用户

groupadd mysql

useradd -g mysql -s /sbin/nologin -M mysql

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

初始化 mysql 数据库

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

复制 mysql 启动脚本

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

直接执行修改文件

sed -i '46s/$/\/usr\/local\/mysql/g' /etc/init.d/mysqld
sed -i '47s/$/\/usr\/local\/mysql\/data/g' /etc/init.d/mysqld
sed -i '263s/datadir/basedir/g' /etc/init.d/mysqld

写入 mysql 配置文件 my.cnf

echo "[mysqld]

basedir=/usr/local/mysql
datadir=/usr/local/mysql/data
socket=/usr/local/mysql/mysqld.sock
user = mysql
port = 3306
server_id = 2
#log-bin = mysql-bin
#log_bin_index = binlog.index
character_set_server = utf8
#lower_case_table_names = 1
#binlog_ignore_db = mysql
#replicate-do-db = mysql
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
innodb_file_per_table=1

[mysql.server]
character_set_server = utf8
socket=/usr/local/mysql/mysqld.sock

[client]
socket=/usr/local/mysql/mysqld.sock
default-character-set = utf8

[mysqld_safe]
character_set_server = utf8

[mysql]
socket=/usr/local/mysql/mysqld.sock
default-character-set = utf8


[mysqldump]
socket=/usr/local/mysql/mysqld.sock
default-character-set = utf8


[mysqladmin]
socket=/usr/local/mysql/mysqld.sock
character_set_server = utf8
" > /usr/local/mysql/my.cnf

将 mysql 加入 centos 系统环境变量
vim /etc/profile

echo -e "export MYSQL_HOME=\"/usr/local/mysql\"export PATH=\"\$PATH:\$MYSQL_HOME/bin\"" >> /etc/profile

刷新环境变量

source /etc/profile

至此 mysql 安装完毕

启动 mysql

/etc/init.d/mysqld start

查看 3306 端口

netstat -ntpl |grep "3306"

(停止或重启 mysql)

/etc/init.d/mysqld stop

/etc/init.d/mysqld restart

shell 界面进入 mysql 删除默认的多余 root 账户

mysql -uroot -p


delete from mysql.user where Host='::1';
delete from mysql.user where Host='localhost.localdomain';
delete from mysql.user where User='';

将所有的 root 用户更改密码

update mysql.user set password=password("root") where user="root";

创建一个可以从其他任何地方访问 mysql 的用户 密码为 root

grant all privileges on *.* to 'root'@'%' identified by "root";

对用户进行增删改后需要重启数据库或者执行 flush privileges;

查看 mysql 用户

select user,host,password from mysql.user;
3. 源码编译安装 php-5.6.30

官网下载 php-5.6.30

http://php.net/downloads.php#v5.6.30

yum 安装依赖包

yum install gcc-c++ gd libxml2-devel libjpeg-devel libpng-devel net-snmp-devel curl-devel libxslt-devel pcre-devel libjpeg libpng libxml2 libcurl4-openssl-dev libcurl-devel libcurl freetype-config freetype freetype-devel unixODBC libxslt -y

开始编译安装 php-5.6.30

tar -zxf php-5.6.30.tar.gz

cd php-5.6.30

./configure –prefix=/usr/local/php-5.6.30 –with-curl –with-gd –with-gettext –with-iconv-dir –with-kerberos –with-libdir=lib64 –with-libxml-dir –with-mysql –with-mysqli –with-openssl –with-pcre-regex –with-pdo-mysql –with-pdo-sqlite –with-pear –with-png-dir –with-freetype-dir –with-jpeg-dir –with-xmlrpc –with-xsl –with-zlib –enable-fpm –enable-bcmath –enable-libxml –enable-inline-optimization –enable-gd-native-ttf –enable-mbregex –enable-mbstring –enable-opcache –enable-pcntl –enable-shmop –enable-soap –enable-sockets –enable-sysvsem –enable-xml && make && make install

从 php 源码包复制 php.ini 配置文件到 php 安装目录,并做系统的软连接

cp -a /root/php-5.6.30/php.ini-production /usr/local/php-5.6.30/etc/php.ini
ln -s /usr/local/php-5.6.30/etc/php.ini /etc/php.ini

从 php 源码包复制 php-fpm.conf 配置文件到 php 安装目录,并做系统的软连接

cp -a /usr/local/php-5.6.30/etc/php-fpm.conf.default /usr/local/php-5.6.30/etc/php-fpm.conf
ln -s /usr/local/php-5.6.30/etc/php-fpm.conf /etc/php-fpm.conf

修改 php-fpm.conf 配置参数

sed -i ’25s/;//g’ /usr/local/php-5.6.30/etc/php-fpm.conf

sed -i ‘303s/disable_functions =/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,esca peshellcmd,dll,popen,disk_free_space,checkdnsrr,checkdnsrr,getservbyname,getservbyport,disk_total_space,p osix_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,pos ix_getpwnam,posix_getpwuid, posix_getrlimit, posix_getsid,posix_getuid,posix_isatty, posix_kill,posix_mkf ifo,posix_setegid,posix_seteuid,posix_setgid, posix_setpgid,posix_setsid,posix_setuid,posix_strerror,posi x_times,posix_ttyname,posix_uname/g’ /usr/local/php-5.6.30/etc/php.ini

sed -i ‘936s/;date.timezone =/date.timezone = PRC/g’ /usr/local/php-5.6.30/etc/php.ini

sed -i ‘151s/; short_open_tag/short_open_tag = ON/g’ /usr/local/php-5.6.30/etc/php.ini

sed -i ‘1905s/;opcache.enable=0/opcache.enable=1/g’ /usr/local/php-5.6.30/etc/php.ini

sed -i ‘1908s/;opcache.enable_cli=0/opcache.enable_cli=0/g’ /usr/local/php-5.6.30/etc/php.ini

sed -i ‘$a zend_extension=opcache.so’ /usr/local/php-5.6.30/etc/php.ini

sed -i ‘509s/;env[PATH] = /usr/local/bin:/usr/bin:/bin/env[PATH] = /usr/local/bin:/usr/bin:/bin/:/usr/local/php5.6.30/bin/g’ /usr/local/php-5.6.30/etc/php-fpm.conf

复制 php 启动脚本

cp -a /root/php-5.6.30/sapi/fpm/php-fpm /etc/init.d/

启动 php

/etc/init.d/php-fpm

查看 9000 端口

netstat -ntpl |grep "9000"

(停止 php)

killall php-fpm

测试 nginx+php

mkdir /opt/test

echo "<?php
Phpinfo();
?>" > /opt/test/index.php

nginx 配置

vim /usr/local/nginx/conf/conf.d/test.conf

server {
        listen          80;
        server_name     192.168.1.2;
        index           index.php;
        root            /opt/test;

        location /
        {try_files $uri $uri/ /index.php?$args;}

        location ~ ^(.+.php)(.*)$ {fastcgi_split_path_info ^(.+.php)(.*)$;
                include fastcgi.conf;
                fastcgi_pass  127.0.0.1:9000;
                fastcgi_index index.php;
                fastcgi_param  PATH_INFO          $fastcgi_path_info;
        }
}

浏览器输入 192.168.1.2 查看 php 页面

LNMP 环境搭建 (Discuz 论坛)  http://www.linuxidc.com/Linux/2016-03/129334.htm 

Ubuntu 14.04 下 apt-get 方法安装 LNMP 环境  http://www.linuxidc.com/Linux/2016-07/133683.htm 

CentOS 7 源码编译安装 PHP5.6 和 Nginx1.7.9 及 MySQL(搭建 LNMP 环境) http://www.linuxidc.com/Linux/2015-12/126200.htm 

Ubuntu 14.04 LTS 安装 LNMP Nginx\PHP5 (PHP-FPM)\MySQL  http://www.linuxidc.com/Linux/2014-05/102351.htm 

CentOS 6.8 编译安装 LNMP 简述  http://www.linuxidc.com/Linux/2017-05/143667.htm 

Ubuntu 16.04 下源码配置 LNMP 开发环境 http://www.linuxidc.com/Linux/2016-09/135381.htm 

CentOS 7 源码编译安装 PHP5.6 和 Nginx1.7.9 及 MySQL(搭建 LNMP 环境) http://www.linuxidc.com/Linux/2015-12/126200.htm 

CentOS 7 源码安装最新版 LNMP 环境 http://www.linuxidc.com/Linux/2015-04/116058.htm 

CentOS 6.8 安装 LNMP 环境(Linux+Nginx+MySQL+PHP)http://www.linuxidc.com/Linux/2017-04/142880.htm 

Ubuntu 系统下 LNMP 环境的搭建  http://www.linuxidc.com/Linux/2017-04/142610.htm 

编译 LNMP 之 Nginx+php-fpm  http://www.linuxidc.com/Linux/2017-10/147535.htm 

Ubuntu 16.04 LTS 下 LNMP 环境配置简述  http://www.linuxidc.com/Linux/2017-05/144252.htm 

本文永久更新链接地址 :http://www.linuxidc.com/Linux/2017-12/149714.htm

正文完
星哥玩云-微信公众号
post-qrcode
 0
星锅
版权声明:本站原创文章,由 星锅 于2022-01-21发表,共计8053字。
转载说明:除特殊说明外本站文章皆由CC-4.0协议发布,转载请注明出处。
【腾讯云】推广者专属福利,新客户无门槛领取总价值高达2860元代金券,每种代金券限量500张,先到先得。
阿里云-最新活动爆款每日限量供应
评论(没有评论)
验证码
【腾讯云】云服务器、云数据库、COS、CDN、短信等云产品特惠热卖中