热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

CentOS7下LNMP环境源码安装

系统:CentOS7x86_64NGINX:nginx-1.7.12数据库:mariadb-10.0.13PHP:php-5.5.23首先做一些准备工作,先把centos7的防火墙更换成iptables,可以参见如下链接centos7防火墙改为iptables修改成iptables之后就可以清空iptables里面的过滤规则了,然后再关闭sel

系统:CentOS 7 x86_64
NGINX:nginx-1.7.12
数据库:mariadb-10.0.13
PHP:php-5.5.23
首先做一些准备工作,先把centos7的防火墙更换成iptables,可以参见如下链接
centos7防火墙改为iptables

修改成iptables之后就可以清空iptables里面的过滤规则了,然后再关闭selinux服务。记得不要忘了先安装gcc gcc-c++ wget net-tools等功能哦。

首先安装mariadb

应为数据库编译需要很长时间,所以我这里下载的是已经编译好了的二进制包,下载版本为 mariadb-10.0.13-linux-glibc_214-x86_64.tar.gz

1、下载二进制包到/usr/local/src 目录下:
[root@centos74 ~]# cd /usr/local/src/
[root@centos74 src]# wget http://ftp.osuosl.org/pub/mariadb/mariadb-10.0.13/bintar-quantal-amd64/mariadb-10.0.13-linux-glibc_214-x86_64.tar.gz
2、将压缩包解压到/usr/local 目录下:
[root@centos74 src]# tar zvxf mariadb-10.0.13-linux-glibc_214-x86_64.tar.gz -C /usr/local/
3、创建mariadb 数据初始化目录/data/mysql:
[root@centos74 src]# mkdir -p /data/mysql
4、添加系统用户mysql,禁止登陆系统,同时,将mariadb 数据初始化目录所属主和组都修改为mysql:
[root@centos74 src]# useradd -r -s /sbin/nologin mysql ;chown -R mysql.mysql /data/mysql/
5、重命名解压出来的mariadb 目录:
[root@centos74 src]# mv /usr/local/mariadb-10.0.13-linux-x86_64/ /usr/local/mysql
6、进入重命名后的目录,初始化mariadb:
[root@centos74 src]# cd /usr/local/mysql/
[root@centos74 mysql]# ./scripts/mysql_install_db --datadir=/data/mysql --user=mysql
Installing MariaDB/MySQL system tables in '/data/mysql' ...
140906  2:03:19 [Note] InnoDB: Using mutexes to ref count buffer pool pages
140906  2:03:19 [Note] InnoDB: The InnoDB memory heap is disabled
140906  2:03:19 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
140906  2:03:19 [Note] InnoDB: Compressed tables use zlib 1.2.3
140906  2:03:19 [Note] InnoDB: Using Linux native AIO
140906  2:03:19 [Note] InnoDB: Using CPU crc32 instructions
140906  2:03:19 [Note] InnoDB: Initializing buffer pool, size = 128.0M
........................................................................
The latest information about MariaDB is available at http://mariadb.org/.
You can find additional information about the MySQL part at:
http://dev.mysql.com
Support MariaDB development by buying support/new features from
SkySQL Ab. You can contact us about this at sales@skysql.com.
Alternatively consider joining our community based development effort:
http://mariadb.com/kb/en/contributing-to-the-mariadb-project/
报错:WARNING: The host 'test4' could not be looked up with resolveip.
解决办法:vim /etc/hosts 在最后一行添加192.168.1.242 test4
报错:./bin/mysqld: error while loading shared libraries: libaio.so.1: cannot open shared object file: No such file or directory
解决办法:yum -y install libaio-devel libaio
7、复制配置文件到/etc目录覆盖之前的my.cnf:
[root@centos74 mysql]# cp support-files/my-large.cnf /etc/my.cnf
cp:是否覆盖"/etc/my.cnf"? y
8、复制mysql 启动脚本文件到/etc/init.d 目录下并重命名为mysqld:
[root@centos74 mysql]# cp support-files/mysql.server /etc/init.d/mysqld
同时修改启动脚本的权限为755:
[root@centos74 mysql]# chmod 755 !$
chmod 755 /etc/init.d/mysqld
9、编辑启动脚本,定义datadir 路径:
[root@centos74 mysql]# vim /etc/init.d/mysqld
定义数据存放路径:
datadir=/data/mysql
10、将mariadb自带命令放入$PATH
[root@localhost ~]# PATH=$PATH:/etc/init.d/#当前有效,重启shell就失效
[root@localhost ~]# echo "export PATH=$PATH:/etc/init.d/" >>/etc/profile
[root@localhost ~]# echo "export PATH=$PATH:/usr/local/mysql/bin/" >>/etc/profile
[root@localhost ~]# source !$


