CentOS7下LNMP环境源码安装

对于在Linux系统中安装web服务其实都是差不多的,只是软件的选择不一样,不过在php-5.2.17和以前的版本LNMP环境和以后安装有一点区别,就是启用–enable-fastcgi这个模块。现在我用php-5.3.27来搭建LNMP环境,对于搭建不成功的网友们希望给我留言,大家一起解决问题,一起进步。

CentOS7下LNMP环境源码安装

系统: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 目录下:
[[email protected]
~]# cd /usr/local/src/
[[email protected]
src]# wget

2、将压缩包解压到/usr/local 目录下:
[[email protected]
src]# tar zvxf mariadb-10.0.13-linux-glibc_214-x86_64.tar.gz -C
/usr/local/
3、创建mariadb 数据初始化目录/data/mysql:
[[email protected]
src]# mkdir -p /data/mysql
4、添加系统用户mysql,禁止登陆系统,同时,将mariadb
数据初始化目录所属主和组都修改为mysql:
[[威尼斯网址开户网站 ,email protected]
src]# useradd -r -s /sbin/nologin mysql ;chown -R mysql.mysql
/data/mysql/
5、重命名解压出来的mariadb 目录:
[[email protected]
src]# mv /usr/local/mariadb-10.0.13-linux-x86_64/ /usr/local/mysql
6、进入重命名后的目录,初始化mariadb:
[[email protected]
src]# cd /usr/local/mysql/
[[email protected]
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
.
You can find additional information about the MySQL part at:

Support MariaDB development by buying support/new features from
SkySQL Ab. You can contact us about this
[email protected]
Alternatively consider joining our community based development effort:

报错: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:
[[email protected]
mysql]# cp support-files/my-large.cnf /etc/my.cnf
cp:是否覆盖”/etc/my.cnf”? y
8、复制mysql 启动脚本文件到/etc/init.d 目录下并重命名为mysqld:
[[email protected]
mysql]# cp support-files/mysql.server /etc/init.d/mysqld
同时修改启动脚本的权限为755:
[[email protected]
mysql]# chmod 755 !$
chmod 755 /etc/init.d/mysqld
9、编辑启动脚本,定义datadir 路径:
[[email protected]
mysql]# vim /etc/init.d/mysqld
定义数据存放路径:
datadir=/data/mysql
10、将mariadb自带命令放入$PATH
[[email protected]
~]# PATH=$PATH:/etc/init.d/#当前有效,重启shell就失效
[[email protected]
~]# echo “export PATH=$PATH:/etc/init.d/” >>/etc/profile
[[email protected]
~]# echo “export PATH=$PATH:/usr/local/mysql/bin/”
>>/etc/profile
[[email protected]
~]# source !$

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

第二步,开始安装php

这里要先声明一下,针对Nginx的php安装和针对apache的php安装是有区别的,因为Nginx中的php是以fastcgi的方式结合nginx的,可以理解为nginx代理了php的fastcgi,而apache是把php作为自己的模块来调用的。同样的,php官方下载地址:

下载php
[[email protected]
src]# cd /usr/local/src
[[email protected]
src]# wget
解压php
[[email protected]
src]# tar zxf php-5.5.23.tar.gz
创建相关账户
[[email protected]
src]# useradd -s /sbin/nologin php-fpm
配置编译参数
[[email protected]
src]# cd php-5.5.23
[[email protected]
src]# yum -y install gcc make gd-devel libjpeg-devel libpng-devel
libxml2-devel bzip2-devel libcurl-devel
[[email protected]
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 <curl-dir>/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
[[email protected]
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
解压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
保存后,更改僿:
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
内容如下:
<?php echo phpinfo();?>
测试:
[[email protected]
nginx]# curl localhost/2.php
或者使用浏览器打开

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

系统:CentOS 7 x86_64
NGINX:nginx-1.7.12 数据库:mariadb-10.0.13 PHP:php-5.5.23
首先做一些准备工作,先把centos7的防火墙更…

首先本文转载至阿里云-文档

CentOS
6.3编译安装LNMP环境,安装必要的依赖关系:

1.安装Linux系统    –这一步省略

背景

系统环境:CentOS release 6.8 (Final)
内核:2.6.32-642.el6.x86_64
系统安装方式:图形安装
工具:VMware、Xshell

yum -y install libjpeg libjpeg-devel libpng libpng-devel freetype
freetype-devel libxml2 libxml2-devel zlib zlib-devel bzip2 bzip2-devel
curl curl-devel openssl openssl-devel gd gd-devel libmcrypt
libmcrypt-devel pcre pcre-devel libaio
 
安装必要的工具:

2.安装nginx服务
[[email protected]
samba]# tar xvf nginx-1.3.13.tar.gz
[[email protected]
samba]# cd nginx-1.3.13
[[email protected]
nginx-1.3.13]# ./configure –prefix=/usr/local/nginx  -user=nginx
–group=nginx  –with-http_sub_module –with-http_gunzip_module 
–without-http_rewrite_module –without-http_proxy_module
–without-http_upstream_ip_hash_module
[[email protected]
nginx-1.3.13]# make && make install
[[email protected]
nginx-1.3.13]# echo $?
0
[[email protected]
nginx-1.3.13]# cd /usr/local/nginx/sbin/
[[email protected]
sbin]# ./nginx
[[email protected]
sbin]# netstat -an |grep 80
tcp        0      0 0.0.0.0:80                  0.0.0.0:*             
    LISTEN
[[email protected]
sbin]#

基本流程

  • 准备编译环境
  • 安装nginx
  • 安装MySQL
  • 安装php-fpm
  • 测试访问

yum -y install gcc gcc-c++ make
 
编译安装mcrypt:

3.测试nginx服务是否正常启动

步骤一:准备编译环境

  • 关闭selinux
    修改配置文件,重启服务后永久生效。

# sed -i 's/SELINUX=.*/SELINUX=disabled/g' /etc/selinux/config

命令行设置立即生效。

# setenforce 0

所需软件包:
nginx-1.10.2.tar.gz
mysql-5.6.24.tar.gz
php-5.6.23.tar.bz2
下载导航

1.首先安装Libmcrypt:

威尼斯网址开户网站 1

步骤二:安装nginx

Nginx是一个小巧而高效的Linux下的Web服务器软件,是由 Igor Sysoev
为俄罗斯访问量第二的 Rambler.ru
站点开发的,已经在一些俄罗斯的大型网站上运行多年,目前很多国内外的门户网站、行业网站也都在是使用Nginx,相当稳定。

  • 1、添加运行nginx服务进程的用户

# groupadd -r nginx    
# useradd -r -g nginx  nginx
  • 2、下载源码包解压编译。

# wget http://nginx.org/download/nginx-1.10.2.tar.gz
# tar xvf nginx-1.10.2.tar.gz -C /usr/local/src
# yum groupinstall "Development tools"
# yum -y install gcc wget gcc-c++ automake autoconf libtool libxml2-devel libxslt-devel perl-devel perl-ExtUtils-Embed pcre-devel openssl-devel
# cd /usr/local/src/nginx-1.10.2
# ./configure \
--prefix=/usr/local/nginx \
--sbin-path=/usr/sbin/nginx \
--conf-path=/etc/nginx/nginx.conf \
--error-log-path=/var/log/nginx/error.log \
--http-log-path=/var/log/nginx/access.log \
--pid-path=/var/run/nginx.pid \
--lock-path=/var/run/nginx.lock \
--http-client-body-temp-path=/var/tmp/nginx/client \
--http-proxy-temp-path=/var/tmp/nginx/proxy \
--http-fastcgi-temp-path=/var/tmp/nginx/fcgi \
--http-uwsgi-temp-path=/var/tmp/nginx/uwsgi \
--http-scgi-temp-path=/var/tmp/nginx/scgi \
--user=nginx \
--group=nginx \
--with-pcre \
--with-http_v2_module \
--with-http_ssl_module \
--with-http_realip_module \
--with-http_addition_module \
--with-http_sub_module \
--with-http_dav_module \
--with-http_flv_module \
--with-http_mp4_module \
--with-http_gunzip_module \
--with-http_gzip_static_module \
--with-http_random_index_module \
--with-http_secure_link_module \
--with-http_stub_status_module \
--with-http_auth_request_module \
--with-mail \
--with-mail_ssl_module \
--with-file-aio \
--with-ipv6 \
--with-http_v2_module \
--with-threads \
--with-stream \
--with-stream_ssl_module
# make && make install
# mkdir -pv /var/tmp/nginx/client
  • 3、添加SysV启动脚本。

# vim /etc/init.d/nginx
#!/bin/sh 
# 
# nginx - this script starts and stops the nginx daemon 
# 
# chkconfig:   - 85 15 
# description: Nginx is an HTTP(S) server, HTTP(S) reverse \ 
#               proxy and IMAP/POP3 proxy server 
# processname: nginx 
# config:      /etc/nginx/nginx.conf 
# config:      /etc/sysconfig/nginx 
# pidfile:     /var/run/nginx.pid 
# Source function library. 
. /etc/rc.d/init.d/functions
# Source networking configuration. 
. /etc/sysconfig/network
# Check that networking is up. 
[ "$NETWORKING" = "no" ] && exit 0
nginx="/usr/sbin/nginx"
prog=$(basename $nginx)
NGINX_CONF_FILE="/etc/nginx/nginx.conf"
[ -f /etc/sysconfig/nginx ] && . /etc/sysconfig/nginx
lockfile=/var/lock/subsys/nginx
start() {
    [ -x $nginx ] || exit 5
    [ -f $NGINX_CONF_FILE ] || exit 6
    echo -n $"Starting $prog: " 
    daemon $nginx -c $NGINX_CONF_FILE
    retval=$?
    echo 
    [ $retval -eq 0 ] && touch $lockfile
    return $retval
}
stop() {
    echo -n $"Stopping $prog: " 
    killproc $prog -QUIT
    retval=$?
    echo 
    [ $retval -eq 0 ] && rm -f $lockfile
    return $retval
killall -9 nginx
}
restart() {
    configtest || return $?
    stop
    sleep 1
    start
}
reload() {
    configtest || return $?
    echo -n $"Reloading $prog: " 
    killproc $nginx -HUP
RETVAL=$?
    echo 
}
force_reload() {
    restart
}
configtest() {
$nginx -t -c $NGINX_CONF_FILE
}
rh_status() {
    status $prog
}
rh_status_q() {
    rh_status >/dev/null 2>&1
}
case "$1" in
    start)
        rh_status_q && exit 0
    $1
        ;;
    stop)
        rh_status_q || exit 0
        $1
        ;;
    restart|configtest)
        $1
        ;;
    reload)
        rh_status_q || exit 7
        $1
        ;;
    force-reload)
        force_reload
        ;;
    status)
        rh_status
        ;;
    condrestart|try-restart)
        rh_status_q || exit 0
            ;;
    *)
      echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|force-reload|configtest}" 
        exit 2
