線上lnmp環境快速安裝

環境:centos6.4 + php5.2.17(編譯安裝) + mysql5.5.30(rpm包安裝) + nginx1.4.1(yum安裝)php

做用:提供用戶註冊html

注:因爲鏈接後臺數據庫,mysql只需安裝相關組件便可,本文重點在php配置mysql


系統初始化nginx

groupadd -g 80 wwwc++

adduser -o --home /www --uid 80 --gid 80 -c "Web Application" wwwsql

cd /usr/local/src/
數據庫

rpm --import http://apt.sw.be/RPM-GPG-KEY.dag.txt
vim

rpm -K http://packages.sw.be/rpmforge-release/rpmforge-release-0.5.2-2.el6.rf.x86_64.rpmcentos

rpm -i http://packages.sw.be/rpmforge-release/rpmforge-release-0.5.2-2.el6.rf.x86_64.rpmapi

yum install -y gcc gcc-c++ make automake autoconf patch curl-devel libmcrypt-devel mhash-devel gd-devel libjpeg-devel libpng-devel libXpm-devel libxml2-devel libxslt-devel openssl-devel recode-devel


軟件包下載: http://down.51cto.com/data/824535

tar zxvf soft_myid.tar.gz

yum localinstall MySQL-*

tar zxvf curl-7.30.0.tar.gz

cd curl-7.30.0

./configure --prefix=/srv/curl-7.30.0/ --without-nss --with-ssl && make && make install

cd ..

tar zxvf libiconv-1.14.tar.gz

cd libiconv-1.14

./configure --prefix=/srv/libiconv-1.14

make && make install

cd ..


php安裝

tar zxvf php-5.2.17.tar.gz

gzip -cd php-5.2.17-fpm-0.5.14.diff.gz | patch -d php-5.2.17 -p1

cd php-5.2.17

./configure --prefix=/srv/php-5.2.17 \

--with-config-file-path=/srv/php-5.2.17/etc \

--with-config-file-scan-dir=/srv/php-5.2.17/etc/conf.d \

--enable-fastcgi \

--enable-fpm \

--with-libdir=lib64 \

--with-pear \

--with-curl=/srv/curl-7.28.1 \

--with-iconv-dir=/srv/libiconv-1.14 \

--with-gd \

--with-jpeg-dir \

--with-png-dir \

--with-freetype-dir \

--with-zlib-dir \

--with-mcrypt \

--with-mhash \

--with-mysql \

--with-mysqli=/usr/bin/mysql_config \

--with-pdo-mysql \

--with-mysql-sock=/var/lib/mysql/mysql.sock \

--with-openssl \

--with-xsl \

--enable-sockets \

--enable-soap \

--enable-mbstring \

--enable-gd-native-ttf \

--enable-zip \

--enable-xml \

--enable-bcmath \

--enable-calendar \

--enable-shmop \

--enable-dba \

--enable-wddx \

--enable-sysvsem \

--enable-sysvshm \

--enable-sysvmsg \

--enable-pcntl \

--with-tsrm-pthreads \

--disable-debug

make && make install


當前路徑/usr/local/src/

mkdir -p /srv/php-5.2.17/etc/conf.d/

cp php.ini-recommended /srv/php-5.2.17/etc/php.ini

cp /srv/php-5.2.17/etc/php-fpm.conf{,.original}

cp /srv/php-5.2.17/etc/pear.conf{,.original}


配置php-fpm啓動

cp /usr/local/src/php-5.2.17/sapi/cgi/fpm/php-fpm /etc/init.d/php-fpm

chmod +x /etc/init.d/php-fpm


在頭部第二行添加下面兩行,以支持開機啓動

vim /etc/init.d/php-fpm  

# chkconfig: - 85 15

# description: nginx is a World Wide Web server. It is used to serve


添加開機啓動

chkconfig --add php-fpm

chkconfig php-fpm on

chkconfig --list php-fpm


更改php-fpm.conf用戶與組

vim /srv/php-5.2.17/etc/php-fpm.conf

用戶: nobody 改成 www

組: nobody 改成 www


php.ini設置與優化

vim /srv/php-5.2.17/etc/php.ini <<EOF > /dev/null 2>&1

:254,254s$;open_basedir =$open_basedir = /www/:/tmp/:/var/tmp/:/srv/php-5.2.17/lib/php/:/srv/php-5.2.17/bin/$

:297,297s/expose_php = On/expose_php = Off/

:307,307s/memory_limit = 128M/memory_limit = 16M/

:525,525s!;include_path = ".:/php/includes"!include_path = ".:/srv/php-5.2.17/lib/php:/srv/php-5.2.17/share"!

:542,542s:extension_dir = "./":extension_dir = "/srv/php-5.2.17/lib/php/extensions/no-debug-non-zts-20060613":

:571,571s/; cgi.fix_pathinfo=1/cgi.fix_pathinfo=1/

:716,716s$;date.timezone =$date.timezone = Asia/Hong_Kong$

:1046,1046s:;session.save_path = "/tmp":session.save_path = "/dev/shm":

:1058,1058s/session.name = PHPSESSID/session.name = JSESSIONID/

:wq

EOF


安裝apc擴展 (alternative php cache 用於緩存和優化php中間代碼)

/srv/php-5.2.17/bin/pecl install apc

cat > /srv/php-5.2.17/etc/conf.d/apc.ini <<EOF

extension=apc.so

EOF


檢測apc模塊

php -m |grep apc


nginx安裝

根據本身的實際環境配置(站點路徑,優化,證書等),這裏只做演示,也沒有改網站權限

yum -y install nginx

chkconfig nginx on


建立測試頁面

cat >> /usr/share/nginx/html/index.php <<PHP

<?php

phpinfo();

PHP


啓動服務器

/etc/init.d/php-fpm start

/etc/init.d/nginx start


訪問phpinfo

http://IP/index.php

相關文章
相關標籤/搜索