lnmp环境的安装

所需软件列表
Linux: CentOS5.6
nginx: pcre-7.9.tar.gz  nginx-1.0.14.tar.gz
mysql: mysql-5.1.60.tar.gz
php: (libxml2,libxslt,curl,gd,freetype,libjpeg,libpng,zlib).rpm
libiconv-1.13.1.tar.gz  libmcrypt-2.5.8.tar.gz    mhash-0.9.9.9.tar.gz    mcrypt-2.6.8.tar.gz
php-5.3.10.tar.gz
memcache-2.2.6.tgz    eeaccelerator-0.9.6.1.tar.bz2    ImageMagick-6.7.6-1.tar.gz    imagick-2.3.0.tgz
APC-3.1.9.tgz
phpmyadmin: phpMyAdmin-3.4.10.1-all-languages.tar.gz



-----------安装nginx------------------


1.安装Nginx所需的pcre库:
tar zxvf pcre-7.9.tar.gz
cd pcre-7.9/
./configure
make && make install
2.安装Nginx(最好安装稳定版本,即stable版)
groupadd nginx
useradd -g nginx nginx
tar zxvf nginx-1.0.14.tar.gz
cd nginx-1.0.14/
./configure --user=nginx --group=nginx --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module
make && make install
chown -R nginx.nginx /usr/local/nginx
测试:/usr/local/nginx/sbin/nginx    ---启动nginx
如果出现“error while loading shared libraries: libpcre.so.1”的错误,做如下操作:
cd /lib
ln -s libpcre.so.0.0.1 libpcre.so.1
加入开机启动:echo "/usr/local/nginx/sbin/nginx" >> /etc/rc.local
输入 http://ip 会出现一页面,上面显示“Welcom to nginx”此时说明nginx安装成功。




-----------安装mysql(源码版)-------------


tar -zxvf mysql-5.1.60.tar.gz
cd mysql-5.1.60
./configure --prefix=/usr/local/mysql --with-mysqld-user=mysql --with-extra-charsets=gbk,gb2312,utf8
make && make install
groupadd mysql
useradd -g mysql mysql
/usr/local/mysql/bin/mysql_install_db --user=mysql
chown -R mysql.mysql /usr/local/mysql
cd /usr/local/mysql
cp share/mysql/my-medium.cnf /etc/my.cnf
cp share/mysql/mysql.server /etc/init.d/mysqld
chmod 755 /etc/init.d/mysqld
chkconfig --add mysqld
chkconfig --level 345 mysqld on
./bin/mysqladmin -u root password 'YOUPASSWORD'--更改数据库帐号root密码
service mysqld start
注:在安装好数据库,需操作时,先用root帐号登录,删除掉匿名用户,如果用工具连接mysql时,需新增帐号root@'%'方可登录
mysql>usr mysql;
mysql>delete from user where user='';
mysql>grant all on *.* to root@'%' identified by "YOUPASSWORD"--设置远端登录时的root密码
mysql>flush privileges;


-------------安装php--------------------


1.安装php需先安装数个模块(libxml2,libxslt,curl),GD库(gd,freetype,libjpeg,libpng,zlib),这些软件可以直接通过系统光盘来安装rpm包即可
2.编译安装php所需的支持库
tar zxvf libiconv-1.13.1.tar.gz
cd libiconv-1.13.1/
./configure --prefix=/usr/local
make && make install


tar zxvf libmcrypt-2.5.8.tar.gz 
cd libmcrypt-2.5.8/
./configure
make && make install
echo "/usr/local/lib" >> /etc/ld.so.conf
ldconfig


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


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


3.安装php5.3
tar -zxvf php-5.3.10.tar.gz
cd php-5.3.10
./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-libxml-dir=/usr --enable-xml --disable-rpath --enable-safe-mode --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --with-curl --with-curlwrappers  --enable-mbregex --enable-fpm --with-fpm-user=nginx --with-fpm-group=nginx --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 --enable-zip --enable-soap
注:--with-mysqli和--with-mcrypt为phpmyadmin必须的
make ZEND_EXTRA_LIBS='-liconv'(如果没有安装libiconv,可以直接运行make)
make install
cp php.ini-production /usr/local/php/etc/php.ini
cd /usr/local/php/etc
cp php-fpm.conf.default php-fpm.conf
启动php: /usr/local/php/sbin/php-fpm
加入开机启动:echo "/usr/local/php/sbin/php-fpm" >> /etc/rc.local


4.整合php和nginx
更改nginx配置文件
(1)加入访问php页面。
location / {
            root   html;
            index  index.html index.htm index.php;
        }
(2)去掉下面行前的注释符号“#”
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;
        }
注:/scripts$fastcgi_script_name如不改为$document_root$fastcgi_script_name,会出现找不到页面的情况。




---------------安装php扩展-------------------
注:3和4可以不安装


1.memcache
Memcache是一个高性能的分布式的内存对象缓存系统,通过在内存里维护一个统一的巨大的hash表,它能够用来存储各种格式的数据,包括图像、视频、文件以及数据库检索的结果等。简单的说就是将数据调用到内存中,然后从内存中读取,从而大大提高读取速度。
tar -zxvf memcache-2.2.6.tgz
cd memcache-2.2.6
/usr/local/php/bin/phpize
./configure --with-php-config=/usr/local/php/bin/php-config
make && make install


