centos6.5搭建lnmp环境
建议安装顺序:
mysql-------》》编译php----》》编译nginx
最麻烦:编译php出各种错。
最简单:mysql
软件版本:
libiconv-1.13.tar.gz
libmcrypt-2.5.8.tar.gz
mcrypt-2.6.8.tar.gz
mhash-0.9.9.9.tar.gz
memcache-2.2.5.tgz
PDO_MYSQL-1.0.2.tgz
imagick-3.1.2.tgz
pcre-8.21.tar.gz
mysql-5.5.30.tar.gz
ImageMagick.tar.gz
php-5.4.21.tar.gz
nginx-1.4.0.tar.gz
eaccelerator-eaccelerator-42067ac.tar.gz(为1.0-dev版)
系统安装需求:
centos6.5X86_64VMware安装,关闭selinux,iptables
磁盘20G
注意:系统全新安装,不是之前的系统卸载了重装
前提:由于要使用编译安装,所以查看httpd、mysql、php是否安装
[root@localhost~]#rpm-qhttpdmysqlphp
如果安装则卸载:
[root@localhost~]#rpm-ehttpd--nodeps
[root@localhost~]#rpm-emysql--nodeps
[root@localhost~]#rpm-ephp--nodeps
find / -name php mysql nginx
rm -rf ***
1安装解决依赖关系:
yuminstall-ywgetgccgcc-c++autoconflibjpeglibjpeg-develperlperl*perl-CPANlibpnglibpng-develfreetype
freetype-devellibxml2libxml2-develzlibzlib-develglibcglibc-develglib2glib2-develbzip2bzip2-devel
ncursesncurses-develcurlcurl-devele2fsprogse2fsprogs-develkrb5krb5-devellibidnlibidn-developenssl
openssl-developenldapopenldap-develnss_ldapopenldap-clientsopenldap-serverspngjpegautoconfgcccmake
makegcc-c++gccladpldap*ncursesncurses-develzlibzlib-develzlib-staticpcrepcre-develpcre-static
opensslopenssl-develperllibtooltopenldap-devellibxml2-develntpdatecmakegd*gd2ImageMagick-develjpeg
jpeg*pcre-dev*fontconfiglibpnglibxml2zipunzipgzip
2下载所有使用到的软件:(13个)
wget/gnu/libiconv/libiconv-1.13.tar.gz
wget/files/libmcrypt-2.5.8.tar.gz
wgethttp://jaist./project/mcrypt/MCrypt/2.6.8/mcrypt-2.6.8.tar.gz
wgethttp://jaist./project/mhash/mhash/0.9.9.9/mhash-0.9.9.9.tar.gz
wget/files/memcache-2.2.5.tgz
wget/files/PDO_MYSQL-1.0.2.tgz
wget/get/imagick-3.1.2.tgz
wgetftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.21.tar.gz
wgethttp://netcologne./project/mysql.mirror/MySQL%205.5.30/mysql-5.5.30.tar.gz
wget/files/ImageMagick.tar.gz
wget/get/php-5.4.21.tar.gz/from//mirror
wgethttps://lnamp-web-/files/eaccelerator-eaccelerator-42067ac.tar.gz
wget/download/nginx-1.4.0.tar.gz
3安装mysql-5.5.0
groupaddmysql
useraddmysql-gmysql
tar-zxvfmysql-5.5.30.tar.gz
cdmysql-5.5.30
cmake-DCMAKE_INSTALL_PREFIX=/usr/local/mysql\
-DMYSQL_UNIX_ADDR=/tmp/mysql.sock\
-DEXTRA_CHARSETS=all\
-DDEFAULT_CHARSET=utf8\
-DDEFAULT_COLLATION=utf8_general_ci\
-DWITH_EXTRA_CHARSETS:STRING=utf8,gbk\
-DWITH_INNOBASE_STORAGE_ENGINE=1\
-DWITH_READLINE=1\
-DENABLED_LOCAL_INFILE=1\
-DMYSQL_DATADIR=/data/mysql/\
-DMYSQL_USER=mysql\
-DMYSQL_TCP_PORT=3306
make&&makeinstall
mkdir-p/data/mysql
chownmysql.mysql-R/data/mysql
mv/etc/f/etc/f-old
cpsupport-files/my-f/etc/f
chmod755scripts/mysql_install_db
scripts/mysql_install_db--user=mysql--basedir=/usr/local/mysql--datadir=/data/mysql/
cpsupport-files/mysql.server/etc/init.d/mysqld
chmod755/etc/init.d/mysqld
chkconfigmysqldon
servicemysqldstart
设置mysql的root密码为123456
/usr/local/mysql/bin/mysqladmin-urootpassword'123456'
4安装php的扩展库:libiconv
tarzxvflibiconv-1.13.tar.gz
cdlibiconv-1.13/
./configure--prefix=/usr/local
make&&makeinstall
5安装php扩展库:libmcrypt
tarzxvflibmcrypt-2.5.8.tar.gz
cdlibmcrypt-2.5.8/
./configure
make&&makeinstall
/sbin/ldconfig
###注:这里不要退出去了。##
cdlibltdl/
./configure--enable-ltdl-install
make&&makeinstall
6安装php扩展库:mhash
tarzxvfmhash-0.9.9.9.tar.gz
cdmhash-0.9.9.9/
./configure
make&&makeinstall
7做库的软连接:
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/lib64/libldap*/usr/lib/
8安装php扩展包:mcrypt
tarzxvfmcrypt-2.6.8.tar.gz
cdmcrypt-2.6.8/
/sbin/ldconfig
./configure
make&&makeinstall
9安装php-5.4.21:
tar-zxvfphp-5.4.21.tar.gz
cdphp-5.4.21
./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-dir=/usr/local--with-freetype-dir--with-jpeg-dir
--with-png-dir--with-zlib--with-gd--enable-gd-native-ttf--with-libxml-dir=/usr--enable-xml--disable-rpath
--enable-discard-path--enable-safe-mode--enable-bcmath--enable-shmop--enable-sysvsem--enable-inline-
optimization--with-curl--with-curlwrappers--enable-mbregex--enable-fastcgi--enable-fpm--enable-force-cgi-
redirect--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
ln-s/usr/local/mysql/lib/libmysqlclient.so.18/usr/lib64/
makeZEND_EXTRA_LIBS='-liconv'
makeinstall
cp-fphp.ini-production/usr/local/php/etc/php.ini
ln-s/usr/local/php/etc/php.ini/usr/local/php/php.ini
cp/usr/local/php/etc/php-fpm.conf.default/usr/local/php/etc/php-fpm.conf
10安装php扩展库:memcache
tarzxvfmemcache-2.2.5.tgz
cdmemcache-2.2.5/
/usr/local/php/bin/phpize
./configure--with-php-config=/usr/local/php/bin/php-config
make&&makeinstall
11安装php加速:eaccelerator
tar-zxvfeaccelerator-eaccelerator-42067ac.tar.gz
cdeaccelerator-eaccelerator-42067ac
/usr/local/php/bin/phpize
./configure--enable-eaccelerator=shared--with-php-config=/usr/local/php/bin/php-config
make&&makeinstall
12修改php.ini增加memcache,ea等软件信息
添加memcache库的位置:
vim/usr/local/php/php.ini
extension_dir="/usr/local/php/lib/php/extensions/no-debug-non-zts-0525"
extension="memcache.so"
extension="pdo_mysql.so"
extension="imagick.so"
添加eaccelerator库的位置信息:
;eaccelerator#errnoticethere
[eaccelerator]
zend_extension="/usr/local/php/lib/php/extensions/no-debug-non-zts-0525/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"
press="1"
press_level="9"
eaccelerator.keys="disk_only"
eaccelerator.sessions="disk_only"
eaccelerator.content="disk_only"
mkdir-p/usr/local/eaccelerator_cache
chmod0777/usr/local/eaccelerator_cache
13:安装php扩展库:PDO_MYSQL
tarzxvfPDO_MYSQL-1.0.2.tgz
cdPDO_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
ln-s/usr/local/mysql/include/*/usr/local/include/
make&&makeinstall
14:安装php扩展库:ImageMagick
tarzxvfImageMagick.tar.gz
cdImageMagick-6.5.1-2/
./configure&&make&&makeinstall
15:安装php扩展库:imagick
tarzxvfimagick-3.1.2.tgz
cdimagick-3.1.2/
/usr/local/php/bin/phpize
ln-s/usr/local/include/ImageMagick-6/usr/local/include/ImageMagick
./configure--with-php-config=/usr/local/php/bin/php-config
make&&makeinstall
16:添加WWW用户,为系统运行nginx专用用户:
/usr/sbin/groupaddwww
/usr/sbin/useradd-gwwwwww
mkdir-p/var/log/nginx
chmod+w/var/log/nginx
chown-Rwww:www/var/log/nginx
mkdir-p/data0/www
chmod+w/data0/www
chown-Rwww:www/data0/www
17:修改php-fpm.conf的配置:
vim/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:configurationfile/usr/local/php/etc/php-fpm.conftestissuccessful
看到上面的信息证明php配置文件正常,可以启动了。
18:添加环境变量:
echo"exportPATH=\$PATH:/usr/local/php/sbin/">>/etc/profile
echo"exportPATH=\$PATH:/usr/local/php/bin/">>/etc/profile
./etc/profile
19:安装nginx的pcre
tar-zxvfpcre-8.21.tar.gz
cdpcre-8.21&&./configure&&make&&makeinstall
20:编译安装nginx
tar-zxvfnginx-1.4.0.tar.gz
cdnginx-1.4.0/
./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=/opt/pcre-8.21--lock-path=/var/run/nginx.lock--pid-path=/var/run/nginx.pid
make&&makeinstall
21:修改nginx配置文件
vim/usr/local/nginx/conf/nginx.conf
#修改一些参数,别直接替换文件,这只是一部分在events模块添加注释掉location
userwww;
events{
useepoll;
worker_connections1024;
}
#注意把/scripti改为$document_root$不然就是filenotfound
location~\.php${
roothtml;
fastcgi_pass127.0.0.1:9000;
fastcgi_indexindex.php;
fastcgi_paramSCRIPT_FILENAME$document_root$fastcgi_script_name;
includefastcgi_params;
}
22:写一个php的测试文件:phpinfo
cat>>/usr/local/nginx/html/index.php<<EOF
<?php
phpinfo();
?>
EOF
23:添加开机启动:
echo"/usr/local/php/sbin/php-fpm">>/etc/rc.local
echo"/usr/local/nginx/sbin/nginx">>/etc/rc.local
echo"/etc/init.d/mysqldrestart">>/etc/rc.local
24:启动nginx 启动php-fpm
24:浏览器访问:
http://ip/index.php
赠送:
可能会报错403404
403是你的权限问题。
404是你的nginx主配置文件问题。
请多指教!
参考:
http://renzhenxing./728846/1321572