centos 下 编译安装lnmp

centos 编译a安装lnmp


软件包存放目录: /usr/src

卸载原有的httpd mysql php  不会自行百度


安装必备的一些工具

yum -y install make gcc gcc-c++ gcc-g77 flex bison file libtool libtool-libs autoconf kernel-devel libjpeg libjpeg-devel libpng libpng-devel libpng10 libpng10-devel gd gd-devel freetype freetype-devel libxml2 libxml2-devel zlib zlib-devel glib2 glib2-devel bzip2 bzip2-devel libevent libevent-devel ncurses ncurses-devel curl curl-devel e2fsprogs e2fsprogs-devel krb5 krb5-devel libidn libidn-devel openssl openssl-devel gettext gettext-devel ncurses-devel gmp-devel pspell-devel unzip libcap lsof

安装mysql


创建群组

groupadd mysql

创建不可登录用户 分配组为mysql

useradd -s /sbin/nologin -g mysql -M mysql

5.5以上mysql不能configure只能cmake


下载cmake

wget http://www.cmake.org/files/v2.8/cmake-2.8.12.2.tar.gz 
tar zxvf cmake-2.8.12.2.tar.gz 
cd cmake-2.8.12.2 
./configure 
make && make install


下载mysql 5.6.34

wget http://mirrors.sohu.com/mysql/MySQL-5.6/mysql-5.6.34.tar.gz
tar xf mysql-5.6.34.tar.gz

cmake 与 安装 路径自行指定

cd mysql-5.6.34
cmake \
-DCMAKE_INSTALL_PREFIX=/usr/local/mysql \
-DMYSQL_DATADIR=/usr/local/mysql/data \
-DSYSCONFDIR=/etc \
-DWITH_MYISAM_STORAGE_ENGINE=1 \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_MEMORY_STORAGE_ENGINE=1 \
-DWITH_READLINE=1 \
-DMYSQL_UNIX_ADDR=/var/lib/mysql/mysql.sock \
-DMYSQL_TCP_PORT=3306 \
-DENABLED_LOCAL_INFILE=1 \
-DWITH_PARTITION_STORAGE_ENGINE=1 \
-DEXTRA_CHARSETS=all \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci \
-DMYSQL_USER=mysql \
-DWITH_DEBUG=0 \
-DWITH_SSL=system
make && make install

修改 /usr/local/mysql 权限

chmod +w /usr/local/mysql
chown -R mysql:mysql /usr/local/mysql

进入support-files 如果有/etc my.cnf 备份 复制my-default.cnf 到/etc 改名为my.cnf

cd support-files/
mv /etc/my.cnf /etc/my.cnf.bk
cp my-default.cnf /etc/my.cnf

初始化配置脚本

/usr/local/mysql/scripts/mysql_install_db --defaults-file=/etc/my.cnf --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --user=mysql

拷贝mysql安装目录下的support-files服务脚本到init.d目录 并赋予权限

cp support-files/mysql.server /etc/init.d/mysqld
chmod +x /etc/init.d/mysqld

设置开机启动

chkconfig mysqld on

启动mysql

service mysqld start

修改环境变量

vim /etc/profile

末尾添加


PATH=/usr/local/mysql/bin:$PATH

export PATH

让配置立即生效

source /etc/profile

进入mysql 无密码

mysql -u root -p

赋予权限 同时设置密码

GRANT ALL PRIVILEGES ON *.* TO 'username'@'host' IDENTIFIED BY '你的密码' WITH GRANT OPTION;

mysql 安装完成 !


安装php 5.5.30


安装libiconv库

wget http://ftp.gnu.org/pub/gnu/libiconv/libiconv-1.14.tar.gz
tar zxvf libiconv-1.14.tar.gz
cd libiconv-1.14
./configure --prefix=/usr/local/libiconv
make && make install
cd ..

下载安装php 5.5.30

wget http://mirrors.sohu.com/php/php-5.5.30.tar.gz
tar xf php-5.5.30.tar.gz
cd php-5.5.30
./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --enable-fpm --with-fpm-user=www --with-fpm-group=www --with-mysql=mysqlnd --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --with-iconv-dir --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir=/usr --enable-xml --disable-rpath --enable-magic-quotes --enable-safe-mode --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --with-curl --with-curlwrappers --enable-mbregex --enable-mbstring --with-mcrypt --enable-ftp --with-gd --enable-gd-native-ttf --with-openssl --with-mhash --enable-pcntl --enable-sockets --with-xmlrpc --enable-zip --enable-soap --without-pear --with-gettext --disable-fileinfo --enable-maintainer-zts
make && make install

修改fpm配置php-fpm.conf.default的文件名称

mv /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf

复制php.ini文件

cp php.ini-production /usr/local/php/etc/php.ini

复制php-fpm启动脚本到init.d

cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm

赋予执行权限

chmod +x /etc/init.d/php-fpm

添加为启动项

chkconfig --add php-fpm

设置开机启动

chkconfig php-fpm on

给php-fpm创建一个指定用户组

groupadd php
useradd -s /sbin/nologin -g php -M php

启动php-fpm

service php-fpm start

下载安装nginx


安装pcre库

wget http://ftp.exim.llorien.org/pcre/pcre2-10.10.tar.gz
tar xf pcre2-10.10.tar.gz
cd pcre2-10.10
./configure
make && make install

安装zlib库

wget http://zlib.net/zlib-1.2.8.tar.gz
tar -zxvf zlib-1.2.8.tar.gz
cd zlib-1.2.8
./configure
make && make install

安装ssl

wget http://www.openssl.org/source/openssl-1.0.1g.tar.gz
tar -zxvf openssl-1.0.1g.tar.gz


下载nginx1.8.0

wget http://mirrors.sohu.com/nginx/nginx-1.8.0.tar.gz
tar xf nginx-1.8.0.tar.gz
cd nginx-1.8.0
./configure \
--user=www \
--group=www \
--prefix=/usr/local/nginx \
--with-http_stub_status_module \
--with-http_ssl_module \
--with-http_gzip_static_module \
--with-pcre=/usr/local/src/pcre-8.35 \
--with-zlib=/usr/local/src/zlib-1.2.8 \
--with-openssl=/usr/local/src/openssl-1.0.1g 


修改nginx.conf

将下面内容的注释打开

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 

phpinfo() 没问题 链接Mysql可能会出现no such file 的情况

在phpinfo()中找到 pdo mysqli mysql三个的socket路径 并进入mysql 执行STATUS 查看UNIX socket的值 

进入php.ini 将do mysqli mysql三个的socket路径改成查找出来的UNIX socket的值

重启php-fpm

	kill -USR2 `cat /var/run/php-fpm/php-fpm.pid`

重启nginx

	/usr/local/nginx/sbin/nginx -s reload

至此centos 下lnmp安装已完成

你可能感兴趣的:(服务器)