1. 程式人生 > >lamp編譯詳解

lamp編譯詳解

時間 ror develop trac print 要求 tex pcre 授權

首先確認系統環境:centos6.4 min版本

1、安裝需要的開發環境 yum groupinstall "Development Tools" "Server Platform Development" -y 2、下載並安裝依賴的包(由於編譯的是httpd2.4的版本對apr有更高要求) wget http://mirrors.hust.edu.cn/apache//apr/apr-1.6.2.tar.gz wget http://mirrors.hust.edu.cn/apache//apr/apr-util-1.6.0.tar.gz 3、開始編譯安裝依賴包 同步時間:ntpdate time.nist.gov tar -xf apr-1.6.2.tar.gz cd apr-1.6.2 ./configure --prefix=/usr/local/apr make && make install tar xf apr-util-1.6.0.tar.gz cd apr-util-1.6.0 ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr make && make install 如果在apr-util編譯時報錯: 技術分享
解決辦法:yum install expat-devel 4、編譯httpd2.4 wget http://apache.fayea.com//httpd/httpd-2.4.25.tar.gz tar xf httpd-2.4.25.tar.gz cd httpd-2.4.25 由於系統上已經安裝了rpm包的httpd所以存在用戶apache [[email protected] httpd-2.4.25]# id apache uid=48(apache) gid=48(apache) groups=48(apache) [[email protected] httpd-2.4.25]# rpm -qa pcre* pcre-7.8-6.el6.x86_64 安裝依賴包pcre-devel yum -y install pcre-devel ./configure --prefix=/usr/local/apache2.4 --sysconf=/etc/httpd2.4 --enable-so --enable-ssl --enable-cgi --enable-rewrite --with-zlib --with-pcre --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util/ --enable-modules=most --enable-mpms-shared=all --with-mpm=prefork make && make install 將2.4啟動的腳本添加到環境變量: [[email protected]
/* */ local]# vim /etc/profile.d/apache2.sh export PATH=/usr/local/apache2.4/bin:$PATH [[email protected] local]# . /etc/profile.d/apache2.sh [[email protected] local]# echo $PATH /usr/local/apache2.4/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin 啟動httpd2.4服務: apachectl start 編譯安裝mysql: 1、創建相應的賬戶和組 cat /etc/passwd|grep mysql 查看是否存在mysql賬號 groupadd -r mysql useradd -g mysql -r -s /sbin/nologin -M mysql 創建mysql組和mysql賬號 2、創建mysql數據目錄,並授權 mkdir /data/mydata -pv 創建mysql數據目錄 chown -R mysql:mysql /data/mydata 將數據目錄的所屬組所屬用戶修改 由於編譯的是mysql5.6的版本,所以需要使用cmake 3、下載並安裝cmake 下載cmake: wget https://cmake.org/files/v3.7/cmake-3.7.2.tar.gz 安裝cmake: tar xf cmake-3.7.2.tar.gz cd cmake-3.7.2 ./bootstrap gmake make install 4、編譯安裝mysql 下載mysql源文件: wget https://dev.mysql.com/get/Downloads/MySQL-5.6/mysql-5.6.36.tar.gz tar xf mysql-5.6.36.tar.gz cd mysql-5.6.36 cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mysql \ -DMYSQL_DATADIR=/data/mydata \ -DSYSCONFDIR=/etc \ -DWITH_INNOBASE_STORAGE_ENGINE=1 \ -DWITH_ARCHIVE_STORAGE_ENGINE=1 \ -DWITH_BLACKHOLE_STORAGE_ENGINE=1 \ -DWITH_READLINE=1 \ -DWITH_SSL=system \ -DWITH_ZLIB=system \ -DWITH_LIBWRAP=0 \ -DWITH_UNIX_ADDR=/tmp/mysql.sock \ -DDEFAULT_CHARSET=utf8 \ -DDEFAULT_COLLATION=utf8_general_ci make && make install 5、初始化mysql chown -R mysql:mysql /usr/local/mysql 修改屬組屬主 cd /usr/local/mysql/scripts 執行數據初始化 ./mysql_install_db --user=mysql --datadir=/data/mydata 執行此步報錯: [[email protected]
/* */ scripts]# ./mysql_install_db --user=mysql --datadir=/data/mydata FATAL ERROR: Could not find ./bin/my_print_defaults If you compiled from source, you need to run ‘make install‘ to copy the software into the correct location ready for operation. If you are using a binary release, you must either be at the top level of the extracted archive, or pass the --basedir option pointing to that location. 解決辦法: 解決辦法:加上--basedir=/usr/local/mysql ./mysql_install_db --user=mysql --basedir=/usr/local/mysql --datadir=/data/mydata cp support-files/my-default.cnf /etc/my.cnf 復制配置文件 增加到配置文件: 【mysqld】 basedir = /usr/local/mysql datadir = /data/mydata socket = /tmp/mysql.sock 增加套接字文件 cp support-files/mysql.server /etc/init.d/mysqld 復制啟動腳本 vim /etc/profile.d/mysqld.sh export PATH=$PATH:/usr/local/mysql/bin . /etc/profile.d/mysqld.sh chkconfig --add mysqld chkconfig --list|grep mysqld [[email protected] mysql]# service mysqld start Starting MySQL.Logging to ‘/data/mydata/wadeson.err‘. . SUCCESS! [[email protected] mysql]# netstat -tunlp Active Internet connections (only servers) Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 4086/sshd tcp 0 0 :::22 :::* LISTEN 4086/sshd tcp 0 0 :::3306 :::* LISTEN 87380/mysqld 編譯安裝php5.6版本: 1、下載php源碼包:http://php.net/releases/

