linux lnmp编译安装

关闭SELINUX

vi /etc/selinux/config

#SELINUX=enforcing #注释掉

#SELINUXTYPE=targeted #注释掉

SELINUX=disabled #增加

:wq!  #保存退出

setenforce 0 #使配置立即生效


mysql 5.5.28安装

安装路径:/usr/local/mysql
数据库路径:/usr/local/mysql/data/

mysql从5.5版本开始,不再使用./configure编译,而是使用cmake编译器,具体的cmake编译参数可以参考mysql官网文档
http://dev.mysql.com/doc/refman/5.5/en/source-configuration-options.html

添加MYSQL用户和组
[root@localhost tools]#groupadd mysql
[root@localhost tools]#useradd mysql -g mysql -s /sbin/nologin

[root@localhost tools]#yum install cmake make -y
[root@localhost tools]#yum -y install gcc gcc-c++ autoconf bison automake zlib* fiex* libxml* ncurses-devel libmcrypt* libtool-ltdl-devel*  #安装依赖包
[root@localhost tools]# cd mysql-5.5.28-linux2.6-i686

配置编译参数
[root@localhost tools]#cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql \
                    -DMYSQL_UNIX_ADDR=/usr/local/mysql/mysql.sock \
                    -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=/usr/local/mysql/data/ \
                    -DMYSQL_TCP_PORT=3306
                    
[root@localhost tools]#CMake Error: The source directory "/root/tools/mysql-5.5.28-linux2.6-x86_64" does not appear to contain CMakeLists.txt.
编译安装时出现上述错误,GOOGLE了一下,发现是下载的包有问题,重新到http://downloads.mysql.com/archives/community/下载源码,版本选5.5.28,
Select Platform:这里选择Source Code,然后在底部找到Generic Linux (Architecture Independent), Compressed TAR Archive(mysql-5.5.28.tar.gz)选下载

[root@localhost tools]#make && make install
[root@localhost tools]#cd /usr/local
[root@localhost tools]#chown mysql.mysql -R mysql  #设置MYSQL目录权限
[root@localhost tools]#cd mysql
[root@localhost tools]#cp support-files/my-medium.cnf /etc/my.cnf  #复制配置文件
[root@localhost tools]#./scripts/mysql_install_db  --user=mysql  --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data/
[root@localhost tools]#cp support-files/mysql.server /etc/init.d/mysqld
[root@localhost tools]#chkconfig mysqld on  #设置开机启动
[root@localhost tools]#service mysqld start   #启动mysql服务
[root@localhost tools]#/usr/local/mysql/bin/mysqladmin -u root password ‘123456789‘  #设置mysql root用户密码

删除root密码为空的记录
[root@localhost tools]#/usr/local/mysql/bin/mysql -u root -p #输入刚才设置的密码
mysql> use mysql;
mysql> delete from user where password=‘‘;
mysql> flush privileges;      #更新权限
mysql> grant all privileges on *.* to root@‘%‘ identified by "root";  #允许ROOT用户远程登陆
mysql> flush privileges;
mysql> quit


php-5.3.28安装

安装依赖包
[root@localhost tools]#yum -y install libjpeg libjpeg-devel 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 
[root@localhost tools]#yum -y install gd-devel libjpeg-devel libpng-devel freetype-devel libxml2-devel curl-devel freetype-devel 
#Nginx
[root@localhost tools]#yum -y install pcre-devel 
#下载PHP库文件
wget http://ncu.dl.sourceforge.net/project/mcrypt/MCrypt/2.6.8/mcrypt-2.6.8.tar.gz
wget http://ncu.dl.sourceforge.net/project/mhash/mhash/0.9.9.9/mhash-0.9.9.9.tar.gz
wget http://ncu.dl.sourceforge.net/project/mcrypt/Libmcrypt/2.5.8/libmcrypt-2.5.8.tar.gz
wget http://ftp.gnu.org/pub/gnu/libiconv/libiconv-1.14.tar.gz 
wget http://nchc.dl.sourceforge.net/project/eaccelerator/eaccelerator/eAccelerator%200.9.6.1/eaccelerator-0.9.6.1.tar.bz2
#Nginx
wget http://nginx.org/download/nginx-1.5.10.tar.gz 
#Nginx(pcre)
wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.34.tar.gz

解压下载的库文件夹

[root@localhost tools]#cd libiconv-1.14
[root@localhost tools]#./configure --prefix=/usr/local
[root@localhost tools]#make && make install
[root@localhost tools]#cd ../

[root@localhost tools]#cd libmcrypt-2.5.8
[root@localhost tools]#./configure
[root@localhost tools]#make && make install
[root@localhost tools]#/sbin/ldconfig  #使所有的库文件都被缓存到ld.so.cache中,避免编译过程中报错找不到库文件
[root@localhost tools]#cd ../
[root@localhost tools]#cd libltdl
[root@localhost tools]#./configure --enable-ltdl-install
[root@localhost tools]#make && make install
[root@localhost tools]#cd ../../

[root@localhost tools]#cd mhash-0.9.9.9
[root@localhost tools]#./configure
[root@localhost tools]#make && make install
[root@localhost tools]#cd ../

