centos 6.2系統下編譯安裝lamp環境

來源:互聯網
上載者:User

標籤:mysql http php 源碼安裝 lamp

系統內容:centOs 6.2(純淨系統內容,已做初步系統最佳化)

系統核心:2.6.32-220.el6.x86_64

軟體版本:http-2.4.2;    mysql-5.5.23;    php-5.3.13

閑言碎語:通過源碼方式安裝軟體,需要準備好安裝環境(如gcc等工具)

個人學習、交流QQ:875656692

yum -y install gcc gcc-c++ openssl openssl-devel yum install -y ncurses ncurses-devel


1.    編譯安裝http-2.4.2 


1.1    下載所需軟體包

http     : http://www.apache.org/

apr      : http://www.apache.org/

pcre    :    http://www.pcre.org/


1.2    解壓

tar -xf httpd-2.4.2.tar.bz2 tar -xf apr-util-1.4.1.tar.bz2 tar -xf apr-1.4.6.tar.bz2 tar -xf apr-iconv-1.2.1.tar.bz2 tar -xf pcre-8.35.tar.gz


1.3    編譯、安裝

cd apr-1.4.6./configure --with-apr=/usr/local/aprmake && make installcd ..
cd apr-util-1.4.1./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr/make && make installcd ..
cd apr-iconv-1.2.1./configure --prefix=/usr/local/apr-iconv --with-apr=/usr/local/apr/make && make installcd ..
cd pcre-8.35./configure --prefix=/usr/local/pcremake && make installcd ..
cd httpd-2.4.2./configure --prefix=/usr/local/apache2 --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util --with-apr-iconv=/usr/local/apr-iconv --with-pcre=/usr/local/pcre --enable-ssl --enable-rewrite --enable-dav --enable-authz --enable-cgid --enable-cgi --enable-module=somake && make installcd ..##### http-2.4.2 編譯安裝完成 #####


1.4    配置

建立apache程式使用者(用於替代預設daemon)useradd  -M -s /sbin/nologin web(不建立家目錄;禁止登陸)

編輯apache設定檔vim /usr/local/apache/conf/http.conf

修改“DirectoryIndex index.html”為“DirectoryIndex index.html index.php”

##添加對PHP檔案的解析

修改“Options Indexes FollowSymLinks”為“Options FollowSymLinks”

##不顯示目錄結構

修改“AllowOverride None ”為“AllowOverride All”

##開啟apache支援偽靜態,有三處

去掉注釋“#LoadModule rewrite_module modules/mod_rewrite.so”為“ LoadModule rewrite_module modules/mod_rewrite.so”  

##開啟apache支援偽靜態

去掉注釋“#ServerName www.example.com:80”為“ServerName www.name.com:80”

添加apache到全域環境變數

echo "export PATH=$PATH:/usr/local/apache2/bin" >> /etc/profile && source /etc/profile

檢查文法/usr/local/apache/bin/apachectl -tSyntax OK

啟動apache

/usr/local/apache/bin/apachectl

開啟瀏覽器輸入:IP/index.html

It Works !


2.    編譯安裝mysql-5.5.23


2.1    下載所需軟體包

cmake    :http://www.cmake.org/ 

mysql      :http://www.mysql.com/downloads/


2.2    解壓

tar -xf cmake-2.8.8.tar.gztar -xf mysql-5.5.23.tar.gz


2.3    編譯、安裝

cd cmake-2.8.8./configuremake && make installcd ..
cd mysql-5.5.23cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql-5.5.23 -DMYSQL_DATADIR=/usr/local/mysql-5.5.23/data/ -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DWITH_EXTRA_CHARSETS:STRING=all -DWITH_MYISAM_STORAGE_ENGINE=1 -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_ARCHIVE_STORAGE_ENGINE=1 -DWITH_READLINE=1 -DENABLED_LOCAL_INFILE=1 -DMYSQL_USER=mysql -DWITH-EMBEDDED_SERVER=1 -DSYSCONFDIR=/usr/local/mysql-5.5.23/conf/my.cnf -DMYSQL_TCP_PORT=3308 -DWITH_SSL=yes -DWITH_MEMORY_STORAGE_ENGINE=1 -DWITH_FEDERATED_STORAGE_ENGINE=1 -DWITH_PARTITION_STORAGE_ENGINE=1 -DINSTALL_PLUGINDIR=/usr/local/mysql-5.5.23/pluginmake && make installcd ..添加軟串連,以便於mysql版本升級ln -s /usr/local/mysql-5.5.23/ /usr/local/mysql##### mysql-5.5.23 編譯安裝完成 #####


2.4    配置mysql