esac
  • 4、赋予脚本执行权限。

# chmod +x /etc/init.d/nginx
  • 5、添加至服务管理列表,设置开机自启。

# chkconfig --add nginx
# chkconfig  nginx on
  • 6、启动服务。

# service nginx start

  • 7、浏览器访问可看到默认欢迎页面。

    威尼斯网址开户网站 2

    nginx.org

   
下载地址:

2.安装mysql数据库软件
[[email protected]
samba]# tar xvf mysql-5.1.51.tar.gz
[[email protected]
samba]# cd mysql-5.1.51
[[email protected]
mysql-5.1.51]# ./configure –prefix=/usr/local/mysql-5.1
[[email protected]
mysql-5.1.51]# make && make install
[[email protected]
mysql-5.1.51]# cd /usr/local/mysql-5.1/bin  –进入安装mysql目录
[[email protected]
bin]# ./mysqld_safe &    –启动数据库
[[email protected]
bin]# netstat -an | grep 3306    –检查mysql是否启动
tcp        0      0 0.0.0.0:3306                0.0.0.0:*             
    LISTEN
[[email protected]
bin]# mysql -u root -p  –登陆数据库,密码为空
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 108
Server version: 5.1.51-log Source distribution
Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights
reserved.
This software comes with ABSOLUTELY NO WARRANTY. This is free
software,
and you are welcome to modify and redistribute it under the GPL v2
license
Type ‘help;’ or ‘\h’ for help. Type ‘\c’ to clear the current input
statement.
mysql>

