1. 程式人生 > >linux 基礎學習編譯安裝php+mysql+python3+memcached+radis+rabbitmq+libevent+tcl+gcc+erlang

linux 基礎學習編譯安裝php+mysql+python3+memcached+radis+rabbitmq+libevent+tcl+gcc+erlang

linux 基礎學習之一

CentOS 6.9 編譯安裝 Nginx+PHP+MYSQL


0x01 環境約束

源碼位置 /home/[用戶文件夾]

源碼編譯安裝位置 /usr/local/[軟件名]

CentOS6.9 x86 - 64 最小化安裝 配置好網絡 用戶 使用Xshell登錄


0x02 軟件下載


內網地址:

http://192.168.20.252/src/php.tar.gz

http://192.168.20.252/src/cmake.tar.gz

http://192.168.20.252/src/libmcrypt.tar.gz

http://192.168.20.252/src/mysql.tar.gz

http://192.168.20.252/src/nginx.tar.gz

http://192.168.20.252/src/pcre.tar.gz


0x03 安裝前的準備

使用用戶登錄主機

su #將當前用戶提升至root權限


yum update -y # 安裝當前操作系統的最新補丁,確保系統是最新的

#以下是安裝依賴組件,編譯工具,庫文件

yum install -y make apr* autoconf automake curl-devel gcc gcc-c++ zlib-devel openssl openssl-devel pcre-devel gd kernel keyutils patch perl kernel-headers compat* mpfr cpp glibc libg

omp libstdc++-devel ppl cloog-ppl keyutils-libs-devel libcom_err-devel libsepol-devel libselinux-devel krb5-devel libXpm* freetype lib libpng libpng-devel libxml2-devel wget screen cyrus-sasl-devel.x86_64

0x04 安裝cmake


tar zxvf cmake.tar.gz

cd cmake-[tab]

./configure && make && make install


0x05 安裝MySQL


groupadd mysql #添加mysql用戶組

useradd -s /sbin/nologin -g mysql -r mysql #創建用戶 mysql 並加入到mysql用戶組 ,不允許mysql用戶直接登錄系統

mkdir -p /data/mysql #創建MySQL數據庫文件存放目錄

chown -R mysql:mysql /data/mysql #設置權限

tar zxvf mysql.tar.gz

cd mysql-

cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_DATADIR=/data/mysql/ -DSYSCONFDIR=/etc #編譯器編譯前配置檢查

make && make install #編譯和安裝

cd /usr/local/mysql

cp ./support-files/my-default.cnf /etc/my.cnf #拷貝配置文件

vi /etc/my.cnf #編輯配置文件 在[mysqld]部分添加

datadir = /data/mysql #添加mysql數據庫路徑

./scripts/mysql_install_db --user=mysql #生成mysql系統數據庫

cp ./support-files/mysql.server /etc/rc.d/init.d/mysqld #把mysql加入到系統服務

chmod 755 /etc/init.d/mysqld #增加執行權限

chkconfig mysqld on #開機啟動該服務

vi /etc/rc.d/init.d/mysqld #編輯服務啟動腳本

basedir = /usr/local/mysql

datadir = /data/mysql



service mysqld start #啟動mysql服務

vi /etc/profile #編輯系統環境變量 在末尾增加如下環境變量

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


source /etc/profile #系統環境變量生效

#下面把mysql的庫文件添加到系統的默認位置中,這樣在編譯php的時候,不用制定mysql的庫文件地址

ln -s /usr/local/mysql/lib/mysql /usr/lib/mysql

ln -s /usr/local/mysql/include/mysql /usr/include/mysql


reboot #第一次重啟


mysql_secure_installation #設置MySQL的 root用戶密碼

service mysqld restart #重啟mysql服務


0x06 安裝PCRE


tar zxvf pcre.tar.gz

cd pcre-

./configure --prefix=/usr/local/pcre && make && make install


0x07 安裝nginx


groupadd www

useradd -s /sbin/nologin -g www -r www

tar zxvf nginx.tar.gz

cd nginx-

./configure --prefix=/usr/local/nginx --without-http_memcached_module --user=www --group=www --with-http_stub_status_module --with-openssl=/usr/ --with-pcre=/home/jue/pcre-8.41/

make && make install



vi /etc/init.d/nginx

[復制nginx啟動腳本]



chmod 775 /etc/rc.d/init.d/nginx #設置運行權限

chkconfig nginx on

/etc/rc.d/init.d/nginx restart #重啟nginx 只是為了測試

service nginx restart #重啟nginx服務



0x08 安裝 libmcrypt

tar zxvf libmcrypt.tar.gz

cd libmcrypt-

./configure && make && make install


0x09 安裝php


tar zxvf php.tar.gz

cd php-

mkdir -p /usr/local/php

./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-mysql-sock=/tmp/mysql.sock --with-gd --with-iconv --with-zlib --enable-xml --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --with-curlwrappers --enable-mbregex --enable-fpm --enable-mbstring --enable-ftp --enable-gd-native-ttf --with-openssl --enable-pcntl --enable-sockets --with-xmlrpc --enable-zip --enable-soap --with-pear --with-gettext --enable-session --with-mcrypt --with-curl

make && make install

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

rm -rf /etc/php.ini

ln -s /usr/local/php/etc/php.ini /etc/php.ini

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