建立mysql使用者(禁止登陸、不建立家目錄)useradd -M -s /sbin/nologin mysql初始化CMD/usr/local/mysql-5.5.23/scripts/mysql_install_db --basedir=/usr/local/mysql-5.5.23/ --datadir=/usr/local/mysql-5.5.23/data/ --user=mysql初始化結果展示WARNING: The host ‘84‘ could not be looked up with resolveip.This probably means that your libc libraries are not 100 % compatiblewith this binary MySQL version. The MySQL daemon, mysqld, should worknormally with the exception that host name resolving will not work.This means that you should use IP addresses instead of hostnameswhen specifying MySQL privileges !Installing MySQL system tables...OKFilling help tables...OKTo start mysqld at boot time you have to copysupport-files/mysql.server to the right place for your systemPLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER !To do so, start the server, then issue the following commands:/usr/local/mysql-5.5.23//bin/mysqladmin -u root password ‘new-password‘/usr/local/mysql-5.5.23//bin/mysqladmin -u root -h 84 password ‘new-password‘Alternatively you can run:/usr/local/mysql-5.5.23//bin/mysql_secure_installationwhich will also give you the option of removing the testdatabases and anonymous user created by default.  This isstrongly recommended for production servers.See the manual for more instructions.You can start the MySQL daemon with:cd /usr/local/mysql-5.5.23/ ; /usr/local/mysql-5.5.23//bin/mysqld_safe &You can test the MySQL daemon with mysql-test-run.plcd /usr/local/mysql-5.5.23//mysql-test ; perl mysql-test-run.plPlease report any problems with the /usr/local/mysql-5.5.23//scripts/mysqlbug script!
配置mysql全域環境變數echo "export PATH=$PATH:/usr/local/mysql/bin/mysql" >> /etc/profile  $$ source /etc/profile
拷貝mysql設定檔到指定路徑下cp /usr/local/mysql/support-files/my-innodb-heavy-4G.cnf /usr/local/mysql/conf/my.cnf
編譯mysql設定檔,根據自己的實際情況修改my.cnfbasedir = /usr/local/mysql/datadir = /usr/local/mysql/data授權mysql使用者對資料目錄的操作許可權chown -R mysql:mysql /usr/local/mysql-5.5.23/data
啟動mysqlmysqld_safe  --defaults-file=/usr/local/mysql/conf/my.cnf &
設定mysql使用者root的登陸密碼(初次安裝完成mysql,root登陸密碼為空白,可直接登陸)mysqladmin -u root password ‘new-password‘
PS:匯出、匯入資料(方法很多,可自行選擇)匯出:mysqldump -uroot -p(passwd) DB_name > /dir/DB_name.sql匯入:mysql -uroot -p(passwd) DB_name < /dir/DB_name.sql


3.    編譯安裝php-5.3.13

3.1    解壓

tar -xf php-5.3.13.tar.bz2


3.2    編譯、安裝

PS:參數可以自己選擇,選擇的越多,所要安裝的依賴也越多(個人理解,僅供參考)我這裡需要安裝一個 ibxml2-devel

yum install -y libxml2-devel
cd php-5.3.13./configure --prefix=/usr/local/php-5.3.13 --with-config-file-path=/usr/local/php-5.5.13/etc --with-mysql=/usr/local/mysql-5.5.23/ --with-mysqli=/usr/local/mysql-5.5.23/bin/mysql_config --with-iconv-dir --with-libxml-dir --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-pcre-dir=/usr/local/pcre --enable-xml --with-apxs2=/usr/local/apache2/bin/apxs --enable-inline-optimization --enable-zip --with-bz2 --without-pear --with-curl=/usr/local/curl-7.3make && make installcd ..##### php-5.3.13 編譯安裝完成 #####


3.3    配置php(此處參考http://sonice.blog.51cto.com/994545/796317)

cp /usr/local/src/php-5.5.23/php.ini-production  /usr/local/php5/etc/php.inivi /usr/local/php5/etc/php.ini

找到“;open_basedir =”;修改為“open_basedir = .:/tmp/”##防止php木馬跨站

找到“disable_functions =”;修改為“disable_functions = passthru,exec,system,chroot,scandir,chgrp,chown,shell_exec,proc_open,proc_get_status,ini_alter,ini_alter,ini_restore,dl,openlog,syslog,readlink,symlink,popepassthru,stream_socket_server,escapeshellcmd,dll,popen,disk_free_space,checkdnsrr,checkdnsrr,getservbyname,getservbyport,disk_total_space,posix_ctermid,posix_get_last_error,posix_getcwd, posix_getegid,posix_geteuid,posix_getgid, posix_getgrgid,posix_getgrnam,posix_getgroups,posix_getlogin,posix_getpgid,posix_getpgrp,posix_getpid, posix_getppid,posix_getpwnam,posix_getpwuid, posix_getrlimit, posix_getsid,posix_getuid,posix_isatty, posix_kill,posix_mkfifo,posix_setegid,posix_seteuid,posix_setgid, posix_setpgid,posix_setsid,posix_setuid,posix_strerror,posix_times,posix_ttyname,posix_uname”

##列出PHP可以禁用的函數,如果某些程式需要用到這個函數,可以刪除,以取消禁用

找到“;date.timezone =”;修改為“date.timezone = PRC”

找到“expose_php = On”;修改為“expose_php = OFF ” ##禁止顯示php版本的資訊
找到“display_errors = On”;修改為“display_errors = OFF“##關閉錯誤提示

配置apache支援php

vi /usr/local/apache2/conf/httpd.conf

##編輯apache設定檔

在LoadModule php5_module        modules/libphp5.so這一行下面添加、
AddType application/x-httpd-php .php  (注意:php .php這個點前面有一個空格)
service httpd restart    #重啟apache

PS:配置完後需重新載入apache

/usr/local/apache/bin/apache graceful#如配置過全域環境變數,可直接apache graceful

驗證配置結果

#在apache根目錄下放置如下php檔案,開啟瀏覽器輸入:ip/index.php可看到php的一系列資訊cat index.php<?phpphpinfo();?>

650) this.width=650;" src="http://s3.51cto.com/wyfs02/M02/48/12/wKioL1QFjCqTT9GYAAR_TnI5Uwk479.jpg" title="F90751BA-E799-468A-BDB1-FB4A6611F62D.png" alt="wKioL1QFjCqTT9GYAAR_TnI5Uwk479.jpg" />

結論:本片博文旨在個人總結、記錄之用,屬***作,雖然參考了網上很多其它人的優秀博文,但仍有很多不足之處,希望對有緣的讀者有所協助,後續會補充。



本文出自 “有容乃大” 部落格,請務必保留此出處http://yumao.blog.51cto.com/9298275/1547950

centos 6.2系統下編譯安裝lamp環境

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.