[root@localhost tools]#ln -s /usr/local/lib/libmcrypt.la /usr/lib/libmcrypt.la
[root@localhost tools]#ln -s /usr/local/lib/libmcrypt.so /usr/lib/libmcrypt.so
[root@localhost tools]#ln -s /usr/local/lib/libmcrypt.so.4 /usr/lib/libmcrypt.so.4
[root@localhost tools]#ln -s /usr/local/lib/libmcrypt.so.4.4.8 /usr/lib/libmcrypt.so.4.4.8
[root@localhost tools]#ln -s /usr/local/lib/libmhash.a /usr/lib/libmhash.a
[root@localhost tools]#ln -s /usr/local/lib/libmhash.la /usr/lib/libmhash.la
[root@localhost tools]#ln -s /usr/local/lib/libmhash.so /usr/lib/libmhash.so
[root@localhost tools]#ln -s /usr/local/lib/libmhash.so.2 /usr/lib/libmhash.so.2
[root@localhost tools]#ln -s /usr/local/lib/libmhash.so.2.0.1 /usr/lib/libmhash.so.2.0.1
[root@localhost tools]#ln -s /usr/local/bin/libmcrypt-config /usr/bin/libmcrypt-config
[root@localhost tools]#ln -s /usr/local/mysql/lib/libmysqlclient.so /usr/lib/
[root@localhost tools]#ln -s /usr/local/mysql/lib/libmysqlclient.so.18 /usr/lib/libmysqlclient.so.18

[root@localhost tools]#cd mcrypt-2.6.8
[root@localhost tools]#/sbin/ldconfig
[root@localhost tools]#./configure
[root@localhost tools]#make && make install
[root@localhost tools]#cd ../

[root@localhost tools]#cd php-5.3.28
[root@localhost tools]#./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-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --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-gd --enable-gd-native-ttf --with-openssl --with-mhash --enable-pcntl --enable-sockets --with-ldap --with-ldap-sasl --with-xmlrpc --enable-zip --enable-soap
[root@localhost tools]#make && make install
[root@localhost tools]#
[root@localhost tools]#cp php.ini-production /usr/local/php/etc/php.ini
[root@localhost tools]#ln -s /usr/local/php/etc/php.ini /etc/php.ini
[root@localhost tools]#cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
[root@localhost tools]# chmod a+x /etc/init.d/php-fpm
[root@localhost tools]#chkconfig php-fpm on
[root@localhost tools]#cd /usr/local/php/etc/
[root@localhost tools]#cp php-fpm.conf.default php-fpm.conf
[root@localhost tools]#vi php-fpm.conf

把;pid = run/php-fpm.pid前面的分号去掉=>pid = run/php-fpm.pid
user = nobody 改为user = www
group = nobody 改为group = www
保存退出
[root@localhost tools]#cd /root/tool
[root@localhost tools]#tar -xjvf eaccelerator-0.9.6.1.tar.bz2
[root@localhost tools]#cd eaccelerator-0.9.6.1
[root@localhost tools]#/usr/local/php/bin/phpize
[root@localhost tools]#./configure --enable-eaccelerator=shared --with-php-config=/usr/local/php/bin/php-config
[root@localhost tools]# make && make install
[root@localhost tools]#mkdir /tmp/eaccelerator
[root@localhost tools]#chmod 0777 /tmp/eaccelerator
[root@localhost tools]#vi /etc/php.ini
修改;extension_dir = "./" 为extension_dir = "/usr/local/php/lib/php/extensions/no-debug-non-zts-20090626"

在结尾处添加
[eaccelerator]
zend_extension="/usr/local/php/lib/php/extensions/no-debug-non-zts-20090626/eaccelerator.so"
eaccelerator.shm_size="128"
eaccelerator.cache_dir="/tmp/eaccelerator"
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"
:x保存退出

重启PHP
[root@localhost tools]#/etc/rc.d/init.d/php-fpm restart

安装NGINX 1.2.9
[root@localhost tools]# cd pcre-8.34
[root@localhost tools]# ./configure
[root@localhost tools]# make && make install
[root@localhost tools]# cd ..
[root@localhost tools]# cd nginx-1.2.9
[root@localhost tools]# ./configure --prefix=/usr/local/nginx --user=www --group=www --with-http_ssl_module --with-http_realip_module --with-http_gzip_static_module --with-http_stub_status_module --with-pcre
[root@localhost tools]# make && make install
[root@localhost tools]# ulimit -SHn 65535
[root@localhost tools]# ln -s /usr/local/lib/libpcre.so.1 /lib #解决启动时找不到libpcre.so.1这个模块的问题
[root@localhost tools]# vi /usr/local/nginx/conf/nginx.conf
#nginx配置文件内容
user  www www;
worker_processes  1;

error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;

pid        logs/nginx.pid;
worker_rlimit_nofile 65535;

events {
    use epoll;
    worker_connections  65535;
}