tar xf php-5.6.30.tar.bz2

cd php-5.6.30

編譯前yum安裝必要的環境

yum install -y libxml2 libxml2-devel bzip2-devel 然後執行編譯: ./configure --prefix=/usr/local/php --with-mysql=/usr/local/mysql --with-openssl --with-mysqli=/usr/local/mysql/bin/mysql_config --enable-mbstring --with-freetype-dir --with-jpeg-dir --with-png-dir --with-mcrypt --with-zlib --with-libxml-dir=/usr --enable-xml --enable-sockets --with-apxs2=/usr/local/apache2.4/bin/apxs --with-config-file-path=/etc --with-config-file-scan-dir=/etc/php.d --with-bz2 --with-gd 報錯如下: configure: error: jpeglib.h not found. 解決辦法: yum -y install libjpeg-devel 繼續執行,依然報錯: configure: error: png.h not found. 解決辦法: yum -y install libpng-devel 再次執行,還是報錯: configure: error: freetype-config not found 解決辦法: yum install freetype-devel 依然執行./configure,報錯: configure: error: mcrypt.h not found. Please reinstall libmcrypt. 解決辦法: wget ftp://mcrypt.hellug.gr/pub/crypto/mcrypt/libmcrypt/libmcrypt-2.5.7.tar.gz tar xf libmcrypt-2.5.7.tar.gz cd libmcrypt-2.5.7 ./configure make && make install 最後再次執行編譯參數,成功 make && make install 上述部分編譯參數解釋: --prefix=/usr/local/php:定義安裝的路徑 --with-mysql=/usr/local/mysql :指定mysql安裝目錄 --with-mysqli=/usr/local/mysql/bin/mysql_config --enable-xml :支持擴展標記語言 --enable-sockets :支持sockets --with-mcrypt :提供加密支持 --with-config-file-path=/etc :在/etc目錄下生成配置文件/etc/php.ini --with-config-file-scan-dir=/etc/php.d :在/etc/php.d目錄下有分配置文件 --with-bz2 :支持bz2壓縮 --enable-maintainer-zts:支持線程的模塊,如果使用prefork請不要加入該選項,可通過命令httpd -V顯示當前加載的模塊 查看當前編譯的httpd2.4支持的mpm: [[email protected] ~]# /usr/local/apache2.4/bin/httpd -V AH00557: httpd: apr_sockaddr_info_get() failed for wadeson AH00558: httpd: Could not reliably determine the server‘s fully qualified domain name, using 127.0.0.1. Set the ‘ServerName‘ directive globally to suppress this message Server version: Apache/2.4.25 (Unix) Server built: Jul 7 2017 00:38:29 Server‘s Module Magic Number: 20120211:67 Server loaded: APR 1.6.2, APR-UTIL 1.6.0 Compiled using: APR 1.6.2, APR-UTIL 1.6.0 Architecture: 64-bit Server MPM: prefork 支持的prefork模塊,於是php沒有上述選項 threaded: no forked: yes (variable process count) Server compiled with.... -D APR_HAS_SENDFILE -D APR_HAS_MMAP -D APR_HAVE_IPV6 (IPv4-mapped addresses enabled) -D APR_USE_SYSVSEM_SERIALIZE -D APR_USE_PTHREAD_SERIALIZE -D SINGLE_LISTEN_UNSERIALIZED_ACCEPT -D APR_HAS_OTHER_CHILD -D AP_HAVE_RELIABLE_PIPED_LOGS -D DYNAMIC_MODULE_LIMIT=256 -D HTTPD_ROOT="/usr/local/apache2.4" -D SUEXEC_BIN="/usr/local/apache2.4/bin/suexec" -D DEFAULT_PIDLOG="logs/httpd.pid" -D DEFAULT_SCOREBOARD="logs/apache_runtime_status" -D DEFAULT_ERRORLOG="logs/error_log" -D AP_TYPES_CONFIG_FILE="/etc/httpd2.4/mime.types" -D SERVER_CONFIG_FILE="/etc/httpd2.4/httpd.conf" 復制php.ini主配置文件: cp php.ini-production /etc/php.ini 然後將httpd與php進行連接,因為httpd是編譯安裝的2.4的版本: [[email protected] httpd2.4]# pwd /etc/httpd2.4 [[email protected] httpd2.4]# ll total 124 drwxr-xr-x. 2 root root 4096 Jul 7 00:40 extra -rw-r--r--. 1 root root 18991 Jul 7 16:22 httpd.conf -rw-r--r--. 1 root root 18759 Jul 7 15:46 httpd.conf.bak -rw-r--r--. 1 root root 13077 Jul 7 00:40 magic -rw-r--r--. 1 root root 60855 Jul 7 00:40 mime.types drwxr-xr-x. 3 root root 4096 Jul 7 00:40 original 在http.conf配置文件中加入以下: DirectoryIndex index.html index.php AddType application/x-httpd-php-source .phps AddHandler php5-script .php AddType text/html .php 並且確認php的模塊已經被啟用:(因為這種模式是和httpd模塊的方式) LoadModule php5_module modules/libphp5.so (這是針對prefork模式) 區分: <IfModule prefork.c> LoadModule php5_module modules/libphp5.so </IfModule> <IfModule worker.c> LoadModule php5_module modules/libphp5-zts.so 然後在網站目錄編寫index.php測試頁面: [[email protected] htdocs]# cat index.php <?php phpinfo(); ?> 技術分享 然後測試是否與數據庫mysql連接: [[email protected] htdocs]# vim index.php <?php phpinfo(); $link = mysql_connect(‘127.0.0.1‘,‘root‘,‘‘); if ($link) echo "successful"; else echo "failure"; mysql_close() ?> /usr/local/php/bin/php -i:查看所有配置信息 為php5.6增加xcache模塊: wget http://xcache.lighttpd.net/pub/Releases/3.0.1/xcache-3.0.1.tar.gz tar xf xcache-3.0.1.tar.gz cd xcache-3.0.1 /usr/local/php/bin/phpize ./configure --enable-xcache --with-php-config=/usr/local/php/bin/php-config make && make install 後執行報錯 報錯如下: .0.1/xcache.c -fPIC -DPIC -o .libs/xcache.o /root/tools/xcache-3.0.1/xcache.c: In function ??zif_xcache_get_special_value?ˉ: /root/tools/xcache-3.0.1/xcache.c:324: error: ??IS_CONSTANT_ARRAY?ˉ undeclared (first use in this function) /root/tools/xcache-3.0.1/xcache.c:324: error: (Each undeclared identifier is reported only once /root/tools/xcache-3.0.1/xcache.c:324: error: for each function it appears in.) make: *** [xcache.lo] Error 1 上面的內容會報錯,原因是php5.6 xcache3.0並不支持,所以官網下載最新版,所以還是多去官網或權威網站比較好 於是下載新版本: wget http://xcache.lighttpd.net/pub/Releases/3.2.0/xcache-3.2.0.tar.gz tar xf xcache-3.2.0.tar.gz cd xcache-3.2.0 /usr/local/php/bin/phpize ./configure --enable-xcache --with-php-config=/usr/local/php/bin/php-config make && make install 出現下面所示: Installing shared extensions: /usr/local/php/lib/php/extensions/no-debug-non-zts-20131226/ [[email protected] xcache-3.2.0]# ll /usr/local/php/lib/php/extensions/no-debug-non-zts-20131226/ total 1264 -rwxr-xr-x. 1 root root 589332 Jul 7 15:46 opcache.so -rwxr-xr-x. 1 root root 701379 Jul 7 16:48 xcache.so 把主配置文件放到php的碎片配置小分隊 [[email protected] xcache-3.2.0]# mkdir /etc/php.d [[email protected] xcache-3.2.0]# cp xcache.ini /etc/php.d/ 修改/etc/php.d/xcache.ini文件中的指定地方 extension = /usr/local/php/lib/php/extensions/no-debug-non-zts-20131226/xcache.so 重啟服務: [[email protected] httpd2.4]# /usr/local/apache2.4/bin/apachectl restart 技術分享

於是整個lamp環境已經編譯成功

note:

如果在編譯php遇見了其他錯誤可以參考如下內容:

http://www.poluoluo.com/jzxy/201505/364819.html

lamp編譯詳解