Centos搭建PHP5.3.8+Nginx1.0.9+Mysql5.5.17详细配置

操作环境

  操作系统:Mac Os Lion
  虚拟主机:VMware Fusion
  虚拟系统:Centos 5.5+
  操作用户:Root
  实现目的:搭建LNMP环境.

安装依赖库和开发环境


代码如下:

yum -y install gcc gcc-c++ autoconf libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel zlib zlib-devel glibc glibc-devel glib2 glib2-devel bzip2 bzip2-devel ncurses ncurses-devel curl curl-devel e2fsprogs e2fsprogs-devel krb5 krb5-devel libidn libidn-devel openssl openssl-devel openldap openldap-devel nss_ldap openldap-clients openldap-servers

#Nginx
yum -y install pcre-devel zlib-devel

#Php
yum -y install gd-devel libjpeg-devel libpng-devel freetype-devel libxml2-devel curl-devel freetype-devel

#Mysql
yum -y install bison gcc gcc-c++ autoconf automake zlib* libxml* ncurses-devel libtool-ltdl-devel* mysql-devel

下载软件包


代码如下:

#创建目录
mkdir /web
cd /web

#PHP5.3.7
wget http://cn.php.net/distributions/php-5.3.8.tar.bz2
#PHP库文件
wget http://ncu.dl.sourceforge.net/project/mcrypt/MCrypt/2.6.8/mcrypt-2.6.8.tar.gz
wget http://ncu.dl.sourceforge.net/project/mhash/mhash/0.9.9.9/mhash-0.9.9.9.tar.gz
wget http://ncu.dl.sourceforge.net/project/mcrypt/Libmcrypt/2.5.8/libmcrypt-2.5.8.tar.gz
wget http://ftp.gnu.org/pub/gnu/libiconv/libiconv-1.14.tar.gz

#Nginx1.0.9
wget http://www.nginx.org/download/nginx-1.0.9.tar.gz

#Nginx(pcre)
wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.13.tar.gz

#Mysql5.5.17
wget http://dev.mysql.com/get/Downloads/MySQL-5.5/mysql-5.5.17.tar.gz/from/http://mysql.ntu.edu.tw/

#Mysql(cmake)
wget http://www.cmake.org/files/v2.8/cmake-2.8.6.tar.gz

安装Mysql


代码如下:

#安装cmake
tar -zxvf cmake-2.8.6.tar.gz
cd cmake-2.8.6/
./configure
gmake && gmake install && cd ../

#添加mysql用户
/usr/sbin/groupadd mysql
/usr/sbin/useradd -g mysql mysql
mkdir -p /data/mysql
chown -R mysql:mysql /data/mysql

#安装Mysql
tar -zxvf mysql-5.5.17.tar.gz
cd mysql-5.5.17
cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_DATADIR=/data/mysql -DSYSCONFDIR=/etc/
make && make install

#设置Mysql
#在support-files目录中有五个配置信息文件:
#my-small.cnf (内存<=64M)
#my-medium.cnf (内存 128M)
#my-large.cnf (内存 512M)
#my-huge.cnf (内存 1G-2G)
#my-innodb-heavy-4G.cnf (内存 4GB)
cd /usr/local/mysql
cp ./support-files/my-medium.cnf /etc/my.cnf
vi /etc/my.cnf
#在 [mysqld] 段增加
datadir = /data/mysql
wait-timeout = 30
max_connections = 512
default-storage-engine = MyISAM
#在 [mysqld] 段修改
max_allowed_packet = 16M

#生成授权表
cd /usr/local/mysql
./scripts/mysql_install_db --user=mysql

#更改密码
/usr/local/mysql/bin/mysqladmin -u root password 123456

#开启mysql
/usr/local/mysql/bin/mysqld_safe &

#测试连接mysql
/usr/local/mysql/bin/mysql -u root -p 123456
show databases;
exit;

#设置开机启动
vi /etc/rc.d/rc.local

#加入
/usr/local/mysql/bin/mysqld_safe &

安装PHP


代码如下:

#1
tar -zxvf libiconv-1.14.tar.gz && cd libiconv-1.14/
./configure --prefix=/usr/local
make && make install && cd ../

#2
tar -zxvf libmcrypt-2.5.8.tar.gz && cd libmcrypt-2.5.8/
./configure && make && make install
/sbin/ldconfig && cd libltdl/ && ./configure --enable-ltdl-install
make && make install && cd ../

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

