CentOS 5.5/5.6 安装LNMP教程(php5.3.6 + Nginx 1.0.0 + MySQL 5.5.12)

5星 · 超过95%的资源 需积分: 9 74 下载量 89 浏览量 更新于2024-09-22 1 收藏 39KB TXT 举报
本文将详细介绍在CentOS 5.5或5.6系统上安装LNMP(Linux + Nginx + MySQL + PHP)环境的步骤,包括PHP 5.3.6、Nginx 1.0.0和MySQL 5.5.12这三个关键组件的安装和配置。 首先,为了确保系统可以编译源码并安装这些软件,我们需要安装一些必要的依赖包。执行以下Yum命令来安装: ``` yum -y install gcc gcc-c++ autoconf libjpeg libjpeg-dev libpng libpng-dev elf freetype freetype-dev 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-devel libtool libtool-libs libevent-devel libevent openldap openldap-devel nss_ldap openldap-clients openldap-servers libtool-ltdl libtool-ltdl-devel bison ``` 接下来,我们逐一下载所需的源码包: 1. Nginx 1.0.0: ``` wget http://nginx.org/download/nginx-1.0.0.tar.gz ``` 2. MySQL 5.5.12: ``` wget http://mirror.switch.ch/ftp/mirror/mysql/Downloads/MySQL-5.5/mysql-5.5.12.tar.gz ``` 3. PHP 5.3.6: ``` wget http://cn.php.net/get/php-5.3.6.tar.gz/from/this/mirror ``` 4. libiconv 1.13.1:这个库对于某些PHP扩展是必需的。 ``` wget ftp://ftp.csx.cam.ac.uk/pub/software/p ``` 在下载完所有源码包后,按照以下顺序进行编译和安装: 1. 安装libiconv: ``` tar zxf libiconv-1.13.1.tar.gz cd libiconv-1.13.1 ./configure make && make install ``` 2. 安装MySQL: ``` tar zxf mysql-5.5.12.tar.gz cd mysql-5.5.12 ./configure --prefix=/usr/local/mysql --with-extra-charsets=complex --enable-thread-safe-client --enable-assembler --with-charset=utf8 --with-collation=utf8_general_ci --without-docs make && make install ``` 完成安装后,还需要初始化数据库,设置root用户的密码,并启动MySQL服务。 3. 安装Nginx: ``` tar zxf nginx-1.0.0.tar.gz cd nginx-1.0.0 ./configure --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_gzip_static_module --with-http_realip_module make && make install ``` 4. 安装PHP: ``` tar zxf php-5.3.6.tar.gz cd php-5.3.6 ./configure --prefix=/usr/local/php --with-config-file-path=/etc/php.ini --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-dir --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 --enable-mbstring --with-mcrypt --with-gd --enable-gd-native-ttf --with-openssl --with-mhash --enable-pcntl --enable-sockets --with-xmlrpc --enable-zip --enable-soap --with-gettext make && make install ``` 最后,配置Nginx以支持PHP-FPM,编辑Nginx的配置文件(如`/usr/local/nginx/conf/nginx.conf`),添加以下内容到HTTP部分: ```nginx location ~ \.php$ { fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; } ``` 启动Nginx和PHP-FPM服务: ``` /usr/local/nginx/sbin/nginx /usr/local/php/sbin/php-fpm ``` 现在,你已经成功地在CentOS 5.5或5.6上搭建了LNMP环境,可以开始部署和运行PHP应用程序了。记得根据实际需求调整配置参数,例如MySQL的存储引擎、Nginx的缓存设置以及PHP的性能优化选项。同时,为了保持系统的安全性和稳定性,定期更新软件和打补丁是非常重要的。