http {
    include       mime.types;
    default_type  application/octet-stream;

    #log_format  main  ‘$remote_addr - $remote_user [$time_local] "$request" ‘
    #                  ‘$status $body_bytes_sent "$http_referer" ‘
    #                  ‘"$http_user_agent" "$http_x_forwarded_for"‘;

    access_log  logs/access.log  ;
    charset utf-8;
    server_names_hash_bucket_size 128;#服务器名字的hash表大小
    client_header_buffer_size 32k;#设置客户端的请求头的header buffer的大小
    large_client_header_buffers 4 64k;#用来指定客户端请求中较大的消息头缓存的最大数量和大小
    client_max_body_size 8m;#设置允许客户端请求的最大的单个文件的字节数
    sendfile        on;#开启高效文件传输模式
    tcp_nopush     on;#防止网络阻塞
    tcp_nodelay on; #防止网络阻塞
    keepalive_timeout 60; #长连接超时时间,单位是秒
    #FastCGI相关参数是为了改善网站的性能:减少资源占用,提高访问速度。下面参数看字面意思都能理解。
    fastcgi_connect_timeout 300;
    fastcgi_send_timeout 300;
    fastcgi_read_timeout 300;
    fastcgi_buffer_size 64k;
    fastcgi_buffers 4 64k;
    fastcgi_busy_buffers_size 128k;
    fastcgi_temp_file_write_size 128k;
    #gzip模块设置
    gzip on; #开启gzip压缩输出
    gzip_min_length 1k; #最小压缩文件大小
    gzip_buffers 4 16k; #压缩缓冲区
    #gzip_http_version 1.0; #压缩版本(默认1.1,前端如果是squid2.5请使用1.0)
    gzip_comp_level 2; #压缩等级
    gzip_types text/plain application/x-javascript text/css application/xml;
    gzip_vary on;
    
  
    server {
        listen       80;
        server_name  www.test.com test.com 192.168.1.33;
        root /home/web/test;
        #charset utf-8;

        access_log  logs/test.access.log ;
    index index.php index.html index.htm;
        location / {
            root   /home/web/test;
            index  index.php index.html index.htm;
        }

        #error_page  404              /404.html;

        # redirect server error pages to the static page /50x.html
        #
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }

        # proxy the PHP scripts to Apache listening on 127.0.0.1:80
        #
        #location ~ \.php$ {
        #    proxy_pass   http://127.0.0.1;
        #}

        # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
        #
        location ~ \.php$ {
        #    root           html;
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.php;
        #    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
            include        fastcgi.conf;
        }
    location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
    {
              expires      30d;
        }
    location ~ .*\.(js|css)?$
    {
          expires      1h;
        }

        # deny access to .htaccess files, if Apache‘s document root
        # concurs with nginx‘s one
        #
        #location ~ /\.ht {
        #    deny  all;
        #}
    }
}

[root@localhost tools]#service iptables stop #关闭防火墙,不然访问不到网站目录

安装memcache,imagemagick php扩展

wget wget http://monkey.org/~provos/libevent-2.0.12-stable.tar.gz
wget http://www.memcached.org/files/memcached-1.4.17.tar.gz
wget http://pecl.php.net/get/memcache-3.0.8.tgz
wget http://www.imagemagick.org/download/ImageMagick.tar.gz
wget http://pecl.php.net/get/imagick-3.1.2.tgz

[root@localhost tools]# cd libevent-2.0.12-stable
[root@localhost tools]# ./configure
[root@localhost tools]# make && make install
[root@localhost tools]# cd ..

[root@localhost tools]# cd memcached-1.4.17
[root@localhost tools]# ./configure
[root@localhost tools]# make && make install
[root@localhost tools]# cd ..

[root@localhost tools]# ldconfig /usr/local/lib
[root@localhost tools]# /usr/local/bin/memcached -d -m 128 -l 192.168.1.33 -p 11211 -u www  #d daemon 以守护程序(daemon)方式运行 memcached -l监听地址 -m内存
[root@localhost tools]# cd memcache-3.0.8  #安装PHP扩展
[root@localhost tools]# /usr/local/php/bin/phpize
[root@localhost tools]# ./configure --with-php-config=/usr/local/php/bin/php-config
[root@localhost tools]# make && make install
[root@localhost tools]# cd ..

 安装imagemagick,linux下的图片处理程序和PDO PHP扩展
 
[root@localhost tools]# cd ImageMagick-6.8.9-0
[root@localhost tools]# ./configure
[root@localhost tools]# make && make install
[root@localhost tools]# cd ..

[root@localhost tools]# cd imagick-3.1.2 #安装PHP下的扩展
[root@localhost tools]# /usr/local/php/bin/phpize
[root@localhost tools]# ./configure --with-php-config=/usr/local/php/bin/php-config
[root@localhost tools]# make && make install
[root@localhost tools]#cd ..

[root@localhost tools]#cd php-5.3.28/ext/pdo_mysql
[root@localhost tools]#/usr/local/php/bin/phpize
[root@localhost tools]#./configure --with-php-config=/usr/local/php/bin/php-config --with-pdo-mysql=/usr/local/mysql/
[root@localhost tools]#make && make install
[root@localhost tools]# vi /etc/php.ini

 添加extension=memcache.so
     extension=imagick.so
     extension=pdo_mysql.so

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。