centos 6.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版)
系统安装需求:
centos 6.5 x86_64 vmware安装,关闭selinux,iptables
磁盘20g
注意:系统全新安装,不是之前的系统卸载了重装
前提:由于要使用编译安装,所以查看httpd、mysql、php是否安装
[root@localhost ~]#rpm -q httpd mysql php
如果安装则卸载:
[root@localhost ~]#rpm -e httpd --nodeps
[root@localhost ~]#rpm -e mysql --nodeps
[root@localhost ~]#rpm -e php --nodeps
find / -name php mysql nginx
rm -rf ***
1 安装解决依赖关系:
yum install -y wget gcc gcc-c++ autoconf libjpeg libjpeg-devel perl perl* perl-cpan 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 png jpeg autoconf gcc cmake
make gcc-c++ gcc ladp ldap* ncurses ncurses-devel zlib zlib-devel zlib-static pcre pcre-devel pcre-static
openssl openssl-devel perl libtoolt openldap-devel libxml2-devel ntpdate cmake gd* gd2 imagemagick-devel jpeg
jpeg* pcre-dev* fontconfig libpng libxml2 zip unzip gzip
2 下载所有使用到的软件:(13个)
wget http://ftp.gnu.org/gnu/libiconv/libiconv-1.13.tar.gz
wget http://lcmp.googlecode.com/files/libmcrypt-2.5.8.tar.gz
wget http://jaist.dl.sourceforge.net/project/mcrypt/mcrypt/2.6.8/mcrypt-2.6.8.tar.gz
wget http://jaist.dl.sourceforge.net/project/mhash/mhash/0.9.9.9/mhash-0.9.9.9.tar.gz
wget http://vps.googlecode.com/files/memcache-2.2.5.tgz
wget http://vps.googlecode.com/files/pdo_mysql-1.0.2.tgz
wget http://pecl.php.net/get/imagick-3.1.2.tgz
wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.21.tar.gz
wget http://netcologne.dl.sourceforge.net/project/mysql.mirror/mysql%205.5.30/mysql-5.5.30.tar.gz
wget http://mynginx.googlecode.com/files/imagemagick.tar.gz
wget http://us3.php.net/get/php-5.4.21.tar.gz/from/cn2.php.net/mirror
wget https://lnamp-web-server.googlecode.com/files/eaccelerator-eaccelerator-42067ac.tar.gz
wget http://nginx.org/download/nginx-1.4.0.tar.gz
3 安装mysql-5.5.0
groupadd mysql
useradd mysql -g mysql
tar -zxvf mysql-5.5.30.tar.gz
cd mysql-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 && make install
mkdir -p /data/mysql
chown mysql.mysql -r /data/mysql
mv /etc/my.cnf /etc/my.cnf-old
cp support-files/my-medium.cnf /etc/my.cnf
chmod 755 scripts/mysql_install_db
scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql --datadir=/data/mysql/
cp support-files/mysql.server /etc/init.d/mysqld
chmod 755 /etc/init.d/mysqld
chkconfig mysqld on
service mysqld start
设置mysql的root密码为123456
/usr/local/mysql/bin/mysqladmin -u root password '123456'
4 安装php的扩展库:libiconv
tar zxvf libiconv-1.13.tar.gz
cd libiconv-1.13/
./configure --prefix=/usr/local
5 安装php扩展库:libmcrypt
tar zxvf libmcrypt-2.5.8.tar.gz
cd libmcrypt-2.5.8/
./configure
/sbin/ldconfig
### 注:这里不要退出去了。##
cd libltdl/
./configure --enable-ltdl-install
6 安装php扩展库:mhash
tar zxvf mhash-0.9.9.9.tar.gz
cd mhash-0.9.9.9/
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
tar zxvf mcrypt-2.6.8.tar.gz
cd mcrypt-2.6.8/
9 安装php-5.4.21:
tar -zxvf php-5.4.21.tar.gz
cd php-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/
make zend_extra_libs='-liconv'
make install
cp -f php.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
tar zxvf memcache-2.2.5.tgz
cd memcache-2.2.5/
/usr/local/php/bin/phpize
./configure --with-php-config=/usr/local/php/bin/php-config
11 安装php加速:eaccelerator
tar -zxvf eaccelerator-eaccelerator-42067ac.tar.gz
cd eaccelerator-eaccelerator-42067ac
./configure --enable-eaccelerator=shared --with-php-config=/usr/local/php/bin/php-config
12 修改php.ini增加memcache,ea等软件信息
添加memcache库的位置:
vim /usr/local/php/php.ini
extension_dir = "/usr/local/php/lib/php/extensions/no-debug-non-zts-20100525"
extension = "memcache.so"
extension = "pdo_mysql.so"
extension = "imagick.so"
添加eaccelerator库的位置信息:
;eaccelerator #err notice there
[eaccelerator]
zend_extension="/usr/local/php/lib/php/extensions/no-debug-non-zts-20100525/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"
eaccelerator.compress="1"
eaccelerator.compress_level="9"
eaccelerator.keys = "disk_only"
eaccelerator.sessions = "disk_only"
eaccelerator.content = "disk_only"
mkdir -p /usr/local/eaccelerator_cache
chmod 0777 /usr/local/eaccelerator_cache
13 :安装php扩展库:pdo_mysql
tar zxvf pdo_mysql-1.0.2.tgz
cd pdo_mysql-1.0.2/
./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/
14 :安装php扩展库: imagemagick
tar zxvf imagemagick.tar.gz
cd imagemagick-6.5.1-2/
./configure && make && make install
15:安装php扩展库:imagick
tar zxvf imagick-3.1.2.tgz
cd imagick-3.1.2/
ln -s /usr/local/include/imagemagick-6 /usr/local/include/imagemagick
16:添加www用户,为系统运行nginx专用用户:
/usr/sbin/groupadd www
/usr/sbin/useradd -g www www
mkdir -p /var/log/nginx
chmod +w /var/log/nginx
chown -r www:www /var/log/nginx
mkdir -p /data0/www
chmod +w /data0/www
chown -r www: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: configuration file /usr/local/php/etc/php-fpm.conf test is successful
看到上面的信息 证明php配置文件正常,可以启动了。
18: 添加环境变量:
echo "export path=\$path:/usr/local/php/sbin/" >>/etc/profile
echo "export path=\$path:/usr/local/php/bin/" >>/etc/profile
. /etc/profile
19:安装nginx的 pcre
tar -zxvf pcre-8.21.tar.gz
cd pcre-8.21 && ./configure && make && make install
20:编译安装 nginx
tar -zxvf nginx-1.4.0.tar.gz
cd nginx-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
21:修改nginx配置文件
vim /usr/local/nginx/conf/nginx.conf
#修改一些参数,别直接替换文件,这只是一部分在events模块添加 注释掉location
user www;
events {
use epoll;
worker_connections 1024;
}
#注意 把/scripti改为$document_root$ 不然就是 file not found
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;
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/mysqld restart" >> /etc/rc.local
24:启动nginx 启动php-fpm
24:浏览器访问:
http://ip/index.php
赠送:
可能会报错 403 404
403 是你的权限问题。
404 是你的nginx主配置文件问题。
请多指教!
参考:
http://renzhenxing.blog.51cto.com/728846/1321572