11、启动mariadb:
[root@centos74 mysql]# /etc/init.d/mysqld start
Starting MySQL. SUCCESS!

第二步,开始安装php

这里要先声明一下,针对Nginx的php安装和针对apache的php安装是有区别的,因为Nginx中的php是以fastcgi的方式结合nginx的,可以理解为nginx代理了php的fastcgi,而apache是把php作为自己的模块来调用的。同样的,php官方下载地址: http://www.php.net/downloads.php
下载php
[rot@localhost src]# cd /usr/local/src
[root@localhost src]# wget http://am1.php.net/distributions/php-5.5.23.tar.gz
解压php
[root@localhost src]# tar zxf php-5.5.23.tar.gz
创建相关账户
[root@localhost src]# useradd -s /sbin/nologin php-fpm
配置编译参数
[root@localhost src]# cd php-5.5.23
[root@localhost src]# yum -y install gcc make gd-devel libjpeg-devel libpng-devel libxml2-devel bzip2-devel libcurl-devel 
[root@localhost php-5.5.23]# ./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --enable-fpm --with-fpm-user=php-fpm --with-fpm-group=php-fpm --with-mysql=mysqlnd  --with-pdo-mysql=mysqlnd --with-mysqli=mysqlnd --with-libxml-dir --with-gd --with-jpeg-dir --with-png-dir --with-freetype-dir --with-iconv-dir --with-zlib-dir --with-mcrypt --enable-soap --enable-gd-native-ttf --enable-ftp --enable-mbstring --enable-exif --disable-ipv6 --with-pear --with-curl --enable-bcmath --enable-mbstring --enable-sockets --with-gd --with-libxml-dir=/usr/local --with-gettext
错误:configure: error: xml2-config not found. Please check your libxml2 installation.
解决办法:yum -y install libxml2-devel
错误:configure: error: Please reinstall the libcurl distribution -easy.h should be in /include/curl/
解决办法:yum -y install libcurl-devel
错误:configure: error: jpeglib.h not found.
解决办法:yum -y install libjpeg-turbo-devel
错误:configure: error: png.h not found.
解决办法:um -y install libpng-devel
错误:configure: error: freetype-config not found.
解决办法:configure: error: mcrypt.h not found. Please reinstall libmcrypt.
错误:configure: error: mcrypt.h not found. Please reinstall libmcrypt.
解决办法:yum -y install libmcrypt-devel

 


