centos下编译安装LNMP环境

自PHP-5.3.3起,PHP-FPM加入到了PHP核心,编译时加上--enable-fpm即可提供支持。 PHP-FPM以守护进程在后台运行,Nginx响应请求后,自行处理静态请求,PHP请求则经过fastcgi_pass交由PHP-FPM处理,处理完毕后返回。 Nginx和PHP-FPM的组合,是一种稳定、高效的PHP运行方式,效率要比传统的Apache和mod_php高出不少。

二.依赖环境

yum -y install gcc gcc-c++ make cmake automake autoconf cpp ncurses ncurses-devel libxml2-devel openssl-devel curl-devel libjpeg-devel libpng-devel pcre-devel libtool libtool-libs freetype-devel gd zlib-devel bison  readline-devel glibc-devel glib2-devel bzip2-devel gettext-devel libcap-devel libmcrypt-devel libxml2-devel curl-devel libpng-devel openldap-devel

三.系统说明

1.centos6.4 IP:10.10.54.157

2.软件版本:nginx1.4.5+mysql5.5+php5.4

四.编译安装nginx1.4.5

1.下载nginx1.4.5
shell> wget
2.解压nginx.1.4.5
shell> tar xvf nginx-1.4.5.tar.gz

3.编译安装

shell> ./configure --prefix=/usr/local/nginx --with-pcre --with-http_stub_status_module --user=apache --group=apache --with-http_ssl_module --with-http_gzip_static_module --with-pcre=/usr/local/src/pcre-8.21 --lock-path=/var/run/nginx.lock --pid-path=/var/run/nginx.pid

shell> make && make install
4.启动nginx
shell> /usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
5.打开浏览器测试是否可以访问

五.编译安装mysql5.5

1.编译安装
shell> groupadd mysql && useradd -g mysql mysql -s /sbin/nologin
shell> mkdir -p /data/mysql
shell> cd /home/softs/mysql-5.5.30
shell> cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_DATADIR=/data/dbdata -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_PARTITION_STORAGE_ENGINE=1 -DWITH_PERFSCHEMA_STORAGE_ENGINE=1 -DWITH_BLACKHOLE_STORAGE_ENGINE=1 -DWITH_ARCHIVE_STORAGE_ENGINE=1 -DWITH_MYISAM_STORAGE_ENGINE=1 -DMYSQL_TCP_PORT=3306 -DENABLED_LOCAL_INFILE=1 -DWITH_EXTRA_CHARSETS=all -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DWITH_SSL=yes
shell> make && make install

#配置
shell> cp -f /home/softs/mysql-5.5.30/support-files/my-large.cnf /etc/my.cnf
shell> cp -f /home/softs/mysql-5.5.30/support-files/mysql.server /etc/init.d/mysqld

