linux下LAMP環境搭建

操作系統 : [CentOS7.0]
服務器     : [httpd-2.4.17]
PHP           : [php-5.5.19]
數據庫       : [mysql-5.5.41]
++++++++++++++++++++++++++++++++++++++++++++++
1>【卸載系統自帶的apache】
[html] view plaincopy
  1. #查看apache是否己安裝  
  2. rpm -qa httpd  
  3. #卸載  
  4. rpm -e httpd --nodeps  
2>【安裝gcc, gcc-c++】
[html] view plaincopy
  1. yum install gcc  
  2. yum install gcc-c++  
3>【開放80、3306、22端口】
[html] view plaincopy
  1. #關閉防火牆  
  2. service iptables stop  
  3. vi /etc/sysconfig/iptables  
  4. #添加  
  5. -A INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT  
  6. -A INPUT -m state --state NEW -m tcp -p tcp --dport 3306 -j ACCEPT  
  7. -A INPUT -m state --state NEW -m tcp -p tcp --dport 22 -j ACCEPT  
  8. #重啓防火牆  
  9. service iptables restart  
4>【安裝libxml2】
[html] view plaincopy
  1. tar -zxvf libxml2-2.6.30.tar.gz  
  2. cd libxml2-2.6.30  
  3. ./configure --prefix=/usr/local/libxml2/  
  4. make   
  5. make install  
5>【安裝libmcrypt】
[html] view plaincopy
  1. tar -zxvf libmcrypt-2.5.8.tar.gz  
  2. cd libmcrypt-2.5.8  
  3. ./configure --enable-ltdl-install  
  4. make  
  5. make install  
6>【安裝zlib】
[html] view plaincopy
  1. tar -zxvf zlib-1.2.3.tar.gz  
  2. cd zlib-1.2.3  
  3. ./configure  
  4. make  
  5. make install  
7>【安裝libpng】
[html] view plaincopy
  1. tar -zxvf libpng-1.2.31.tar.gz  
  2. cd libpng-1.2.31  
  3. ./configure --prefix=/usr/local/libpng/  
  4. make  
  5. make install  
8>【安裝libtool】
9>【安裝jpegsrc.v6b】
[html] view plaincopy
  1. mkdir /usr/local/jpeg6  
  2. mkdir /usr/local/jpeg6/bin  
  3. mkdir /usr/local/jpeg6/lib  
  4. mkdir /usr/local/jpeg6/include  
  5. mkdir -p /usr/local/jpeg6/man/man1  
  6.   
  7. tar -zxvf jpegsrc.v6b.tar.gz  
  8. cd jpeg-6b  
  9. ./configure --prefix=/usr/local/jpeg6/ --enable-shared --enable-static  
  10. make  
  11. make install  
10>【安裝freetype】
[html] view plaincopy
  1. tar -zxvf freetype-2.3.5.tar.gz  
  2. cd freetype-2.3.5  
  3. ./configure --prefix=/usr/local/freetype/  
  4. make  
  5. make install  
11>【安裝autoconf】
[html] view plaincopy
  1. tar -zxvf autoconf-2.61.tar.gz  
  2. cd autoconf-2.61  
  3. ./configure  
  4. make  
  5. make install  
12>【安裝gd】
[html] view plaincopy
  1. tar -zxvf gd-2.0.35.tar.gz  
  2. cd gd-2.0.35  
  3. ./configure --prefix=/usr/local/gd2/ --with-jpeg=/usr/local/jpeg6/ --with-freetype=/usr/local/freetype/  
  4. make  
  5. make install  

13>【安裝apache】

[html] view plaincopy
  1. tar -zxvf httpd-2.4.17.tar.gz  
  2. cd httpd-2.4.17  
  3. ./configure --prefix=/usr/local/apache2/ --sysconfdir=/etc/httpd/ --with-included-apr --disable-userdir --enable-so --enable-deflate=shared --enable-expires=shared --enable-rewrite=shared --enable-static-support  
  4. make  
  5. make install  
  6. #啓動apache  
  7. /usr/local/apache2/bin/apachectl start  
  8. #如果出現下面的錯誤,  
  9. #httpd: Could not reliably determine the server's fully qualified domain name, using ::1 for ServerName  
  10. #修改配置文件  
  11. vi /etc/httpd/httpd.conf  
  12. #查找ServerName,將註釋去掉  
  13. ServerName www.example.com:80  
  14. #添加到自啓動  
  15. echo "/usr/local/apache2/bin/apachectl start" >> /etc/rc.d/rc.sysinit  
  16. #將apache添加到系統服務中  
  17. cp /usr/local/apache2/bin/apachectl /etc/init.d/httpd  
  18. vi /etc/rc.d/init.d/httpd  
  19. #在#!/bin/sh後添加下面兩行(包含"#")  
  20. # chkconfig:2345 85 15  
  21. # description:Apache  
  22. #添加執行權限  
  23. chmod 755 /etc/init.d/httpd  
  24. #添加到系統服務中  
  25. chkconfig --add httpd  
  26. #開啓apache  
  27. service httpd start  