#4
ln -s /usr/local/lib/libmcrypt.la /usr/lib/libmcrypt.la
ln -s /usr/local/lib/libmcrypt.so /usr/lib/libmcrypt.so
ln -s /usr/local/lib/libmcrypt.so.4 /usr/lib/libmcrypt.so.4
ln -s /usr/local/lib/libmcrypt.so.4.4.8 /usr/lib/libmcrypt.so.4.4.8
ln -s /usr/local/lib/libmhash.a /usr/lib/libmhash.a
ln -s /usr/local/lib/libmhash.la /usr/lib/libmhash.la
ln -s /usr/local/lib/libmhash.so /usr/lib/libmhash.so
ln -s /usr/local/lib/libmhash.so.2 /usr/lib/libmhash.so.2
ln -s /usr/local/lib/libmhash.so.2.0.1 /usr/lib/libmhash.so.2.0.1
ln -s /usr/local/bin/libmcrypt-config /usr/bin/libmcrypt-config

#5
tar -zxvf mcrypt-2.6.8.tar.gz &&cd mcrypt-2.6.8/
/sbin/ldconfig
./configure
make && make install && cd ../

#6
tar -xjvf php-5.3.8.tar.bz2
cd php-5.3.8

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

make ZEND_EXTRA_LIBS='-liconv'

#注意这里容易出现 make: *** [ext/phar/phar.php] 错误 127

#出现mysql client解决方法
#ln -s /usr/local/mysql/lib/libmysqlclient.so /usr/lib/
#ln -s /usr/local/mysql/lib/libmysqlclient.so.18 /usr/lib/libmysqlclient.so.18

#或者chmod: 无法访问 “ext/phar/phar.phar”: 没有那个文件或目录
#make: [ext/phar/phar.phar] 错误 1 (忽略)
#解决方法在编译的时候加--without-pear参数
#如果还不行,make的时候不添加 ZEND_EXTRA_LIBS='-liconv' 参数

make install

#选择PHP.ini配置文件
cp php.ini-production /usr/local/php/etc/php.ini

更改PHP-FPM


代码如下:

#添加WWW用户
/usr/sbin/groupadd www && /usr/sbin/useradd -g www www
mkdir -p /var/log/nginx && chmod +w /var/log/nginx &&chown -R www:www /var/log/nginx
mkdir -p /data/www && chmod +w /data/www && chown -R www:www /data/www

cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf
vi /usr/local/php/etc/php-fpm.conf

#去掉/更改 配置文件中的;
pm.max_children = 64
pm.start_servers = 20
pm.min_spare_servers = 5
pm.max_spare_servers = 35
pm.max_requests = 1024
user = www
group = www

#检查语法是否正确
/usr/local/php/sbin/php-fpm -t
#出现NOTICE: configuration file /usr/local/php/etc/php-fpm.conf test is successful 测试成功
/usr/local/php/sbin/php-fpm &
#设置开机启动
vi /etc/rc.d/rc.local
#在行末加入
/usr/local/php/sbin/php-fpm &

#返回安装包目录
cd /web

安装Nginx


代码如下:

#安装pcre库
tar -zxvf pcre-8.13.tar.gz && cd pcre-8.13/ && ./configure
make && make install && cd ../

#安装Nginx
tar -zxvf nginx-1.0.9.tar.gz && cd nginx-1.0.9 &&
./configure --user=www --group=www \
--prefix=/usr/local/nginx \
--sbin-path=/usr/local/nginx/sbin/nginx \
--conf-path=/usr/local/nginx/conf/nginx.conf \
--with-http_stub_status_module \
--with-http_ssl_module \
--with-pcre \
--lock-path=/var/run/nginx.lock \
--pid-path=/var/run/nginx.pid

make && make install && cd ../

#更改配置
vi /usr/local/nginx/conf/nginx.conf

#修改一些参数,别直接替换文件,这只是一部分
user www

events {
use epoll;
worker_connections 1024;
}

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;
}

#注意这里
#$document_root$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
/usr/local/nginx/sbin/nginx#平滑重启Nginx
/usr/local/nginx/sbin/nginx -s reload

#添加开机启动
vi /etc/rc.d/rc.local
#最后移行加入
/usr/local/nginx/sbin/nginx

#测试
cd /usr/local/nginx/html/
touch index.php
vi /usr/local/nginx/html/index.php
<?php
phpinfo();
?>


作者:吴佰清

(0)

