說明:php
操做系統:CentOS 6.5 64位html
需求:mysql
編譯安裝LAMP運行環境linux
各軟件版本以下:c++
MySQL:mysql-5.1.73web
Apache:httpd-2.2.31sql
PHP:php-5.2.17shell
具體操做:數據庫
準備篇apache
1、配置防火牆,開啓80端口、3306端口
vi /etc/sysconfig/iptables #編輯防火牆配置文件
# Firewall configuration written by system-config-firewall
# Manual customization of this file is not recommended.
*filter
:INPUT ACCEPT [0:0]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [0:0]
-A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
-A INPUT -p icmp -j ACCEPT
-A INPUT -i lo -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 22 -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 3306 -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT
-A INPUT -j REJECT --reject-with icmp-host-prohibited
-A FORWARD -j REJECT --reject-with icmp-host-prohibited
COMMIT
:wq! #保存退出
service iptables restart #最後重啓防火牆使配置生效
2、關閉SELINUX
vi /etc/selinux/config
#SELINUX=enforcing #註釋掉
#SELINUXTYPE=targeted #註釋掉
SELINUX=disabled #增長
:wq! #保存退出
setenforce 0 #使配置當即生效
三 、系統約定
軟件源代碼包存放位置:/usr/local/src
源碼包編譯安裝位置:/usr/local/軟件名字
4、下載軟件包
一、下載Apache
http://www.apache.org/dist/httpd/httpd-2.2.31.tar.gz
二、下載MySQL
http://mirrors.sohu.com/mysql/MySQL-5.1/mysql-5.1.73.tar.gz
三、下載php
http://museum.php.net/php5/php-5.2.17.tar.gz
四、下載libmcrypt(php擴展)
http://nchc.dl.sourceforge.net/project/mcrypt/Libmcrypt/2.5.8/libmcrypt-2.5.8.tar.gz
五、下載yasm(php擴展)
http://www.tortall.net/projects/yasm/releases/yasm-1.3.0.tar.gz
六、t1lib(php擴展)
ftp://sunsite.unc.edu/pub/Linux/libs/graphics/t1lib-5.1.2.tar.gz
七、下載gd庫安裝包
https://bitbucket.org/libgd/gd-libgd/downloads/libgd-2.1.0.tar.gz
八、libvpx(gd庫須要)
https://webm.googlecode.com/files/libvpx-v1.3.0.tar.bz2
九、tiff(gd庫須要)
http://download.osgeo.org/libtiff/tiff-4.0.3.tar.gz
十、libpng(gd庫須要)
ftp://ftp.simplesystems.org/pub/png/src/libpng16/libpng-1.6.18.tar.gz
十一、freetype(gd庫須要)
http://ring.u-toyama.ac.jp/archives/graphics/freetype/freetype2/freetype-2.5.4.tar.gz
十二、jpegsrc(gd庫須要)
http://www.ijg.org/files/jpegsrc.v9a.tar.gz
1三、curl(php擴展)
http://curl.haxx.se/download/curl-7.44.0.tar.gz
以上軟件包上傳到/usr/local/src目錄
5、安裝編譯工具及庫文件(使用yum命令安裝)
yum install -y apr* autoconf automake bison bzip2 bzip2* cloog-ppl compat* cpp curl curl-devel fontconfig fontconfig-devel freetype freetype* freetype-devel gcc gcc-c++ gtk+-devel gd gettext gettext-devel glibc kernel kernel-headers keyutils keyutils-libs-devel krb5-devel libcom_err-devel libpng libpng* libpng-devel libjpeg* libsepol-devel libselinux-devel libstdc++-devel libtool* libgomp libxml2 libxml2-devel libXpm* libX* libtiff libtiff* make mpfr ncurses* ntp openssl nasm nasm* openssl-devel patch pcre-devel perl php-common php-gd policycoreutils ppl telnet t1lib t1lib* wget zlib-devel
安裝篇
1、安裝MySQL
cd /usr/local/src
tar zxvf mysql-5.1.73.tar.gz
cd mysql-5.1.73
./configure --prefix=/usr/local/mysql --localstatedir=/usr/local/mysql/data/ --with-mysqld-ldflags=-all-static --with-client-ldflags=-all-static --with-unix-socket-path=/tmp/mysql.sock --without-debug --with-extra-charsets=all --without-embedded-server --enable-profiling --enable-assembler --enable-thread-safe-client --enable-shared --with-server-suffix=-community --with-plugins=innobase --with-extra-charsets=all
make
make install
注意:在執行make install編譯的過程當中,若是你看到屏幕上出現下面這一行,卡在那裏,好久都過不去,千萬別覺得是編譯錯誤了,或者服務器卡住了,只須要堅持,耐心的等待幾分鐘,就會編譯成功!
make[4]: Entering directory `/usr/local/src/mysql-5.1.73/mysql-test'
groupadd mysql #添加mysql組
useradd -g mysql mysql -s /bin/false #建立用戶mysql並加入到mysql組,不容許mysql用戶直接登陸系統
chown -R root /usr/local/mysql/ #容許root訪問
chgrp -R mysql /usr/local/mysql/ #容許mysql組訪問
cd /usr/local/mysql/ #進入mysql安裝目錄
cp share/mysql/my-huge.cnf /etc/my.cnf #拷貝配置文件(注意:/etc目錄下面默認有my.cnf,直接覆蓋便可)
cp share/mysql/mysql.server /etc/init.d/mysqld #把Mysql加入系統啓動
chmod 755 /etc/init.d/mysqld #執行權限
vi /etc/profile #把mysql服務加入系統環境變量:
在最後添加下面這一行
export PATH=$PATH:/usr/local/mysql/bin
source /etc/profile #使配置馬上生效
下面這兩行把myslq的庫文件連接到系統默認的位置,在編譯相似PHP等軟件時能夠不用指定mysql的庫文件地址。
ln -s /usr/local/mysql/lib/mysql /usr/lib/mysql
ln -s /usr/local/mysql/include/mysql /usr/include/mysql
/usr/local/mysql/bin/mysql_install_db --user=mysql --datadir=/usr/local/mysql/data #生成mysql系統數據庫
/usr/local/mysql/bin/mysqld_safe --user=mysql & --datadir=/usr/local/mysql/data #啓動mysql
/etc/rc.d/init.d/mysqld start #啓動
chkconfig mysqld on #加入開機啓動
mysql_secure_installation #設置Mysql密碼
根據提示按Y 回車輸入2次密碼
或者直接修改密碼/usr/local/mysql/bin/mysqladmin -u root -p password "123456" #修改密碼
service mysqld restart #重啓
到此,mysql安裝完成!
2、安裝Apache
cd /usr/local/src
tar zxvf httpd-2.2.31.tar.gz
cd httpd-2.2.31
./configure --prefix=/usr/local/apache --with-included-apr --enable-module=so --enable-deflate --enable-expires --enable-ssl --enable-headers --enable-module=rewrite --enable-static-support --enable-mods-shared=all
make #編譯
make install #安裝
/usr/local/apache/bin/apachectl -k start #啓動
vi /usr/local/apache/conf/httpd.conf #編輯配置文件
找到:#ServerName www.example.com:80
修改成:ServerName www.osyunwei.com:80
找到:DirectoryIndex index.html
修改成:DirectoryIndex index.html index.php
找到:Options Indexes FollowSymLinks
修改成:Options FollowSymLinks #不顯示目錄結構
找到AllowOverride None
修改成:AllowOverride All #開啓apache支持僞靜態,有三處都作修改
LoadModule rewrite_module modules/mod_rewrite.so #取消前面的註釋,開啓apache支持僞靜態
vi /etc/profile #添加apache服務系統環境變量,在最後添加下面這一行
export PATH=$PATH:/usr/local/apache/bin
:wq! #保存退出
cp /usr/local/apache/bin/apachectl /etc/rc.d/init.d/httpd #把apache加入到系統啓動
vi /etc/init.d/httpd #編輯文件,在#!/bin/sh下面添加如下兩行
#chkconfig:2345 10 90
#description:Activates/Deactivates Apache Web Server
:wq! #保存退出
chown daemon.daemon -R /usr/local/apache/htdocs #更改目錄全部者
chmod 700 /usr/local/apache/htdocs -R #更改apache網站目錄權限
chkconfig httpd on #設置開機啓動
/etc/init.d/httpd start
service httpd restart
系統運維 www.osyunwei.com 舒適提醒:系統運維原創內容©版權全部,轉載請註明出處及原文連接
3、安裝PHP
一、安裝yasm
cd /usr/local/src
tar zxvf yasm-1.3.0.tar.gz
cd yasm-1.3.0
./configure
make
make install
二、安裝libmcrypt
cd /usr/local/src
tar zxvf libmcrypt-2.5.8.tar.gz
cd libmcrypt-2.5.8
./configure
make
make install
三、安裝libvpx
cd /usr/local/src
tar xvf libvpx-v1.3.0.tar.bz2
cd libvpx-v1.3.0
./configure --prefix=/usr/local/libvpx --enable-shared --enable-vp9
make
make install
四、安裝tiff
cd /usr/local/src
tar zxvf tiff-4.0.3.tar.gz
cd tiff-4.0.3
./configure --prefix=/usr/local/tiff --enable-shared
make
make install
五、安裝libpng
cd /usr/local/src
tar zxvf libpng-1.6.18.tar.gz
cd libpng-1.6.18
./configure --prefix=/usr/local/libpng --enable-shared
make
make install
六、安裝freetype
cd /usr/local/src
tar zxvf freetype-2.5.4.tar.gz
cd freetype-2.5.4
./configure --prefix=/usr/local/freetype --enable-shared
make #編譯
make install #安裝
七、安裝jpeg
cd /usr/local/src
tar zxvf jpegsrc.v9a.tar.gz
cd jpeg-9a
./configure --prefix=/usr/local/jpeg --enable-shared
make #編譯
make install #安裝
八、安裝libgd
cd /usr/local/src
tar zxvf libgd-2.1.0.tar.gz #解壓
cd libgd-2.1.0 #進入目錄
./configure --prefix=/usr/local/libgd --enable-shared --with-jpeg=/usr/local/jpeg --with-png=/usr/local/libpng --with-freetype=/usr/local/freetype --with-fontconfig=/usr/local/freetype --with-xpm=/usr/ --with-tiff=/usr/local/tiff --with-vpx=/usr/local/libvpx #配置
make #編譯
make install #安裝
九、安裝t1lib
cd /usr/local/src
tar zxvf t1lib-5.1.2.tar.gz
cd t1lib-5.1.2
./configure --prefix=/usr/local/t1lib --enable-shared
make without_doc
make install
十、安裝curl
cd /usr/local/src
tar zxvf curl-7.44.0.tar.gz
cd curl-7.44.0
./configure --prefix=/usr/local/curl --with-gssapi --enable-tls-srp --with-libmetalink
make
make install
十一、安裝php
注意:若是系統是64位,請執行如下兩條命令,不然安裝php會出錯(32位系統不須要執行)
\cp -frp /usr/lib64/libltdl.so* /usr/lib/
\cp -frp /usr/lib64/libXpm.so* /usr/lib/
cd /usr/local/src
tar -zvxf php-5.2.17.tar.gz
cd php-5.2.17
export LD_LIBRARY_PATH=/usr/local/libgd/lib
./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --with-apxs2=/usr/local/apache/bin/apxs --with-mysql=/usr/local/mysql --with-mysqli=/usr/local/mysql/bin/mysql_config --with-mysql-sock=/tmp/mysql.sock --with-pdo-mysql=/usr/local/mysql --with-gd --with-png-dir=/usr/local/libpng --with-jpeg-dir=/usr/local/jpeg --with-freetype-dir=/usr/local/freetype --with-xpm-dir=/usr/ --with-vpx-dir=/usr/local/libvpx/ --with-zlib-dir=/usr/local/zlib --with-t1lib=/usr/local/t1lib --with-curl=/usr/local/curl --with-iconv --enable-libxml --enable-xml --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --enable-mbregex --enable-mbstring --enable-ftp --enable-gd-native-ttf --with-openssl --enable-pcntl --enable-sockets --with-xmlrpc --enable-zip --enable-soap --without-pear --with-gettext --enable-session --with-mcrypt --enable-ctype
make #編譯
make install #安裝
cp php.ini-production /usr/local/php/etc/php.ini #複製php配置文件到安裝目錄
rm -rf /etc/php.ini #刪除系統自帶配置文件
ln -s /usr/local/php/etc/php.ini /etc/php.ini #添加軟連接到 /etc目錄
vi /usr/local/php/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 #關閉錯誤提示
:wq! #保存退出
4、配置apache支持php
vi /usr/local/apache/conf/httpd.conf #編輯apache配置文件,在AddType application/x-gzip .gz .tgz這一行下面添加
AddType application/x-httpd-php .php (注意:php .php這個點前面有一個空格)
:wq! #保存退出
service httpd restart #重啓apache
service mysqld restart #重啓mysql
5、測試
cd /usr/local/apache/htdocs
vi index.php #輸入下面內容
<?php
phpinfo();
?>
:wq! #保存
在客戶端瀏覽器輸入服務器IP地址,能夠看到相關的配置信息!
網站程序上傳到/usr/local/apache/htdocs目錄裏面,若是安裝有問題,請檢查目錄權限,確保目錄爲如下權限
chown daemon.daemon -R /usr/local/apache/htdocs
chmod -R 700 /usr/local/apache/htdocs
至此,Linux下指定版本編譯安裝LAMP教程完成!