LAMP是一個縮寫Linux+Apache+MySql+PHP,它指一組一般一塊兒使用來運行動態網站或者服務器的自由軟件:php
* Linux,操做系統;
* Apache,網頁服務器;
* MySQL,數據庫管理系統(或者數據庫服務器);
* PHP 和有時 Perl 或 Python,腳本語言。mysql
今天介紹一下Linux下LAMP(Apache+PHP+MySql)環境配置:linux
一、下載軟件web
MySql:wget http://down1.chinaunix.net/distfiles/mysql-5.0.56.tar.gzsql
http://dev.mysql.com/get/Downloads/MySQL-5.5/mysql-5.6.23.tar.gzshell
Apache:wget http://apache.freelamp.com/httpd/httpd-2.2.13.tar.gz數據庫
PHP:wget http://125.39.113.23:9203/CDE349DEF7D7A6AC19DE5771F752CA258C693F634815D4BE/cn.php.net/distributions/php-5.2.10.tar.bz2apache
http://php.net/downloads.php瀏覽器
二、安裝MySql服務器
安裝步驟:
5.6的編譯,要用cmake編譯
cmake \ -DCMAKE_INSTALL_PREFIX=/usr/local/install/mysql \ -DMYSQL_DATADIR=/var/mysql_data \ -DSYSCONFDIR=/etc \ -DWITH_MYISAM_STORAGE_ENGINE=1 \ -DWITH_INNOBASE_STORAGE_ENGINE=1 \ -DWITH_MEMORY_STORAGE_ENGINE=1 \
-DWITH_MRG_MYISAM_STORAGE_ENGINE=1 \ -DWITH_READLINE=1 \ -DMYSQL_UNIX_ADDR=/var/lib/mysql/mysql.sock \ -DMYSQL_TCP_PORT=3306 \ -DENABLED_LOCAL_INFILE=1 \ -DWITH_PARTITION_STORAGE_ENGINE=1 \ -DEXTRA_CHARSETS=all \ -DDEFAULT_CHARSET=utf8 \ -DDEFAULT_COLLATION=utf8_general_ci
安裝 ncurses-devel
shell> groupadd mysql
shell> useradd -g mysql mysql
shell> gunzip < mysql-VERSION.tar.gz | tar -xvf – 或 tar -zxvf mysql-5.0.56.tar.gz(解壓mysql源碼包)
shell> cd mysql-VERSION(進入mysql源碼文件夾)
shell> ./configure –prefix=/usr/local/mysql
shell> make
shell> make install
shell> cp support-files/my-medium.cnf /etc/my.cnf
shell> cd /usr/local/mysql
shell> scripts/mysql_install_db –user=mysql
shell> chown -R root .
shell> chown -R mysql var
shell> chgrp -R mysql .
shell> bin/mysqld_safe –user=mysql &
修改mysql root 密碼
$ mysqladmin -u root password newpass
添加服務項
cp /usr/local/mysql/share/mysql/mysql.server /etc/init.d/mysqld
chmod 755 /etc/init.d/mysqld
chkconfig –add mysqld
三、安裝Apache
tar zvxf httpd-2.2.13.tar.gz
cd httpd-2.2.13
修改src/include/httpd.h 增大最大線程數
#define HARD_SERVER_LIMIT 256
改爲
#define HARD_SERVER_LIMIT 2560
保存退出編譯apache
./configure –prefix=/usr/local/apache –enable-module=so –enable-module=rewrite –enable-shared=max –htdocsdir=/var/www &&
make
make install
#這裏咱們經過enable-module參數告訴設置腳本,咱們須要啓動so和rewrite模塊,so模塊是用來提DSO支持的apache核 心模塊,而rewrite模塊則是用意實現地址重寫的模塊,因爲rewrite模塊須要DBM支持,若是在初次安裝時沒有編譯進apache,之後須要用 到時須要從新編譯整個apache才能夠實現。爲此除非你能夠肯定之後不會用到rewrite模塊,不然仍是建議你在第一次編譯的時候把rewrite模 塊編譯好。
enable-shared=max 這個參數的做用時編譯apache時,把除了so之外的全部apache的標準模塊都編譯成DSO模塊。而不是編譯進apache核心內。
好了安裝apache很簡單的哦,啓動apache看看
/usr/local/apache/bin/apachectl start
而後 經過瀏覽器查看http://youhost/,若是正常則說明安裝成功。
apache設爲linux服務
cp /usr/local/apache2/bin/apachectl /etc/init.d/httpd
vi /etc/init.d/httpd
在在#!/bin/sh後面加入下面兩行
#chkconfig:345 85 15
#description: Start and stops the Apache HTTP Server.
而後
chmod +x /etc/rc.d/init.d/httpd
chkconfig –add httpd
四、安裝PHP
(1)tar zvxf php-5.2.10.tar.bz2
(2)cd php-5.2.10
(3)
./configure --prefix=/usr/local/php --with-config-file-path=/etc --with-mysql=/usr/local/mysql --with-mysqli=/usr/local/mysql/bin/mysql_config --with-pdo-mysql=/usr/local/mysql --with-iconv-dir=/usr/local --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir=/usr/bin --enable-xml --disable-rpath --enable-discard-path --enable-safe-mode --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --with-curl --with-curlwrappers --enable-mbregex --enable-fastcgi --enable-fpm --enable-force-cgi-redirect --enable-mbstring --with-mcrypt --with-gd --enable-gd-native-ttf --with-openssl --with-mhash --enable-pcntl --enable-sockets --with-ldap --with-ldap-sasl --with-apxs2=/usr/local/apache2/bin/apxs
(4)make
(5)make install
最後一步從新啓動apache報以下錯誤:
httpd: Syntax error on line 53 of /usr/local/apache/conf/httpd.conf: Cannot load /usr/local/apache/modules/libphp5.so into server: /usr/local/apache/modules/libphp5.so: cannot restore segment prot after reloc: Permission denied
緣由:是Linux有一個SELinux保護模式引發的。
解決辦法:
1關閉SELINUX的方法:
vi /etc/selinux/config 將SELINUX=enforcing 改爲SELINUX=disabled 須要重啓
這個方法可能會對服務器帶來風險。
# service httpd restart
# setenforce 1
vi /usr/local/apache/conf/httpd.conf
查找
在此範圍添加
AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps
然CPOPY PHP的配置文件
cp ../php-5.2.10/php.ini.dist /usr/local/php/lib/php.ini
修改php.ini文件
register_globals = On
ok!從新啓動一下apache服務器
/usr/local/apache/bin/apachectl restart
而後寫個php測試頁info.php:內容以下
<?php
phpinfo();
?>
正常的話,應該能看到php的信息了,恭喜你的Apche+Mysql+PHP安裝成功。