相关推荐

  • Linux+php+apache+oracle环境搭建之CentOS下安装Oracle数据库

    这里推荐使用OTK脚本安装Oracle,会大大提高安装Oracle的成功系数. Description oraToolKit is the Swiss Army Knife for Oracle. Standards and well designed tools help DBA's mastering Oracle 10g / 11g throughout the whole lifecycle. OTK runs on Linux, zLinux, Solaris, AIX, HP-UX

  • CentOS 5.4 服务器配置 yum安装Apache+php+Mysql

    中国官方镜像网站: http://centos.ustc.edu.cn/ /* 使用说明 */ cd /etc/yum.repos.d[进入yum.repos.d目录] mv CentOS-Base.repo CentOS-Base.repo.save[修改源文件名称备份] wget http://centos.ustc.edu.cn/CentOS-Base.repo.5[下载] mv CentOS-Base.repo.5 CentOS-Base.repo[下载后的文件更名] 1. 更新系统内核

  • CentOS 6.4安装配置LNMP服务器(Nginx+PHP+MySQL)

    准备篇 1.配置防火墙,开启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 --state NEW -m tcp -p tcp --dport 3306 -j ACCEPT #允许3306端口通过防火墙 备注:很多网友把这两条规则添加到防火墙配置的最后一行,导致防火墙启动失败, 正确

  • CentOS下搭建PHP环境与WordPress博客程序的全流程总结

    环境 服务器操作系统:CentOS 7.0 博客部署服务器:Apache 后台语言:PHP 数据库:MySql 前端框架:WordPress 步骤 一.安装Apache 安装 Apache 很简单,只需要在终端输入以下命令就可以了: sudo yum install httpd sudo 的意思是用 root 用户做什么操作,yum install 是在线安装:然后输入 yes 就确认下载安装了. 安装完毕之后我们需要启动服务: sudo service httpd start 当启动服务器完成

  • CentOS+Nginx+PHP+MySQL详细配置(图解)

    一.安装MySQL 目前web服务器已经很少有跑静态页面的,如果要跑动态网站那当然就离不开数据库,虽然在以前文章中有写MySQL是怎么安装的,但是感觉好久没装MySQL,现在只把步骤贴出来,就不做过多的讲解了 #useradd mysql #tar zxvf mysql-5.0.40.tar.gz #cd mysql-5.0.40 #./configure --prefix=/usr/local/mysql #make && make install #/usr/local/mysql/b

  • CentOS 6.4安装配置LAMP服务器(Apache+PHP5+MySQL)

    准备篇: 1.配置防火墙,开启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 --state NEW -m tcp -p tcp --dport 3306 -j ACCEPT #允许3306端口通过防火墙 备注:很多网友把这两条规则添加到防火墙配置的最后一行,导致防火墙启动失败, 正

  • CentOS上搭建PHP服务器环境的步骤与方法

    本文实例讲述了CentOS上搭建PHP服务器环境的步骤与方法.分享给大家供大家参考,具体如下: 安装apache: yum install httpd httpd-devel 启动apache: /etc/init.d/httpd start 此时输入服务器的IP地址,应该看到apache的服务页面,端口不用输,apache默认就是使用80端口 安装mysql: yum install mysql mysql-server 启动mysql: /etc/init.d/mysqld start 安装

  • Centos6.5和Centos7 php环境搭建方法

    总有人认为linux搭建php环境很复杂,然后尝试安装lnmp一键安装包.其实说白了就是安装一个web服务器,然后支持php即可,很简单的,比起你安装lnmp一键安装包还要简单.不说大话,看实际安装步骤. 首先我们先查看下centos的版本信息 复制代码 代码如下: #适用于所有的linux lsb_release -a #或者 cat /etc/redhat-release #又或者 rpm -q centos-release 以上三种任意一种均可查看centos的版本信息. 这里我们分别在c

  • Linux+php+apache+oracle环境搭建之CentOS下安装Apache

    CentOS系统安装的是Basic Server.安装apache之前所必须的缺少的组件比较多,下面罗列下本次需要安装的组件 apache - aprapache - apr-utilperl - pcreapache 官网下载Apache,下载地址:http://httpd.apache.org/download.cgi 下载稳定版本httpd-2.4.9.tar.gz,上传到服务器/usr/packages目录下. 安装Apache: # tar -xvzf httpd-2.4.9.tar.

  • Linux+php+apache+oracle环境搭建之CentOS下源码编译安装PHP

    首先需要安装下面几个安装包,可以在CD-ROM数据源里找到以下安装包yum安装 yum install perl* freetype libpng* libxm2 libxm2-devel curl curl-devel libjpeg* 手动下载安装 jpegsrc.v8c.tar libmcrypt-2.5.8.tar.gz 安装 jpegsrc # tar -xvzf jpegsrc.v8c.tar # cd jpeg-8c # ./configure --prefix=/usr/loca

随机推荐