2.eaccelerator
eAccelerator是一个自由开放源码php加速器,优化和动态内容缓存,提高了php脚本的缓存性能,使得PHP脚本在编译的状态下,对服务器的开销几乎完全消除。
tar jxvf 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


3.ImageMagick
ImageMagick是一套功能强大、稳定而且免费的工具集和开发包,可以用来读、写和处理超过89种基本格式的图片文件,包括流行的TIFF、JPEG、GIF、 PNG、PDF以及PhotoCD等格式。
tar -zxf ImageMagick-6.7.6-1.tar.gz
cd ImageMagick-6.7.6-1
./configure
make && make install


4.imagick(供PHP调用ImageMagick功能的PHP扩展)
tar -zxf imagick-2.3.0.tgz
cd imagick-2.3.0
/usr/local/php/bin/phpize
./configure --with-php-config=/usr/local/php/bin/php-config
make && make install


5.APC(不能与eaccelerator共用)
tar -zxvf APC-3.1.9.tgz
cd APC-3.1.9
/usr/local/php/bin/phpize
./configure --with-php-config=/usr/local/php/bin/php-config --enable-apc --enable-mmap --enable-apc-spinlocks
make && make install


6.配置php.ini
查找/usr/local/webserver/php/etc/php.ini中的extension_dir = "./"
修改为extension_dir = "/usr/local/php/lib/php/extensions/no-debug-non-zts-20090626/"
并在此行后增加以下几行,然后保存:
extension = "memcache.so"
extension = "eaccelerator.so"
extension = "imagick.so"
extension = "apc.so"
脚本:sed -i 's#extension_dir = "./"#extension_dir = "/usr/local/webserver/php/lib/php/extensions/no-debug-non-zts-20090626/"\nextension = "memcache.so"\nextension = "eaccelerator.so"\nextension = "imagick.so"\n#' /usr/local/php/etc/php.ini
sed -i 's#output_buffering = Off#output_buffering = On#' /usr/local/webserver/php/etc/php.ini

7.配置PHP加速
mkdir -p /tmp/eaccelerator_cache
chmod 777 /tmp/eaccelerator_cache
vi /usr/local/php/etc/php.ini
在配置文件的末尾,加上以下信息:、
[eaccelerator]
zend_extension="/usr/local/php/lib/php/extensions/no-debug-non-zts-20090626/eaccelerator.so"
eaccelerator.shm_size="64"
eaccelerator.cache_dir="/tmp/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"


[apc]
apc.enabled = 1
apc.cache_by_default = on
apc.shm_segments = 1
apc.shm_size = 32
apc.ttl = 600
apc.user_ttl = 600
apc.num_files_hint = 0
apc.write_lock = On


-------------安装phpmyadmin-----------


1.解压并安装
tar zxvf phpMyAdmin-3.4.10.1-all-languages.tar.gz
mv phpMyAdmin-3.4.10.1-all-languages phpmyadmin
cd phpmyadmin/libraries/
cp config.default.php ../config.inc.php
cd ..
chmod 755 phpmyadmin
2,更改phpmyadmin配置文件
vi config.inc.php,查找以下内容,并更改。
$cfg['PmaAbsoluteUri'] = 'http://192.168.1.183/phpmyadmin/';
$cfg['Servers'][$i]['host'] = 'localhost';
$cfg['Servers'][$i]['auth_type'] = 'cookie';
$cfg['Servers'][$i]['user'] = 'root'; // MySQL user
$cfg['Servers'][$i]['password'] = ''; // MySQL password
3.添加nginx虚拟主机
# server for phpmyadmin
  server {
         listen 80;
         server_name 192.168.1.183; ----不要设为本机IP,可以虚拟个eth0:1,另设IP
         location /phpmyadmin {
         index index.html index.php;
         root /var/www;
          }
         location ~^/phpmyadmin.+\.php$ {
         root /var/www;
         fastcgi_pass 127.0.0.1:9000;
         fastcgi_index index.php;
         fastcgi_param SCRIPT_FILENAME   $document_root$fastcgi_script_name;
         include         fastcgi_params;
         }
}
4.在浏览器里输入 http://192.168.1.183/phpmyadmin即可打开phpmyadmin页面。输入mysql密码就可以通过WEB来管理mysql了。



遇到问题:
1.php安装好后,nginx不能访问php页面
nginx的配置文件中,php设定项没有指向正确的目录。把/scripts$fastcgi_script_name改为$document_root$fastcgi_script_name即可。
2.安装php后,在安装php扩展eaccelerator时提示错误。
经查找资料,发现本人安装php版本为5.4,但eaccelerator的最新稳定版暂时不支持php5.4以上版本,最终只要重新安装php5.3版本。
3.安装php扩展imagick-3.0.1时,报大量的error
把imagick更换为更老版本imagick-2.3.0,再次安装OK
4.eaccelerator安装完成后不生效
通过phpinfo查看php安装情况,发现默认的配置文件目录指向/usr/local/php/lib,但本机的配置文件放在/usr/local/php/etc下面,拷贝配置文件到/usr/local/php/lib,或者重新编译的时候加上with-config-file-path参数指定配置文件的路径。
5.配置phpmyadmin后,可以正常使用,但打开nginx默认目录下的php页面,则会提示下载,而不会打开
提示下载是因为系统不能识别到php页面,经查看nginx的配置文件,发现phpmyadmin的server_name写的本机IP,而项目目录则与本机默认的web目录不同,更改phpmyadmin的IP即可。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值