安装php
[root@localhost  php-5.3.27]# make && make install
以上每一个步骤,如果没有完全执行正确,那么下一步是无法进行的,使用 echo $? 看结果是否为 “0” , 如果不是,就是没有执行正确。
修改配置文件
cp php.ini-production /usr/local/php/etc/php.ini
vim /usr/local/php/etc/php-fpm.conf
把如下内容写入该文件:
[global]
pid = /usr/local/php/var/run/php-fpm.pid
error_log = /usr/local/php/var/log/php-fpm.log
[www]
listen = /tmp/php-fcgi.sock
user = php-fpm
group = php-fpm
listen.owner = nobody
listen.group = nobody
pm = dynamic
pm.max_children = 50
pm.start_servers = 20
pm.min_spare_servers = 5
pm.max_spare_servers = 35
pm.max_requests = 500
rlimit_files = 1024
保存配置文件后,检验配置是否正确的方法为:
/usr/local/php/sbin/php-fpm -t
如果出现诸如 “test is successful” 字样,说明配置没有问题。
启动php-fpm
cp /usr/local/src/php-5.5.23/sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
chmod 755 /etc/init.d/php-fpm
service php-fpm start
如果想让它开机启动,执行:
chkconfig php-fpm on
检测是否启动:
ps aux |grep php-fpm
看看是不是有很多个进程(大概20多个)。

安装nginx

下载nginx
cd /usr/local/src/
wget http://nginx.org/download/nginx-1.7.12.tar.gz
解压nginx
tar zxvf nginx-1.7.12.tar.gz
配置编译参数
cd nginx-1.7.12
./configure \
--prefix=/usr/local/nginx \
--with-http_realip_module \
--with-http_sub_module \
--with-http_gzip_static_module \
--with-http_stub_status_module  \
--with-pcre
报错:./configure: error: the HTTP rewrite module requires the PCRE library.
解决办法:yum -y install pcre-devel
报错:./configure: error: the HTTP gzip module requires the zlib library.
解决办法:yum install -y zlib-devel


编译nginx
make
安装nginx
make install


编写nginx启动脚本,并加入系统服务
vim /etc/init.d/nginx
写入如下内容:
#!/bin/bash
# chkconfig: - 30 21
# description: http service.
# Source Function Library
. /etc/init.d/functions
# Nginx Settings


NGINX_SBIN="/usr/local/nginx/sbin/nginx"
NGINX_COnF="/usr/local/nginx/conf/nginx.conf"
NGINX_PID="/usr/local/nginx/logs/nginx.pid"
RETVAL=0
prog="Nginx"


start() {
        echo -n $"Starting $prog: "
        mkdir -p /dev/shm/nginx_temp
        daemon $NGINX_SBIN -c $NGINX_CONF
        RETVAL=$?
        echo
        return $RETVAL
}


stop() {
        echo -n $"Stopping $prog: "
        killproc -p $NGINX_PID $NGINX_SBIN -TERM
        rm -rf /dev/shm/nginx_temp
        RETVAL=$?
        echo
        return $RETVAL
}


reload(){
        echo -n $"Reloading $prog: "
        killproc -p $NGINX_PID $NGINX_SBIN -HUP
        RETVAL=$?
        echo
        return $RETVAL
}


restart(){
        stop
        start
}


configtest(){
    $NGINX_SBIN -c $NGINX_CONF -t
    return 0
}


case "$1" in
  start)
        start
        ;;
  stop)
        stop
        ;;
  reload)
        reload
        ;;
  restart)
        restart
        ;;
  configtest)
        configtest
        ;;
  *)
        echo $"Usage: $0 {start|stop|reload|restart|configtest}"
        RETVAL=1
esac


exit $RETVAL
保存后,更改?w:
chmod 755 /etc/init.d/nginx
chkconfig --add nginx
如果想开机启动,请执行:
chkconfig nginx on
更改nginx配置
首先把原来的配置文件清空:
> /usr/local/nginx/conf/nginx.conf
“>” 这个符号为重定向的意思,单独用它,可以把一个文本文档快速清空。
vim /usr/local/nginx/conf/nginx.conf
写入如下内容:
user nobody nobody;
worker_processes 2;
error_log /usr/local/nginx/logs/nginx_error.log crit;
pid /usr/local/nginx/logs/nginx.pid;
worker_rlimit_nofile 51200;


events
{
    use epoll;
    worker_connections 6000;
}


