1. yum安装基础包
[shell]
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 lrzsz dos2unix
[/shell]
2. 下载软件包 (截止2015.1.22)
[shell]
wget -P /usr/local/src/ http://nginx.org/download/nginx-1.6.2.tar.gz
wget -P /usr/local/src/ http://cn2.php.net/distributions/php-5.4.36.tar.gz
wget -P /usr/local/src/ http://ftp.gnu.org/pub/gnu/libiconv/libiconv-1.14.tar.gz
wget -P /usr/local/src/ http://downloads.sourceforge.net/mcrypt/libmcrypt-2.5.8.tar.gz
wget -P /usr/local/src/ http://downloads.sourceforge.net/mcrypt/mcrypt-2.6.8.tar.gz
wget -P /usr/local/src/ http://pecl.php.net/get/memcache-2.2.7.tgz
wget -P /usr/local/src/ http://downloads.sourceforge.net/mhash/mhash-0.9.9.9.tar.gz
wget -P /usr/local/src/ ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.36.tar.gz
wget -P /usr/local/src/ http://pecl.php.net/get/PDO_MYSQL-1.0.2.tgz
wget -P /usr/local/src/ http://pecl.php.net/get/redis-2.2.5.tgz
wget -P /usr/local/src/ https://github.com/eaccelerator/eaccelerator/archive/master.zip
[/shell]
3. 安装PHP的支持包
新建phplib-x86_64.conf文件,并放入/etc/ld.so.conf.d/目录中,文件内容为:
/usr/local/lib/
[shell]
cd /usr/local/src/
tar zxvf libiconv-1.14.tar.gz
cd libiconv-1.14/
./configure --prefix=/usr/local
make
make install
cd ..
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 ../..
tar zxvf mhash-0.9.9.9.tar.gz
cd mhash-0.9.9.9/
./configure
make
make install
cd ..
tar zxvf mcrypt-2.6.8.tar.gz
cd mcrypt-2.6.8/
/sbin/ldconfig
./configure
make
make install
cd ..
[/shell]
4. 安装MySQL
[shell]
yum install -y mysql-server mysql-devel mysql
[/shell]
5. 安装PHP
[shell]
cp -ra /usr/lib64/libldap* /usr/lib/
mkdir /usr/lib/mysql/
cp -ra /usr/lib64/mysql/* /usr/lib/mysql/
cp -ra /usr/include/mysql/* /usr/local/include/
tar zxvf php-5.4.36.tar.gz
cd php-5.4.36
./configure --prefix=/usr/local/php5 --with-config-file-path=/usr/local/php5/etc --with-mysql=/usr/ --with-mysqli=/usr/bin/mysql_config --with-iconv-dir=/usr/local --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir=/usr --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-gd --enable-gd-native-ttf --with-openssl --with-mhash --enable-pcntl --enable-sockets --with-ldap --with-ldap-sasl --with-xmlrpc --with-gettext --enable-zip --enable-soap --disable-fileinfo
make ZEND_EXTRA_LIBS='-liconv'
make install
[/shell]
6. 安装扩展包
[shell]
cd /usr/local/src/
tar zxvf PDO_MYSQL-1.0.2.tgz
cd PDO_MYSQL-1.0.2
/usr/local/php5/bin/phpize
./configure --with-php-config=/usr/local/php5/bin/php-config --with-pdo-mysql=/usr/
make
make install
cd ..
tar zxvf redis-2.2.5.tgz
cd redis-2.2.5
/usr/local/php5/bin/phpize
./configure --with-php-config=/usr/local/php5/bin/php-config
make
make install
cd ..
unzip master.zip
cd eaccelerator-master/
/usr/local/php5/bin/phpize
./configure --enable-eaccelerator=shared --with-php-config=/usr/local/php5/bin/php-config
make
make install
[/shell]
最后编辑php.ini文件,在此文件最低端追加以下内容:(并放在user/local/php5/etc/下)PS:安装phpmyadmin后访问出现错误:Cannot start session without errors, please check errors given in your PHP 解决方法:/usr/local/php5/etc/php.ini文件 session.save_path = "/tmp/session" 确保tmp下有这个文件夹
[shell]
[Redis]
extension=redis.so
[PDO_MySql]
extension=pdo_mysql.so
[eaccelerator]
zend_extension="/usr/local/php5/lib/php/extensions/no-debug-non-zts-20100525/eaccelerator.so"
eaccelerator.shm_size="64"
eaccelerator.cache_dir="/data/cache/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"
[/shell]
7. 安装nginx
[shell]
cd /usr/local/src/
tar zxvf pcre-8.36.tar.gz
cd pcre-8.36
./configure
make
make install
[/shell]
[shell]
cd ..
tar zxvf nginx-1.6.2.tar.gz
cd nginx-1.6.2
./configure --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module --with-http_mp4_module --with-http_flv_module
make
make install
[/shell]
8. 将php-fpm配置成系统服务
[shell]
cd /usr/local/src/php-5.4.36/sapi/fpm
cp -a init.d.php-fpm.in /etc/init.d/php-fpm
[/shell]
编辑/etc/init.d/php-fpm文件,主要是编辑目录路径,如下:
[shell]
prefix=/usr/local/php5/
exec_prefix=/usr/local/php5/sbin/
php_fpm_BIN=/usr/local/php5/sbin/php-fpm
php_fpm_CONF=/usr/local/php5/etc/php-fpm.conf
php_fpm_PID=/usr/local/php5/var/run/php-fpm.pid
[/shell]
保存退出
[shell]
cd /etc/init.d/
chown root:root php-fpm
chmod 755 php-fpm
chkconfig --add php-fpm
[/shell]
9. 系统相关配置
[shell]
ldconfig
useradd www
mkdir -p /data/cache/eaccelerator_cache
mkdir /data/wwwroot
chown -R ftpuser:www /data/wwwroot
cd /data/wwroot
find -type d -exec chmod 754 {} \;
find -not -type d -exec chmod 644 {} \;
find data -type d -exec chmod 774 {} \;
[/shell]
10. 服务配置
设置mysql密码:
[shell]
service mysqld start
mysql -uroot -p
mysql> update mysql.user set password=PASSWORD('123456') where User='root';
mysql> flush privileges;
mysql> quit
[/shell]
启动:
[shell]
service mysqld start
service php-fpm start
/usr/local/nginx/sbin/nginx
[/shell]
停止:
[shell]
/usr/local/nginx/sbin/nginx -s stop
service php-fpm stop
service mysqld stop
[/shell]
重启:
[shell]
service mysqld restart
service php-fpm restart
/usr/local/nginx/sbin/nginx -s reload
[/shell]
加入自启动:
chkconfig php-fpm on
chkconfig mysqld on
echo "/usr/local/nginx/sbin/nginx" >> /etc/rc.local
上传php-fpm.conf 至/usr/local/php5/etc/
mkdir -p /data/logs/php