安裝包請各位自行解決哈膛堤,建議去各官網(wǎng)下載最新穩(wěn)定版,不多說晌该,直接開搞
常規(guī)依賴包安裝
yum -y install gcc gcc-c++ autoconf libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-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 openldap openldap-devel openldap-clients openldap-servers make zlib-devel pcre-devel openssl-devel libtool* git tree bison perl gd gd-devel
安裝libiconv庫
有了這個之后就可以在PHP里使用iconv函數(shù)來轉(zhuǎn)換字符編碼啦肥荔,比如想將字符串的編碼從GBK轉(zhuǎn)到UTF-8,就用: iconv('GBK', 'UTF-8', $str);
tar zxvf libiconv-1.14.tar.gz
cd libiconv-1.14
./configure --prefix=/usr/local/libiconv
make && make install
cd ..
安裝libmcrypt,mhash,mcrypt庫
如果PHP自帶的加密算法不能滿足你的需求朝群,就應(yīng)該考慮第三方加密擴展庫了(建議一定要裝呀燕耿,自己寫代碼可能沒用到,但是一些PHP框架可是要用到的姜胖,比如Laravel)誉帅。
按順序安裝libmcrypt,mhash,mcrypt
tar zxvf libmcrypt-2.5.8.tar.gz
cd libmcrypt-2.5.8
./configure
make && make install
cd ..
tar jxvf mhash-0.9.9.9.tar.bz2
cd mhash-0.9.9.9
./configure
make && make install
cd ..
tar zxvf mcrypt-2.6.8.tar.gz
cd mcrypt-2.6.8
./configure
make && make install
cd ..
編譯mcrypt如果報錯:configure: error: *** libmcrypt was not found
echo '/usr/local/lib/'>>/etc/ld.so.conf
ldconfig
編譯mcrypt如果報錯:/bin/rm: cannot remove 'libtoolT': No such file or directory
修改 configure 文件,找到RM='$RM'并改為RM='$RM -f'就行啦
安裝CMake工具
MySQL從5.5版本開始右莱,通過./configure進(jìn)行編譯配置方式已經(jīng)被取消堵第,取而代之的是cmake工具
tar zxvf cmake-3.7.2.tar.gz
cd cmake-3.7.2
./bootstrap && make && make install
cd..
安裝MySQL
#卸載舊版本
rpm -e mysql --nodeps
#創(chuàng)建mysql用戶
groupadd mysql && useradd -g mysql -M mysql
tar zxvf mysql-5.6.24.tar.gz
cd mysql-5.6.24
cmake \
-DCMAKE_INSTALL_PREFIX=/usr/local/mysql \
-DMYSQL_DATADIR=/usr/local/mysql/data \
-DSYSCONFDIR=/etc \
-DMYSQL_USER=mysql \
-DWITH_MYISAM_STORAGE_ENGINE=1 \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_ARCHIVE_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 \
-DENABLE_DOWNLOADS=1 \
-DWITH_PARTITION_STORAGE_ENGINE=1 \
-DEXTRA_CHARSETS=all \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci \
-DWITH_DEBUG=0 \
-DMYSQL_MAINTAINER_MODE=0 \
-DWITH_SSL:STRING=bundled \
-DWITH_ZLIB:STRING=bundled
make && make install
#修改目錄權(quán)限
chown -R mysql:mysql /usr/local/mysql
#拷貝配置文件(注意:如果/etc目錄下面默認(rèn)有一個my.cnf,直接覆蓋即可)
cp support-files/my-default.cnf /etc/my.cnf
#編輯配置文件,在 [mysqld] 部分增加下面一行
vi /etc/my.cnf
datadir = /usr/local/mysql/data #添加MySQL數(shù)據(jù)庫路徑
#執(zhí)行初始化配置腳本隧出,創(chuàng)建系統(tǒng)自帶的數(shù)據(jù)庫和表
/usr/local/mysql/scripts/mysql_install_db --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --user=mysql
#加入系統(tǒng)服務(wù)
cp support-files/mysql.server /etc/init.d/mysqld
chmod +x /etc/init.d/mysqld
#啟動mysql
service mysqld start
#開機啟動
chkconfig mysqld on
#加入環(huán)境變量
echo 'PATH=/usr/local/mysql/bin:$PATH'>>/etc/profile
export PATH
#讓配置生效
source /etc/profile
#設(shè)置root密碼踏志,默認(rèn)是沒有密碼的
/usr/local/mysql/bin/mysqladmin -uroot -p password
cd ..
安裝PHP
tar zxvf php-5.6.30.tar.gz
cd php-5.6.30
./configure \
--prefix=/usr/local/php \
--with-fpm-user=www --with-fpm-group=www \
--with-config-file-path=/usr/local/php/etc \
--with-mhash --with-mcrypt --enable-bcmath \
--enable-mysqlnd --with-mysql --with-mysqli --with-pdo-mysql \
--with-gd --enable-gd-native-ttf --with-jpeg-dir --with-png-dir --with-freetype-dir \
--enable-fpm \
--enable-mbstring \
--enable-pcntl \
--enable-sockets \
--enable-opcache \
--with-openssl \
--with-zlib \
--with-curl \
--with-libxml-dir \
--with-iconv-dir
make && make install
#移動生成php-fpm配置文件
mv /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf
#復(fù)制生成一份php配置文件
cp php.ini-production /usr/local/php/etc/php.ini
#將php-fpm加入系統(tǒng)服務(wù)
cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
#賦予執(zhí)行權(quán)限
chmod +x /etc/init.d/php-fpm
#開機啟動
chkconfig php-fpm on
#創(chuàng)建www用戶
groupadd www && useradd -d /home/www -g www www
#啟動php-fpm
service php-fpm start
cd ..
如果編譯報錯:gcc: Internal error: Killed (program cc1),在編譯參數(shù)后加
--disable-fileinfo
編輯/etc/profile將php加入環(huán)境變量(和前面mysql一樣)
修改PATH=/usr/local/php/bin:/usr/local/mysql/bin:$PATH
export PATH
source /etc/profile
安裝Nginx
tar zxvf nginx-1.10.2.tar.gz
cd nginx-1.10.2
./configure \
--user=www \
--group=www \
--prefix=/usr/local/nginx \
--conf-path=/etc/nginx/nginx.conf \
--error-log-path=/var/log/nginx/error.log \
--http-log-path=/var/log/nginx/access.log \
--pid-path=/var/run/nginx.pid \
--with-http_stub_status_module \
--with-http_gzip_static_module \
--with-http_ssl_module \
--with-pcre
接下來添加Nginx啟動管理腳本/etc/init.d/nginx
關(guān)于啟動腳本請參考鏈接Nginx啟動管理腳本胀瞪,修改腳本變量nginx="/usr/local/nginx/sbin/nginx"针余,保險起見其它變量也盡量核對下
chmod +x /etc/init.d/nginx
service nginx start #啟動nginx服務(wù)
chkconfig nginx on #開機啟動
cd ..
Nginx配置相關(guān)的內(nèi)容后續(xù)有空會補充
至此,LNMP環(huán)境已搭建完畢凄诞。