vi /usr/local/php/etc/php-fpm.conf #在這個文件中設置 3項

user = www

group = www

pid = run/php-fpm.pid #去掉了前面的分號



cp /home/feng/php-5.6.31/sapi/fpm/init.d.php-fpm /etc/rc.d/init.d/php-fpm

chmod 755 /etc/rc.d/init.d/php-fpm

chkconfig php-fpm on

vi /etc/php.ini

data.timezone = RPC #設置時區



0x10 配置nginx支持php

mkdir -p /home/wwwroot

chown -R www:www /home/wwwroot

vi /usr/local/nginx/conf/nginx.conf

user www www;


root /home/wwwroot #web根目錄

index index.php index.html index.htm; #添加index.php


location ~ \.php$ {

root /home/wwwroot;

fastcgi_pass 127.0.0.1:9000;

fastcgi_index index.php;

fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;

include fastcgi_params;

}







/etc/init.d/nginx restart


0x11 測試


cd /home/wwwroot

vi index.php

<?php phpinfo();?>



chown -R www:www /home/wwwroot

curl http://127.0.0.1/

curl http://localhost/



配置python3

# wget http://192.168.40.66/python3.tar.gz

tar -zxvf python3.tar.gz

cd Python-3.6.2/

./configure --prefix=/usr/local/python3 && make && make install

ln -s /usr/local/python3/bin/python3.6 /usr/bin/python3

cd /home/ht



配置libevent 與 memcached


99 wget http://192.168.100.252/src/libevent.tar.gz

100 wget http://192.168.100.252/src/memcached.tar.gz

102 tar -zxvf libevent.tar.gz

103 cd libevent-2.1.8-stable/

104 ./configure --prefix=/usr/local/libevent

105 make && make install

106 cd ..


108 tar -zxvf memcached.tar.gz

109 cd memcached-1.5.0/

111 ./configure --prefix=/usr/local/memcached --enable-sasl --with-libevent=/usr/local/libevent && make && make install

cd /usr/local/python3/bin

./pip3.6 install python3-memcached




配置gcc

209 wget http://192.168.100.252/src/gcc.tar.gz

210 tar -zxvf gcc.tar.gz

211 mkdir gccmake

213 cd gcc-4.9.4/

214 vi ./contrib/download_prerequisites

wget http://192.168.100.252/src/gcc/$MPFR.tar.bz2 || exit 1 (配置文件,改URL)

215 ./contrib/download_prerequisites

216 cd ..

220 cd gccmake

221 ../gcc-4.9.4/configure --enable-checking=release --enable-languages=c,c++ --disable-multilib

223 make && make install

配置redis

cd /home/ht

224 wget http://192.168.100.252/src/tcl.tar.gz

225 wget http://192.168.100.252/src/redis.tar.gz

232 tar -zxvf tcl.tar.gz

234 cd tcl8.6.6/

236 cd /home/ht

237 rm -rf /usr/lib64/libstdc

239 cp /home/ht/soft/gccmake/x86_64-unknown-linux-gnu/libstdc++-v3/src/.libs/libstdc++.so /usr/lib64/libstdc++.so.

240 rm -rf /usr/lib64/libstdc++.so.6

241 ln -sv /usr/lib64/libstdc++.so /usr/lib64/libstdc++.so.6

242 gcc -v

243 cd /home/ht

246 cd tcl8.6.6/

247 cd unix

./configure

252 make install && make install-private-headers

253 cd ..

255 tar -zxvf redis.tar.gz

257 cd redis-3.2.10/

258 make PREFIX=/usr/local/redis install

259 cd /usr/local/redis/

260 mkdir conf

261 cd /home/jue/

263 cd redis-3.2.10/

265 cp redis.conf /usr/local/redis/conf

266 cd ..

268 ln -s /usr/local/mysql/lib/mysql /usr/lib/mysql

269 ln -s /usr/local/mysql/include/mysql /usr/include/mysql

288 ./pip3.6 install python-redis (在 /usr/local/python3/bin 下)



配置erlang

394 cd /home/ht

395 ls

396 mkdir rabbit

cd rabbit

399 wget http://192.168.100.252/src/rabbitmq.tar.xz

400 wget http://192.168.100.252/src/otp.tar.gz

401 yum install kernel-devel m4 ncurses-devel openssl-devel

408 tar -zxvf otp.tar.gz

411 cd otp_src_20.0/

412 ./configure --prefix=/usr/local/erlang --with-ssl --enable-threads --enable-smmp-support --enable-kernel-poll --enable-hipe --without-javac

416 make && make install



配置rabbit


450 cd /usr/bin

452 rm -rf python python2

453 ll python*

455 vim yum

470 cd /usr/bin

471 ln -sv /usr/local/python3/bin/python3.6 /usr/bin/python

484 wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-6.repo ( 視察情況)(yum源)

485 yum makecache(yum緩存)

525 vi /etc/profile

526 source /etc/profile

cd rabbit

442 tar -xvf rabbitmq.tar.xz

534 cd rabbitmq-server-3.6.10/

537 yum install zip rsync libxslt -y

538 make PREFIX=/usr/local/rabbitmq install

make && make install

539 cd /usr/local/python3/bin

541 ./pip3.6 install simplejson




linux 基礎學習編譯安裝php+mysql+python3+memcached+radis+rabbitmq+libevent+tcl+gcc+erlang