步骤三:安装mysql

  • 1、准备编译环境。

  1. # yum groupinstall "Server Platform Development"  "Development tools" -y
  2. # yum install cmake -y
  • 2、准备mysql数据存放目录。

1.  # mkdir /mnt/data
2.  # groupadd -r mysql
3.  # useradd -r -g mysql -s /sbin/nologin mysql
4.  # id mysql
5.  uid=495(mysql) gid=492(mysql) groups=492(mysql)
  • 3、更改数据目录属主属组。

# chown -R mysql:mysql /mnt/data

# mv /etc/my.cnf{,.bak}
:在CentOS
6.5版操作系统的最小安装完成后,在/etc目录下会存在一个my.cnf,需要将此文件更名为其他的名字,如:/etc/my.cnf.bak,否则,该文件会干扰源码安装的MySQL的正确配置,造成无法启动。虽然我的环境是centOS
6.8的,但也这么做了。

  • 4、解压编译在MySQL官网下载的稳定版源码包,这里使用的是5.6.24版本
  1. # tar xvf mysql-5.6.24.tar.gz -C /usr/local/src
  2. # cd /usr/local/src/mysql-5.6.24
  3. # cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mysql \
  4. -DMYSQL_DATADIR=/mnt/data \
  5. -DSYSCONFDIR=/etc \
  6. -DWITH_INNOBASE_STORAGE_ENGINE=1 \
  7. -DWITH_ARCHIVE_STORAGE_ENGINE=1 \
  8. -DWITH_BLACKHOLE_STORAGE_ENGINE=1 \
  9. -DWITH_READLINE=1 \
  10. -DWITH_SSL=system \
  11. -DWITH_ZLIB=system \
  12. -DWITH_LIBWRAP=0 \
  13. -DMYSQL_TCP_PORT=3306 \
  14. -DMYSQL_UNIX_ADDR=/tmp/mysql.sock \
  15. -DDEFAULT_CHARSET=utf8 \
  16. -DDEFAULT_COLLATION=utf8_general_ci
  17. # make && make install
    编译挺慢的,请耐心等待……
  • 5、修改安装目录的属组为mysql。