shell> chmod 755 /etc/init.d/mysqld
shell> vim /etc/my.cnf
---------------------------
[mysqld
datadir=/data/mysql
socket=/usr/local/mysql/tmp/mysql.sock
---------------------------

shell> chown mysql.mysql /usr/local/mysql -R
#初始化数据库
shell> /usr/local/mysql/scripts/mysql_install_db --user=root --datadir=/data/mysql --basedir=/usr/local/mysql
shell> chown mysql.mysql /data/mysql -R
shell> /etc/init.d/mysqld restart
#添加环境变量
shell> echo "export PATH=${PATH}:/usr/local/mysql/bin" >> /etc/profile

六.编译安装php5.4

1.编译前说明
#yum安装运行环境
shell> yum –y install libxml2-devel curl-devel libpng-devel openldap-devel
#安装PHP前需要编译安装这两个源码包:libmcrypt mhash
#nginx使用fpm的方式条用php,php5.4以后版本中已经支持php-fpm,所以只需要在php编译参数里指定--enable-fpm即可

2.首先安装libmcrypt-2.5.8
wget http://pkgs.fedoraproject.org/repo/pkgs/libmcrypt/libmcrypt-2.5.7.tar.gz/b1be163143f8e8ed0474beeb642b3bad/libmcrypt-2.5.7.tar.gz
tar xvf libmcrypt-2.5.7.tar.gz
cd libmcrypt-2.5.7
./configure
make && make install

3.安装mhash-0.9.9.9
wget http://sourceforge.net/projects/mhash/files/mhash/0.9.9.9/mhash-0.9.9.9.tar.bz2/download
tar -jxvf mhash-0.9.9.9.tar.bz2
cd mhash-0.9.9.9
./configure
make && make install

4.建立软连接到/usr/lib
ln -s /usr/local/lib/libmcrypt* /usr/lib
ln -s /usr/local/lib/libmhash.* /usr/lib

ln -s /usr/local/bin/libmcrypt-config /usr/bin/libmcrypt-config

ln -s /usr/lib64/libldap* /usr/lib/

ln -s /usr/local/mysql/lib/libmysqlclient* /usr/lib/

ldconfig

5.安装php5.4
tar xvf php-5.4.25.tar.gz
cd php-5.4.25

./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --with-mysql=/usr/local/mysql --with-mysqli=/usr/local/mysql/bin/mysql_config --with-iconv --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-gd --enable-gd-native-ttf --with libxml-dir --enable-xml --disable-rpath  --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --with-curl --with-curlwrappers --enable-mbregex --enable-fpm --enable-mbstring --with-mcrypt --with-openssl --with-mhash --enable-pcntl --enable-sockets --with-ldap --with-ldap-sasl --with-xmlrpc --enable-zip --enable-soap --without-pear

【error1】
configure: error: Cannot find ldap libraries in /usr/lib.
【solution1】
shell> ln -s /usr/lib64/libldap* /usr/lib/
shell> ldconfig
【error2】
Generating phar.php
/home/softs/php-5.4.25/sapi/cli/php: error while loading shared libraries: libmysqlclient.so.18: cannot open shared object file: No such file or directory
make: *** [ext/phar/phar.php] Error 127
【solution2】
shell> ln -s /usr/local/mysql/lib/libmysqlclient* /usr/lib/
shell> ldconfig

shell> make && make install

PHP安装涉及的软件包:
php5                            - 服务器端PHP解释器
php5-cgi                      - 服务器端PHP-CGI解释器
php5-cli                       - PHP5命令行工具
iphp5-common           - PHP5一些基本文件
php5-fpm                    - 服务器端PHP-FPM程序 这个程序对Nginx处理PHP很重要
php5-gd                      - PHP5的GD模块 GD是一套开源图像处理库,一般dz生成缩略图或者加水印需要他
php5-imagick              - PHP5的ImageMagick模块 DZ支持调用其用以提供比GD跟快以及更高效的图像处理
php5-imap                   - PHP5的IMAP模块 论坛的邮件发送功能可能需要
php5-ldap                    - PHP5的LDAP模块 LDAP是一个轻量级目录服务
php5-mcrypt                - PHP5的MCrypt模块 主要用途是数据加密,比如phpmyadmin就会要求提供此模块来提供更高的安全性
php5-mysql                  - PHP5的MySQL模块 如果想让你的网站可以访问数据库,此模块必备
php5-snmp                   - PHP5的SNMP模块 SNMP是简单网络管理协议的缩写,主要用于从一些设备以及服务器读取信息。部分监控软件可能会用到
php5-sqlite                   - PHP5的SQLite模块 SQLite是一个轻量级的数据库,某些软件可能需要
php5-xmlrpc                 - PHP5的XML-RPC

七.安装php扩展

1.安装php扩展库:memcache

tar zxvf memcache-2.2.5.tgz

cd memcache-2.2.5/

/usr/local/php/bin/phpize

./configure--with-php-config=/usr/local/php/bin/php-config

make && make install

2.安装php加速:eaccelerator

tar-zxvf eaccelerator-eaccelerator-42067ac.tar.gz

cd eaccelerator-eaccelerator-42067ac

/usr/local/php/bin/phpize

./configure --enable-eaccelerator=shared --with-php-config=/usr/local/php/bin/php-config

make && make install

12 修改php.ini增加memcache,ea等软件信息

添加memcache库的位置:

vim /usr/local/php/php.ini

extension_dir = "/usr/local/php/lib/php/extensions/no-debug-non-zts-20100525"

extension = "memcache.so"

extension = "pdo_mysql.so"

extension = "imagick.so"

添加eaccelerator库的位置信息:

[eaccelerator]

zend_extension="/usr/local/php/lib/php/extensions/no-debug-non-zts-20100525/eaccelerator.so"

eaccelerator.shm_size="1"

eaccelerator.cache_dir="/usr/local/eaccelerator_cache"

eaccelerator.enable="1"

eaccelerator.optimizer="1"

eaccelerator.check_mtime="1"

eaccelerator.debug="0"

eaccelerator.filter=""

eaccelerator.shm_max="0"

eaccelerator.shm_ttl="3600"

eaccelerator.shm_prune_period="3600"

eaccelerator.shm_only="0"

eaccelerator.compress="1"

eaccelerator.compress_level="9"

eaccelerator.keys = "disk_only"

eaccelerator.sessions = "disk_only"

eaccelerator.content = "disk_only"

mkdir -p /usr/local/eaccelerator_cache

chmod 0777 /usr/local/eaccelerator_cache

七.配置nginx支持php

1.首先为php创建配置文件:
cp php.ini-production /usr/local/php/php.ini
mv /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf
ln -s /usr/local/php/bin/php /usr/bin/

2.配置php-fpm.conf
vi /usr/local/php/etc/php-fpm.conf
--------------------------------
listen = /var/run/php-fpm.sock   # 使用unix socket
--------------------------------
#启动php-fpm
/usr/local/php/sbin/php-fpm
shell> ps aux | grep php-fpm   #查看php-fpm是否成功
root      3412  0.0  0.0 103236   892 pts/3    S+   13:56   0:00 grep php-fpm
root     29811  0.0  0.5 281608  5280 ?        Ss   Mar12   0:05 php-fpm: master process (/usr/local/php/etc/php-fpm.conf)
nobody   29812  0.0  1.5 290576 15832 ?        S    Mar12   0:00 php-fpm: pool www          
nobody   29813  0.0  1.8 293496 19064 ?        S    Mar12   0:01 php-fpm: pool www          
nobody   30839  0.0  1.1 286492 11300 ?        S    Mar12   0:00 php-fpm: pool www

3.配置nginx,添加支持php
vi /usr/local/nginx/conf/nginx.conf
-------------------------------------------------------------
http {
server {
           listen       80;
           server_name  localhost;
           charset uft-8;
           access_log  logs/host.access.log;
           location / {
           #默认网站根目录
           root  /var/www/bbs;    
           # 添加index.php的首页文件
           index  index.php index.html index.htm;  
           }
           #添加下面的内容,注意$document_root在默认配置文件中没有
           location ~ \.php$ {
           fastcgi_pass        unix:/var/run/php-fpm/php-fpm.sock;
           fastcgi_index       index.php;
           fastcgi_param SCRIPT_FILENAME $document_root/$fastcgi_script_name;
           include fastcg  i_params;
           include fastcgi.conf;
           }
      }
  }
------------------------------------------------------------
#修改完之后重启nginx

//支持ssl加密传输

--------------------------------------------------------------
user  apache apache;
worker_processes  2;
error_log  logs/error_nginx.log;
pid        logs/nginx.pid;
events {
   worker_connections  1024;
}

http {
           include       mime.types;
           default_type  application/octet-stream;
           log_format  main  ‘$remote_addr - $remote_user [$time_local] "$request" ‘
                     ‘$status $body_bytes_sent "$http_referer" ‘
                     ‘"$http_user_agent" "$http_x_forwarded_for"‘;
           access_log  logs/access_nginx.log  main;
           sendfile        on;
           tcp_nopush     on;
           keepalive_timeout  65;
           gzip  on;
#虚拟主机配置文件
#           include virtual/www.zijian.com.conf;

server {
#https加密协议默认端口
           listen       443;

server_name  bbs.zijian.com;
           charset uft-8;
           access_log logs/bbs.access.log main;

#网站根目录
           root /var/www/bbs;        
           index index.php index.html;
           location ~ \.php$ {
           fastcgi_pass        unix:/var/run/php-fpm.sock;
           fastcgi_index       index.php;
           fastcgi_param SCRIPT_FILENAME $document_root/$fastcgi_script_name;
           include fastcgi_params;
           include fastcgi.conf;
           }

#配置ssl,证书用openssl工具生成,下面的路径是证书的存放目录,证书需要用系统自带的openssl工具生成
#访问这个server时候,用https://xxx.com格式
          ssl         on;
          ssl_certificate      /usr/local/nginx/conf/ssl/client.pem;
          ssl_certificate_key  /usr/local/nginx/conf/ssl/client.key;
       }
}
-------------------------------------------------------------------

centos下编译安装LNMP环境

时间: 2024-08-02 02:41:10

centos下编译安装LNMP环境的相关文章

CentOS编译安装LNMP环境

这里是教大家如何在centos下利用源码编译安装LNMP环境. 工具/原料 centos服务器一台 自用电脑一台 准备篇 配置好IP.DNS .网关,确保使用远程连接工具能够连接服务器 配置防火墙,开启80端口.3306端口 vi /etc/sysconfig/iptables   #编辑防火墙配置文件 -A INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT(允许80端口通过防火墙) -A INPUT -m state -

Centos 6.8编译安装LNMP环境

Centos 6.8编译安装LNMP环境 参考资料: http://www.jb51.net/article/107429.htm https://phperzh.com/articles/1360 一 准备工作 环境介绍: OS:Centos 6.8 最小化安装 Nginx:nginx-1.12.2.tar.gz mysql:mysql-boost-5.7.20.tar.gz php:php-7.2.0.tar.bz2 1.1.关闭SELINUX # 修改配置文件,重启服务后永久生效. sed

SaltStack之编译安装LNMP环境

使用saltstack编译安装LNMP环境 一,系统版本查看 二,安装salt-master和salt-minion 安装配置过程参考SaltStack概述及安装 三,修改配置文件 /etc/salt/master设置根的两个目录 四,设置Nginx安装文档 目录结构为 其中files文件夹下面放置的是源码包 install.sls是安装配置文件 install.sls include: - pkg.make nginx: user.present: - uid: 1001 nginx-inst

centos 下编译安装mysql5.1与mysql5.5

mysql5.1.60编译安装 1.tar -zxvf mysql* 2../configure 之前要make clean ./configure --prefix=/home/shk/mysql-5.1.60 \ --enable-local-infile \ --with-unix-socket-path=/home/shk/mysql-5.1.60/var/mysql.sock \ --with-tcp-port=5506 \ --enable-thread-safe-client \

转:在CentOS下编译安装GCC

转:https://teddysun.com/432.html 在CentOS下编译安装GCC 技术  秋水逸冰  发布于: 2015-09-02  更新于: 2015-09-02  6519 次围观  14 次吐槽 我们知道,关于 GCC 在 CentOS 下通过 yum 安装默认版本号,CentOS 5 是 4.1.2:CentOS 6 是 4.4.7:CentOS 7 是 4.8.3.很多时候在编译安装软件都需要高版本的 GCC,否则就会报错.那么如何升级 GCC 的版本呢? 首先要确认升

linux的ubuntu和centos下快速安装LAMP环境

在linux下安装lamp环境,下面为大家分别介绍在ubuntu和centos下面快速安装LAMP环境的方法. 首先,让我们了解一下什么是LAMP环境(一下摘自百度百科): Linux+Apache+Mysql/MariaDB+Perl/PHP/Python一组常用来搭建动态网站或者服务器的开源软件,本身都是各自独立的程序,但是因为常被放在一起使用,拥有了越来越高的兼容度,共同组成了一个强大的Web应用程序平台.随着开源潮流的蓬勃发展,开放源代码的LAMP已经与J2EE和.Net商业软件形成三足

centos6.7下编译安装lnmp

很多步骤不说明了,请参照本人的centos6.7下编译安装lamp,这次的架构是nginx+php-fpm一台服务器,mysql一台服务器 (1)首先编译安装nginx: 操作命令: yum -y groupinstall "Development Tools" "Server Platform Development" yum -y install pcre-devel  useradd -r nginx  mkdir /var/tmp/nginx   事先得创建

CentOS 6.6 环境下 编译安装LNMP

环境:      OS:     CentOS 6.6     IP: 172.16.66.100    Nginx:  nginx-1.6.2    PHP:     php-5.4.40    Xcache: xcache-3.2.0    Mysql:  mariadb-5.5.43 一.前期环境准备: 1.根据官方ISO 创建本地yum源[[email protected] ~]# mkdir /mnt/cd [[email protected] ~]# mount /dev/cdrom

基于CentOS 6.8平台最新源代码包编译安装LNMP环境搭建(Nginx+MySQL+PHP)

部署环境 系统:CentOS 6.8 x86_64 Nginx:1.11.3 MySQL:5.7.14 PHP:7.0.10 pcre:8.39 zlib:1.2.8 openssl:1.0.1t freetype:2.6.5 libmcrypt:2.5.8 boost:1.59.0 cmake:3.6.1 部署准备 使用客户机浏览器访问freetype官网 https://www.freetype.org/ 下载页面选取一个下载地址 下载目前最新发行版本,右击-复制下载链接. 在CentOS服