14>【安裝ncurses】
[html] view plaincopy
  1. tar -zxvf ncurses-5.6.tar.gz  
  2. cd ncurses-5.6  
  3. ./configure --with-shared --without-debug --without-ada --enable-overwrite  
  4. make  
  5. make install  
15>【安裝mysql】
[html] view plaincopy
  1. groupadd mysql  
  2. useradd -g mysql mysql  
  3. tar -zxvf mysql-5.5.41.tar.gz  
  4. cd mysql-5.5.41  
  5. # 創建安裝目錄
    mkdir  /usr/local/ mysql
    # 創建數據庫目錄
    mkdir  /usr/local/ mysql/data  
  6. # cmake編譯: 
    cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql \
    -DMYSQL_DATADIR=/usr/local/mysql/data \
    -DDEFAULT_CHARSET=utf8 \
    -DDEFAULT_COLLATION=utf8_unicode_ci \
    -DWITH_READLINE=1 \
    -DWITH_SSL=system \
    -DWITH_EMBEDDED_SERVER=1 \
    -DENABLED_LOCAL_INFILE=1 \
    -DDEFAULT_COLLATION=utf8_general_ci \
    -DWITH_MYISAM_STORAGE_ENGINE=1 \
    -DWITH_INNOBASE_STORAGE_ENGINE=1 \
    -DWITH_DEBUG=0
  7. make  
  8. make install  

[html] view plaincopy
  1. cp support-files/my-medium.cnf /etc/my.cnf  
  2. /usr/local/mysql/bin/mysql_install_db --user=mysql  
  3. chown -R root /usr/local/mysql  
  4. chown -R mysql /usr/local/mysql/var  
  5. chgrp -R mysql /usr/local/mysql  
  6.   
  7. /usr/local/mysql/bin/mysqld_safe  --user=mysql &  
  8. cp /lamp/src/mysql-5.1.59/support-files/mysql.server /etc/rc.d/init.d/mysqld  
  9. chown root.root /etc/rc.d/init.d/mysqld  
  10. chmod 755 /etc/rc.d/init.d/mysqld  
  11. chkconfig --add mysqld  
  12. chkconfig --list mysqld  
  13. chkconfig --levels 245 mysqld off  

[html] view plaincopy
  1. #配置mysql  
  2. cd /usr/local/mysql  
  3. bin/mysqladmin version //簡單的測試  
  4. bin/mysqladmin Variables //查看所有mysql參數  
  5. bin/mysql -uroot //沒有密碼可以直接登錄本機服務器  
  6. DELETE FROM mysql.user WHERE Host='localhost' AND User='';  
  7. FLUSH PRIVILEGES;  
  8. #設置root密碼爲123456  
  9. SET PASSWORD FOR 'root'@'localhost' = PASSWORD('123456');  
  10. #配置可遠程連接mysql  
  11. use mysql  
  12. SELECT user,password,host FROM user;  
  13. DELETE FROM user WHERE host='localhsot.localdomain'  
  14. DELETE FROM user WHERE host='127.0.0.1';  
  15. UPDATE user SET host='%' WHERE user='root';  
  16. #重啓mysql  
  17. service mysqld restart  
16>【安裝php】
[html] view plaincopy
  1. tar -zxvf php-5.5.19.tar.gz  
  2. cd php-5.5.19  
  3. ./configure --prefix=/usr/local/php/ --with-config-file-path=/usr/local/php/etc/ --with-apxs2=/usr/local/apache2/bin/apxs --with-mysql=/usr/local/mysql/ --with-libxml-dir=/usr/local/libxml2/ --with-jpeg-dir=/usr/local/jpeg6/ --with-freetype-dir=/usr/local/freetype/ --with-gd=/usr/local/gd2/ --with-mcrypt=/usr/local/libmcrypt/ --with-mysqli=/usr/local/mysql/bin/mysql_config --enable-soap --enable-mbstring=all --enable-sockets  
  4. make  
  5. make install  
  6. cp php.ini-dist /usr/local/php/etc/php.ini  