# chown -R mysql:mysql /usr/local/mysql/

  • 6、初始化数据库。
    # cd /usr/local/mysql
    # /usr/local/mysql/scripts/mysql_install_db --user=mysql --datadir=/mnt/data/

  • 7、拷贝配置文件和启动脚本。

# cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
# chmod +x /etc/init.d/mysqld
# cp support-files/my-default.cnf /etc/my.cnf
  • 8、设置开机自动启动。
  1. # chkconfig mysqld on
  2. # chkconfig --add mysqld
  • 9、修改配置文件中的安装路径及数据目录存放路径。

# echo -e "basedir = /usr/local/mysql\ndatadir = /mnt/data\n" >> /etc/my.cnf

  • 10、设置PATH环境变量。
  1. # echo "export PATH=$PATH:/usr/local/mysql/bin" > /etc/profile.d/mysql.sh
  2. # source /etc/profile.d/mysql.sh
  • 11、启动服务。
  1. # service mysqld start
  2. # mysql -h 127.0.0.1

  tar -zxvf libmcrypt-2.5.8.tar.gz
  cd libmcrypt-2.5.8
  ./configure
  make
  make install
 

3.安装php软件
[[email protected]
samba]# tar xvf php-5.3.27.tar.gz
[[email protected]
samba]# cd php-5.3.27
[[email protected]
php-5.3.27]# ./configure –prefix=/usr/local/php-5.3.27 –enable-fpm
–with-gd –with-mysql=/usr/local/mysql5.1/
–with-mysqli=/usr/local/mysql5.1/bin/mysql_config  –with-png-dir
–with-jpeg-dir  –with-zlib  –with-ldap –with-curl –with-snmp
–with-freetype-dir
[[email protected]
php-5.3.27]# make && make install
[[email protected]
php-5.3.27]# cd /usr/local/php-5.3.27/etc/
[[email protected]
etc]# cp -a php-fpm.conf.default php-fpm.conf
[[email protected]
etc]# cp /home/samba/php-5.3.27/php.ini-development  php.ini

步骤四:安装php-fpm

