近期公司打算从lamp 更换到lnmp 平台,所以研究了一下lnmp的安装。将这个整理成了一个脚本.后面会附带给大家的,脚本写的很烂,基本没有什么判断,希望大家能够谅解.可以提出意见,我尽力改正。
软件版本:
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.4 *86_64 mini安装,关闭selinux,iptables
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 下载所有使用到的软件:
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
make && make install
5 安装php扩展库:libmcrypt
tar zxvf libmcrypt-2.5.8.tar.gz
cd libmcrypt-2.5.8/
./configure
make && make install
/sbin/ldconfig
### 注:这里不要退出去了。
cd libltdl/
./configure --enable-ltdl-install
make && make install
6 安装php扩展库:mhash
tar zxvf mhash-0.9.9.9.tar.gz
cd mhash-0.9.9.9/
./configure
make && make install
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/
/sbin/ldconfig
./configure
make && make install
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
make && make install
11 安装php加速:eaccelerator
tar -zxvf eaccelerator-eaccelerator-42067ac.tar.gz
cd eaccelerator-eaccelerator-42067ac
/usr/local/php/bin/phpize
./configure --enable-eaccelerator=shared --with-php-config=/usr/local/php/bin/php-config
make && make install
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
[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/
/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 && make install
14 :安装php扩展库: ImageMagick
123 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/
/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 && make install
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=/usr/local/src/pcre-8.21 --lock-path=/var/run/nginx.lock --pid-path=/var/run/nginx.pid
make && make install
21:修改nginx配置文件
vim /usr/local/nginx/conf/nginx.conf
#修改一些参数,别直接替换文件,这只是一部分
user www;
events {
use epoll;
worker_connections 1024;
}
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/supper/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:浏览器访问:
访问之前建议先关闭selinux,iptables
看到以上信息可以确定我们的lnmp 环境初步搭建完成。关于优化的事情,待研究之后再次释出。
附件有一个lnmp的初始安装脚本,仅在CentOS 6.4 ×86_64位下测试成功。其他未经测试,小心使用。
相关文章:
Ubuntu 14.04 LTS安装LNMP Nginx\PHP5(PHP-FPM)\MySQL:http://www.linuxdiyf.com/linux/10659.html
CentOS 7用户怎样安装LNMP(Nginx+PHP+MySQL):http://www.linuxdiyf.com/linux/10460.html
CentOS 6中配置PHP的LNMP的开发环境:http://www.linuxdiyf.com/linux/11474.html
CentOS 6.4用源代码安装LNMP环境:http://www.linuxdiyf.com/linux/11471.html
CentOS 6.4系统安装配置LNMP及搭建PHP服务器运行环境:http://www.linuxdiyf.com/linux/10690.html