http
{
    include mime.types;
    default_type application/octet-stream;
    server_names_hash_bucket_size 3526;
    server_names_hash_max_size 4096;
    log_format combined_realip '$remote_addr $http_x_forwarded_for [$time_local]'
    '$host "$request_uri" $status'
    '"$http_referer" "$http_user_agent"';
    sendfile on;
    tcp_nopush on;
    keepalive_timeout 30;
    client_header_timeout 3m;
    client_body_timeout 3m;
    send_timeout 3m;
    connection_pool_size 256;
    client_header_buffer_size 1k;
    large_client_header_buffers 8 4k;
    request_pool_size 4k;
    output_buffers 4 32k;
    postpone_output 1460;
    client_max_body_size 10m;
    client_body_buffer_size 256k;
    client_body_temp_path /usr/local/nginx/client_body_temp;
    proxy_temp_path /usr/local/nginx/proxy_temp;
    fastcgi_temp_path /usr/local/nginx/fastcgi_temp;
    fastcgi_intercept_errors on;
    tcp_nodelay on;
    gzip on;
    gzip_min_length 1k;
    gzip_buffers 4 8k;
    gzip_comp_level 5;
    gzip_http_version 1.1;
    gzip_types text/plain application/x-Javascript text/css text/htm application/xml;


server
{
    listen 80;
    server_name localhost;
    index index.html index.htm index.php;
    root /usr/local/nginx/html;


    location ~ \.php$ {
        include fastcgi_params;
        fastcgi_pass unix:/tmp/php-fcgi.sock;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME /usr/local/nginx/html$fastcgi_script_name;
    }


}


}
保存配置后,先检验一下配置文件是否有错误存在:
/usr/local/nginx/sbin/nginx  -t
如果显示内容如下,则配置正确,否则需要根据错误提示修改配置文件:
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
启动nginx:
service nginx start
如果不能启动,请查看 “/usr/local/nginx/logs/error.log” 文件,检查nginx是否启动:
ps aux |grep nginx
看是否有进程。

测试是否解析php文件

创建测试文件:
vim /usr/local/nginx/html/2.php
内容如下:

测试:
[root@localhost nginx]# curl localhost/2.php
或者使用浏览器打开http://YourServerIPAddress/2.php

重要:如果解析不了,检查日志发现连接不到php,我的php版本为5.5.23,比较新的版本,需要在php/etc/php-fpm.conf文件中添加
listen.owner = nobody
listen.group = nobody
这两行,再重启一下服务就能使用php了
原因是/tmp/php-fcgi.sock这个文件没有读权限
至此,最新版的LNMP环境源码编译安装完成。