Nginx本身不能处理PHP,作为web服务器,当它接收到请求后,不支持对外部程序的直接调用或者解析,必须通过FastCGI进行调用。如果是PHP请求,则交给PHP解释器处理,并把结果返回给客户端。PHP-FPM是支持解析php的一个FastCGI进程管理器。提供了更好管理PHP进程的方式,可以有效控制内存和进程、可以平滑重载PHP配置。

  • 1、安装依赖包。

# yum install libmcrypt libmcrypt-devel mhash mhash-devel libxml2 libxml2-devel bzip2 bzip2-devel

:libmcrypt libmcrypt-devel mhash
mhash-devel这四个包是epel源里的,如果找不到安装包,请配置EPEL源
yum install epel-release

  • 2、解压官网下载的源码包,编译安装。

# tar xvf php-5.6.23.tar.bz2 -C /usr/local/src
# cd /usr/local/src/php-5.6.23
# ./configure --prefix=/usr/local/php \
--with-config-file-scan-dir=/etc/php.d \
--with-config-file-path=/etc \
--with-mysql=/usr/local/mysql \
--with-mysqli=/usr/local/mysql/bin/mysql_config \
--enable-mbstring \
--with-freetype-dir \
--with-jpeg-dir \
--with-png-dir \
--with-zlib \
--with-libxml-dir=/usr \
--with-openssl \
-enable-xml \
--enable-sockets \
--enable-fpm \
--with-mcrypt \
--with-bz2
# make && make install

在make的时候报错如下:
make: warning: Clock skew detected. Your build may be incomplete
可能是系统时间不对的问题

快捷修改系统时间# date 072611002006.30 月日时分 年 .秒

永久修改系统时间


  • 3、添加php和php-fpm配置文件。

# cp /usr/local/src/php-5.6.23/php.ini-production /etc/php.ini
# cd /usr/local/php/etc/
# cp php-fpm.conf.default php-fpm.conf
# sed -i 's@;pid = run/php-fpm.pid@pid = /usr/local/php/var/run/php-fpm.pid@' php-fpm.conf
  • 4、添加php-fpm启动脚本。

# cp /usr/local/src/php-5.6.23/sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
# chmod +x /etc/init.d/php-fpm
  • 5、添加php-fpm至服务列表并设置开机自启。

# chkconfig --add php-fpm     
# chkconfig --list php-fpm     
# chkconfig php-fpm on
  • 6、启动服务。

# service php-fpm start

  • 7、添加nginx对fastcgi的支持,首先备份默认的配置文件。

# cp /etc/nginx/nginx.conf /etc/nginx/nginx.confbak
# cp /etc/nginx/nginx.conf.default /etc/nginx/nginx.conf

编辑/etc/nginx/nginx.conf,在所支持的主页面格式中添加php格式的主页,类似如下:

    location / {
        root   /usr/local/nginx/html;
        index  index.php index.html index.htm;
    }

取消以下内容前面的注释:

   location ~ \.php$ {
        root           /usr/local/nginx/html;
        fastcgi_pass    127.0.0.1:9000;
        fastcgi_index   index.php;
        fastcgi_param  SCRIPT_FILENAME  /usr/local/nginx/html/$fastcgi_script_name;
        include        fastcgi_params;
    }

重新载入nginx的配置文件。

# service nginx reload

在/usr/local/nginx/html/新建index.php的测试页面,内容如下。

<?php
$conn=mysql_connect('127.0.0.1','root','');
if ($conn){
  echo "LNMP platform connect to mysql is successful!";
}else{
  echo "LNMP platform connect to mysql is failed!";
}
 phpinfo();
?>

浏览器访问测试,如看到以下内容则表示LNMP平台构建完成。

威尼斯网址开户网站 3

phpinfo

2.安装mhash

4.nginx和php相接合
[[email protected]
etc]# cd /usr/local/nginx/conf/
[[email protected]
conf]# vim nginx.conf    –去掉以下注释
location ~ \.php$ {
root          html;
fastcgi_pass  127.0.0.1:9000;
fastcgi_index  index.php;
fastcgi_param  SCRIPT_FILENAME 
$document_root$fastcgi_script_name;
include        fastcgi_params;
}
[[email protected]
conf]# vim ../html/index.php    –创建php首页文件
<?php
phpinfo();
?>

    下载地址:

