搭建基于Linux6.3+Nginx1.2+PHP5+MySQL5.5的Web服务器全过程----转载
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了搭建基于Linux6.3+Nginx1.2+PHP5+MySQL5.5的Web服务器全过程----转载相关的知识,希望对你有一定的参考价值。
之前的Web服务器都是通过yum搭建的,想要添加新模块或者更新某些软件都很不方便(牵一发而动全身啊!)。所以,现在准备将环境改为源码编译安装,这样便于调整,性能上也会比yum方式好很多。以下是我的安装步骤,我的系统是CentOS 6.3 64位。
注意:本文所以配置都是基于第二步所下载的软件版本,安装其他版本不保证会成功
推荐阅读:
生产环境实用之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
一:安装依赖包
yum install cmake make gcc gcc-c++ 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-devel libidn libidn-devel openssl expat expat-devel \
openssl-devel nss_ldap openldap openldap-devel openldap-clients openldap-servers unixODBC-devel \
libxslt-devel libevent-devel libtool-ltdl bison libtool pcre-devel zip unzip gmp-devel gd gd-devel
二:下载LNMP所需软件
wget http://downloads.mysql.com/archives/mysql-5.5/mysql-5.5.19.tar.gz
wget http://ftp.gnu.org/pub/gnu/libiconv/libiconv-1.14.tar.gz
wget http://iweb.dl.sourceforge.net/project/mcrypt/Libmcrypt/2.5.8/libmcrypt-2.5.8.tar.gz
wget http://iweb.dl.sourceforge.net/project/mhash/mhash/0.9.9.9/mhash-0.9.9.9.tar.gz
wget http://vps.googlecode.com/files/mcrypt-2.6.8.tar.gz
wget http://download-euro.oldapps.com/PHP/php-5.3.18.tar.bz2
wget
http://superb-dca2.dl.sourceforge.net/project/eaccelerator/eaccelerator/eAccelerator%200.9.6.1/eaccelerator-0.9.6.1.tar.bz2
wget http://pecl.php.net/get/PDO_MYSQL-1.0.2.tgz
wget http://pecl.php.net/get/memcache-2.2.7.tgz
wget http://www.imagemagick.org/download/legacy/ImageMagick-6.8.3-10.tar.gz
wget http://pecl.php.net/get/imagick-3.0.1.tgz
wget http://pecl.php.net/get/pecl_http-1.7.5.tgz
wget http://jaist.dl.sourceforge.net/project/pcre/pcre/8.33/pcre-8.33.tar.gz
wget http://nginx.org/download/nginx-1.2.9.tar.gz
wget http://sourceforge.net/projects/re2c/files/re2c/0.13.5/re2c-0.13.5.tar.gz/download
wget http://pecl.php.net/get/igbinary-1.1.1.tgz
wget https://github.com/nicolasff/phpredis/archive/master.zip
三、安装mysql
tar zxf mysql-5.5.19.tar.gz
cd mysql-5.5.19
groupadd mysql
useradd -g mysql -s /sbin/nologin -M mysql
cmake \
-DCMAKE_INSTALL_PREFIX=/usr/local/mysql \
-DSYSCONFDIR=/etc/mysql \
-DMYSQL_UNIX_ADDR=/usr/local/mysql/tmp/mysql.sock \
-DWITH_READLINE=1 \
-DWITH_EMBEDDED_SERVER=1 \
-DMYSQL_DATADIR=/usr/local/mysql/data \
-DMYSQL_USER=mysql \
-DMYSQL_TCP_PORT=3306
make && make install
chown -R mysql.mysql /usr/local/mysql
cd ..
因为有专门的mysql服务器,所以mysql安装到此结束。如果想要在本地运行mysql的话还要做其他配置。比如my.cnf配置文件,mysql启动脚本等等。
四:安装PHP
安装PHP(FastCGI)
### 安装PHP支持库 ###
tar zxf libiconv-1.14.tar.gz
cd libiconv-1.14
./configure --prefix=/usr/local
make
make install
cd ..
tar zxf 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 ../../
tar zxf mhash-0.9.9.9.tar.gz
cd mhash-0.9.9.9/
./configure
make
make install
cd ../
tar zxf mcrypt-2.6.8.tar.gz
cd mcrypt-2.6.8/
./configure
make
make install
cd ../
tar zxf re2c-0.13.5.tar.gz
cd re2c-0.13.5
./configure
make && make install
cd ..
在安装PHP主程序前,还需要做一些调整,不然会各种报错。
echo "/usr/local/lib" > /etc/ld.so.conf.d/local.conf
echo "/usr/lib64" >> /etc/ld.so.conf.d/local.conf
ln -sv /usr/lib64/libldap* /usr/lib/
ln -sv /usr/include/sqlext.h /usr/local/include/sqlext.h
ln -sv /usr/local/mysql/bin/mysql_config /usr/bin/mysql_config
ln -sv /usr/local/mysql/lib/libmysqlclient.so.18 /usr/lib64/
ln -sv /lib64/libexpat.* /lib/
ln -sv /usr/lib64/libexpat.* /usr/lib/
ldconfig
现在安装PHP
tar jxf php-5.3.18.tar.bz2
cd php-5.3.18
groupadd nginx
useradd -M -s /sbin/nologin -g nginx nginx
./configure \
--prefix=/usr/local/php --with-config-file-path=/etc --with-config-file-scan-dir=/etc/php.d \
--with-pic --with-bz2 --with-gettext --with-gmp --with-iconv --with-openssl \
--with-zlib --with-layout=GNU --with-kerberos --with-mhash --with-pcre-regex --enable-exif \
--enable-magic-quotes --enable-sockets --enable-ucd-snmp-hack --enable-shmop --enable-calendar \
--enable-mbstring \
--enable-xml --enable-fpm --enable-gd-native-ttf --enable-exif --enable-soap --with-gd --with-curl \
--with-mcrypt \
--with-mysql=/usr/local/mysql --with-mysqli=/usr/local/mysql/bin/mysql_config --with-pdo-mysql \
--with-unixODBC \
--enable-wddx --with-libexpat-dir --with-xmlrpc --with-xsl --with-ldap --enable-bcmath \
--enable-dom --without-gdbm --disable-debug --disable-rpath --disable-fileinfo --without-pspell \
--disable-posix --disable-sysvmsg --disable-sysvshm --disable-sysvsem
make ZEND_EXTRA_LIBS=‘-liconv‘
make install
拷贝配置文件及启动脚本
cp php.ini-production /etc/php.ini
cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
chmod +x /etc/init.d/php-fpm
chkconfig --add php-fpm
chkconfig php-fpm on
cd ../
安装PHP扩展模块,别忘记在配置文件里开启模块,不然就白装了哈
### 安装扩展模块 ###
tar zxf memcache-2.2.7.tgz
cd memcache-2.2.7/
/usr/local/php/bin/phpize
./configure --enable-memcache --with-php-config=/usr/local/php/bin/php-config
make
make install
cd ../
tar jxf eaccelerator-0.9.6.1.tar.bz2
cd eaccelerator-0.9.6.1/
/usr/local/php/bin/phpize
./configure --enable-eaccelerator=shared --with-php-config=/usr/local/php/bin/php-config
make
make install
mkdir /tmp/cache/eaccelerator
chmod 0777 /tmp/cache/eaccelerator
cd ../
tar zxf PDO_MYSQL-1.0.2.tgz
cd PDO_MYSQL-1.0.2/
/usr/local/php/bin/phpize
./configure --with-php-config=/usr/local/php/bin/php-config --with-pdo-mysql=/usr/local/mysql
make
make install
cd ../
tar zxf igbinary-1.1.1.tgz
cd igbinary-1.1.1
/usr/local/php/bin/phpize
./configure --enable-igbinary --with-php-config=/usr/local/php/bin/php-config
make && make install
cd ..
unzip master
cd phpredis-master
/usr/local/php/bin/phpize
./configure --enable-redis --enable-redis-igbinary --with-php-config=/usr/local/php/bin/php-config
make && make install
cd ..
tar zxvf ImageMagick-6.8.3-10.tar.gz
cd ImageMagick-6.8.3-10/
./configure
make
make install
cd ../
tar zxvf imagick-3.0.1.tgz
cd imagick-3.0.1/
/usr/local/php/bin/phpize
./configure --with-php-config=/usr/local/php/bin/php-config
ln -s /usr/local/include/ImageMagick-6 /usr/local/include/ImageMagick
export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig
make
make install
cd ../
到此PHP环境配置完毕,接下来安装大名鼎鼎的Nginx。它的好咱就不说了,大家都知道哈。
以上是关于搭建基于Linux6.3+Nginx1.2+PHP5+MySQL5.5的Web服务器全过程----转载的主要内容,如果未能解决你的问题,请参考以下文章
使用基于 PHP 的开源软件 YOURLS 搭建短链接地址服务
Debian 8 上的 nginx 1.6 别名 + php5-fpm = 404
windows 7搭建基于docker的nginx, php运行环境