推荐阅读
  • 本文介绍了在Mac上搭建php环境后无法使用localhost连接mysql的问题,并通过将localhost替换为127.0.0.1或本机IP解决了该问题。文章解释了localhost和127.0.0.1的区别,指出了使用socket方式连接导致连接失败的原因。此外,还提供了相关链接供读者深入了解。 ... [详细]
  • 本文介绍了在开发Android新闻App时,搭建本地服务器的步骤。通过使用XAMPP软件,可以一键式搭建起开发环境,包括Apache、MySQL、PHP、PERL。在本地服务器上新建数据库和表,并设置相应的属性。最后,给出了创建new表的SQL语句。这个教程适合初学者参考。 ... [详细]
  • 本文讨论了Alink回归预测的不完善问题,指出目前主要针对Python做案例,对其他语言支持不足。同时介绍了pom.xml文件的基本结构和使用方法,以及Maven的相关知识。最后,对Alink回归预测的未来发展提出了期待。 ... [详细]
  • 在说Hibernate映射前,我们先来了解下对象关系映射ORM。ORM的实现思想就是将关系数据库中表的数据映射成对象,以对象的形式展现。这样开发人员就可以把对数据库的操作转化为对 ... [详细]
  • 本文介绍了在SpringBoot中集成thymeleaf前端模版的配置步骤,包括在application.properties配置文件中添加thymeleaf的配置信息,引入thymeleaf的jar包,以及创建PageController并添加index方法。 ... [详细]
  • 本文介绍了使用cacti监控mssql 2005运行资源情况的操作步骤,包括安装必要的工具和驱动,测试mssql的连接,配置监控脚本等。通过php连接mssql来获取SQL 2005性能计算器的值,实现对mssql的监控。详细的操作步骤和代码请参考附件。 ... [详细]
  • 目录浏览漏洞与目录遍历漏洞的危害及修复方法
    本文讨论了目录浏览漏洞与目录遍历漏洞的危害,包括网站结构暴露、隐秘文件访问等。同时介绍了检测方法,如使用漏洞扫描器和搜索关键词。最后提供了针对常见中间件的修复方式,包括关闭目录浏览功能。对于保护网站安全具有一定的参考价值。 ... [详细]
  • Apache Shiro 身份验证绕过漏洞 (CVE202011989) 详细解析及防范措施
    本文详细解析了Apache Shiro 身份验证绕过漏洞 (CVE202011989) 的原理和影响,并提供了相应的防范措施。Apache Shiro 是一个强大且易用的Java安全框架,常用于执行身份验证、授权、密码和会话管理。在Apache Shiro 1.5.3之前的版本中,与Spring控制器一起使用时,存在特制请求可能导致身份验证绕过的漏洞。本文还介绍了该漏洞的具体细节,并给出了防范该漏洞的建议措施。 ... [详细]
  • PHP组合工具以及开发所需的工具
    本文介绍了PHP开发中常用的组合工具和开发所需的工具。对于数据分析软件,包括Excel、hihidata、SPSS、SAS、MARLAB、Eview以及各种BI与报表工具等。同时还介绍了PHP开发所需的PHP MySQL Apache集成环境,包括推荐的AppServ等版本。 ... [详细]
  • 本文介绍了在无法联网的情况下,通过下载rpm包离线安装zip和unzip的方法。详细介绍了如何搜索并下载合适的rpm包,以及如何使用rpm命令进行安装。 ... [详细]
  • 如何实现织梦DedeCms全站伪静态
    本文介绍了如何通过修改织梦DedeCms源代码来实现全站伪静态,以提高管理和SEO效果。全站伪静态可以避免重复URL的问题,同时通过使用mod_rewrite伪静态模块和.htaccess正则表达式,可以更好地适应搜索引擎的需求。文章还提到了一些相关的技术和工具,如Ubuntu、qt编程、tomcat端口、爬虫、php request根目录等。 ... [详细]
  • Nginx使用AWStats日志分析的步骤及注意事项
    本文介绍了在Centos7操作系统上使用Nginx和AWStats进行日志分析的步骤和注意事项。通过AWStats可以统计网站的访问量、IP地址、操作系统、浏览器等信息,并提供精确到每月、每日、每小时的数据。在部署AWStats之前需要确认服务器上已经安装了Perl环境,并进行DNS解析。 ... [详细]
  • 本文介绍了Python高级网络编程及TCP/IP协议簇的OSI七层模型。首先简单介绍了七层模型的各层及其封装解封装过程。然后讨论了程序开发中涉及到的网络通信内容,主要包括TCP协议、UDP协议和IPV4协议。最后还介绍了socket编程、聊天socket实现、远程执行命令、上传文件、socketserver及其源码分析等相关内容。 ... [详细]
  • 这是原文链接:sendingformdata许多情况下,我们使用表单发送数据到服务器。服务器处理数据并返回响应给用户。这看起来很简单,但是 ... [详细]
  • Java验证码——kaptcha的使用配置及样式
    本文介绍了如何使用kaptcha库来实现Java验证码的配置和样式设置,包括pom.xml的依赖配置和web.xml中servlet的配置。 ... [详细]
author-avatar
江自流
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有