5.启动服务,并测试 
[[email protected]
conf]# /usr/local/php-5.3.27/sbin/php-fpm
[[email protected]
conf]# /usr/local/nginx/sbin/nginx
[[email protected]
conf]# netstat -an |more
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address              Foreign Address         
  State
tcp        0      0 127.0.0.1:9000              0.0.0.0:*             
    LISTEN
tcp        0      0 0.0.0.0:80                  0.0.0.0:*             
    LISTEN

  tar -zxvf mhash-0.9.9.9.tar.gz
  cd mhash-0.9.9.9
  ./configure
  make
  make install

威尼斯网址开户网站 4

3.安装mcrypt

Ubuntu 13.04 安装 LAMP\Vsftpd\Webmin\phpMyAdmin 服务及设置

    下载地址:

CentOS 6.4 下的LNMP 生产环境搭建及安装脚本

  tar -zxvf mcrypt-2.6.8.tar.gz
  cd mcrypt-2.6.8
  export LD_LIBRARY_PATH=/usr/local/lib
  ./configure
  make
  make install
 
编译安装Nginx

生产环境实用之LNMP架构的编译安装+SSL加密实现

./configure –prefix=/usr/local/nginx –user=www –group=www
–with-http_stub_status_module
make && make install
 
编译安装MYSQL

LNMP 全功能编译安装 for CentOS 6.3笔记

下载MYSQL源码,按照INSTALL-BINARY文档里面的说明部署即可~
 
编译安装PHP

CentOS 6.3 安装LNMP (PHP 5.4,MyySQL5.6)

PHP编译参数:
./configure –prefix=/usr/local/php \
–with-libxml-dir \
–with-zlib \
–with-curl \
–enable-exif \
–with-gd \
–with-jpeg-dir \
–with-png-dir \
–with-freetype-dir \
–with-gettext \
–with-openssl \
–with-mcrypt \
–with-mysql=/usr/local/mysql \
–with-mysqli=/usr/local/mysql/bin/mysql_config \
–with-pdo-mysql=/usr/local/mysql \
–enable-soap \
–with-iconv \
–with-pear \
–enable-sockets \
–enable-fpm \
–enable-pcntl \
–enable-mbstring \
–enable-fileinfo \
 
make && make install
 
将/usr/local/php/etc/下的php-fpm.conf.default 改为 php-fpm.conf

在部署LNMP的时候遇到Nginx启动失败的2个问题

PS:

Ubuntu安装Nginx php5-fpm MySQL(LNMP环境搭建)

   
1.一个小技巧,安装完成之后把php目录改成php+版本号,然后再做一个链接到这个目录,方便以后多个版本的替换
 
lrwxrwxrwx.  1 root root    9 6月  22 07:03 php -> php5.6.9/
drwxr-xr-x.  9 root root  4096 6月  21 11:03 php5.6.9
drwxr-xr-x.  9 root root  4096 6月  21 10:38 php7.0.0
 

    2.如果安装的是php7,还要把/usr/local/php/etc/php-fpm.d
目录的www.conf.default改成www.conf

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

Ubuntu 13.04 安装 LAMP\Vsftpd\Webmin\phpMyAdmin 服务及设置
http://www.linuxidc.com/Linux/2013-06/86250.htm

CentOS 6.4 下的LNMP 生产环境搭建及安装脚本
http://www.linuxidc.com/Linux/2013-11/92428.htm

生产环境实用之LNMP架构的编译安装+SSL加密实现
http://www.linuxidc.com/Linux/2013-05/85099.htm

LNMP 全功能编译安装 for CentOS 6.3笔记
http://www.linuxidc.com/Linux/2013-05/83788.htm

CentOS 6.3 安装LNMP (PHP 5.4,MyySQL5.6)
http://www.linuxidc.com/Linux/2013-04/82069.htm

在部署LNMP的时候遇到Nginx启动失败的2个问题
http://www.linuxidc.com/Linux/2013-03/81120.htm

Ubuntu安装Nginx php5-fpm MySQL(LNMP环境搭建)
http://www.linuxidc.com/Linux/2012-10/72458.htm

更多CentOS相关信息见CentOS 专题页面 http://www.linuxidc.com/topicnews.aspx?tid=14

本文永久更新链接地址:http://www.linuxidc.com/Linux/2015-10/123844.htm

威尼斯网址开户网站 5

相关文章