17>【apache配置】
[html] view plaincopy
  1. #建立工作目錄  
  2. mkdir -p /var/www/html  
  3. #修改httpd.conf  
  4. vi /etc/httpd/httpd.conf  
  5. #功能: 設置工作目錄  
  6. #說明: 搜索DocumentRoot, 修改爲  
  7. DocumentRoot "/var/www/html"  
  8.   
  9. #功能: 設置目錄選項  
  10. #說明: 搜索<Directory "/usr/local/apache2//htdocs">, 修改爲  
  11. <Directory "/var/www/html">  
  12.   
  13. #功能: 設置默認文檔  
  14. #說明: 搜索<IfModule dir_module>, 修改爲  
  15. DirectoryIndex index.html index.php  
  16.   
  17. #功能: 增加php類型  
  18. #說明: 搜索 AddType application/x-gzip .gz .tgz在後面添加  
  19. AddType application/x-httpd-php .html .php  
  20.   
  21. 功能: 不允許訪問目錄  
  22. 說明: 搜索Options Indexes FollowSymLinks項並註釋  
  23. #Options Indexes FollowSymLinks  
  24.   
  25. #注意: 修改配置文件後, 重啓apache才能生效  
  26. #重啓apache  
  27. service httpd restart  
18>【添加PDO_MYSQL擴展】
[html] view plaincopy
  1. cd /lamp/src/php-5.2.6/ext/pdo_mysql  
  2. /usr/local/php/bin/phpize  
  3. ./configure --with-php-config=/usr/local/php/bin/php-config --with-pdo-mysql=/usr/local/mysql  
  4. make  
  5. make install  
[html] view plaincopy
  1. #執行完make install後會生成  
  2. #Installing shared extensions: /usr/local/php/lib/php/extensions/no-debug-non-zts-20060613/  
  3. #修改php.ini  
  4. vi /usr/local/php/etc/php.ini  
  5. #查找extension_dir,修改爲  
  6. extension_dir = "/usr/local/php/lib/php/extensions/no-debug-non-zts-20060613/"  
  7. #添加pdo_mysql  
  8. extension = pdo_mysql.so  
  9. #重啓apache  
  10. service httpd restart  
19>【apache虛擬主機配置】
[html] view plaincopy
  1. #建立dev目錄  
  2. mkdir -p /var/www/html/dev  
  3. cd /var/www/html/dev  
  4. vi index.php  
  5. #添加  
  6. <?php  
  7.     phpinfo();  
  8. ?>  
  9. #保存,退出  
  10. #打開httpd.conf  
  11. vi /etc/httpd/httpd.conf  
  12. #查找Include /etc/httpd//extra/httpd-vhosts.conf並取消註釋  
  13. Include /etc/httpd//extra/httpd-vhosts.conf  
  14. #打開httpd-vhosts.conf  
  15. vi /etc/httpd//extra/httpd-vhosts.conf  
  16. #將下面幾行註釋  
  17. #<VirtualHost *:80>  
  18. #    ServerAdmin [email protected]  
  19. #    DocumentRoot "/usr/local/apache2//docs/dummy-host.example.com"  
  20. #    ServerName dummy-host.example.com  
  21. #    ServerAlias www.dummy-host.example.com  
  22. #    ErrorLog "logs/dummy-host.example.com-error_log"  
  23. #    CustomLog "logs/dummy-host.example.com-access_log" common  
  24. #</VirtualHost>  
  25.   
  26.   
  27. #<VirtualHost *:80>  
  28. #    ServerAdmin [email protected]  
  29. #    DocumentRoot "/usr/local/apache2//docs/dummy-host2.example.com"  
  30. #    ServerName dummy-host2.example.com  
  31. #    ErrorLog "logs/dummy-host2.example.com-error_log"  
  32. #    CustomLog "logs/dummy-host2.example.com-access_log" common  
  33. #</VirtualHost>  
  34. #添加  
  35. <VirtualHost *:80>  
  36.         ServerName dev.dev  
  37.         DocumentRoot "/var/www/html/dev"  
  38.         <Directory "/var/www/html/dev/">  
  39.                 AllowOverride All  
  40.         </Directory>  
  41. </VirtualHost>  
  42. #保存, 退出  
  43. #重啓apache  
  44. service httpd restart  
  45. #修改hosts文件  
  46. vi /etc/hosts  
  47. #添加  
  48. 127.0.0.1       dev.dev localhost  
  49. #保存, 退出  
  50. #在瀏覽器輸入http://dev.dev訪問,查看能否輸出php信息  
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章