天天看點

LAMP的基本搭建--同一台機器上

1 mysql二進制安裝

1 準備二進制包

 mysql-5.6.21-linux-glibc2.5-x86_64.tar.gz

cd /usr/local/src

tar xf  mysql-5.6.21-linux-glibc2.5-x86_64.tar.gz

cd /usr/local/

ln -sv src/mysql-5.6.21-linux-glibc2.5-x86_64 mysql  

groupadd -r -g 306 mysql

useradd -g 306 -r -s /sbin/nologin  -u 306 mysql

mkdir -pv /data/mysql

chown -R mysql.mysql /data/mysql/

mkdir -pv /data/owbinlogbackup /data/mysql-tmpdir

chown -R mysql.mysql /data/owbinlogbackup/ /data/mysql-tmpdir/

cd /usr/local/mysql  && ./scripts/mysql_install_db --user=mysql --datadir=/data/mysql

cp support-files/my-default.cnf /etc/my.cnf  (用上線的配置檔案替換)

cp support-files/mysql.server /etc/init.d/mysqld

chmod 755 /etc/init.d/mysqld 

vim /etc/init.d/mysqld   #修改basedir=/usr/local/mysql 和datadir=/data/mysq

chkconfig --add mysqld

chkconfig mysqld on

/etc/init.d/mysqld start

将mysql 用戶端指令加入環境變量

vim /etc/profile.d/mysql.sh

export PATH=$PATH:/usr/local/mysql/bin

source /etc/profile

設定root 密碼

 mysqladmin -uroot password 'c110123'

測試成功sql常用的語句:

登入:myql -uroot -p

檢視:show processlist;

show status;

show databases;

退出:quit

\! ls 執行shell指令

2 安裝apache--httpd

準備好httpd的源碼包:httpd-2.2.27.tar.gz

安裝步驟:

tar -xf httpd-2.2.27.tar.gz

cd httpd-2.2.27

檢視INSTALL文檔

./configure --prefix=/usr/local/apache --with-included-apr  --enable-deflate=shared  --enable-expires=shared  --enable-rewrite=shared  --with-pcre 

make && make install

echo $?

常用指令:

/usr/local/apache/bin/apachectl -t 配置檔案檢查

/usr/local/apache/bin/apachectl start  啟動

/usr/local/apache/bin/apachectl graceful 平緩啟動

出現如下資訊,基本無影響,可以修改vim /usr/local/apache/conf/httpd.conf  

#

測試:

ps -ef |grep httpd

curl -I localhost

頁面路徑預設在

/usr/local/apache/htdocs

通路成功的預設頁面:

3 安裝php

準備包php-5.3.27.tar.gz

tar -xvf php-5.3.27.tar.gz

cd php-5.3.27

./configure   --prefix=/usr/local/php   --with-apxs2=/usr/local/apache/bin/apxs   --with-config-file-path=/usr/local/php/etc   --with-mysql=/usr/local/mysql   --with-libxml-dir   --with-gd   --with-jpeg-dir   --with-png-dir   --with-freetype-dir   --with-iconv-dir   --with-zlib-dir   --with-bz2   --with-openssl   --with-mcrypt   --enable-soap   --enable-gd-native-ttf   --enable-mbstring   --enable-sockets   --enable-exif  --disable-ipv6  

或者:

./configure   --prefix=/usr/local/php   --with-apxs2=/usr/local/apache/bin/apxs   --with-config-file-path=/usr/local/php/etc   --with-mysql=/usr/local/mysql   --with-libxml-dir   --with-gd   --with-jpeg-dir   --with-png-dir   --with-freetype-dir   --with-iconv-dir   --with-zlib-dir   --with-bz2   --with-openssl   --with-mcrypt   --enable-soap   --enable-gd-native-ttf   --enable-mbstring   --enable-sockets   --enable-exif  --disable-ipv6  --enable-bcmath --with-mysqli --with-gettext

make && make install 

如果安裝mysql和zabbix-server web 獨立開倆的則紅色标記的選項要安裝不然安裝zabbix-web的時候會報錯

報錯:

configure: error: mcrypt.h not found. Please reinstall libmcrypt.

解決方法:

libmcrypt-2.5.8.tar

mcrypt-2.6.8.tar.gz

編譯安裝mcrypt

configure: error: *** libmcrypt was not found

/usr/local/lib/libmcrypt

編輯:

include ld.so.conf.d/*.conf

然後執行:

ldconfig 

php編譯成功的顯示:

4 . apache支援php配置

vim /usr/local/apache/conf/httpd.conf 

增加 AddType application/x-httpd-php .php  

AddType application/x-httpd-php-source .phps

DirectoryIndex index.html  改為 DirectoryIndex index.html  index.php

/usr/local/apache/bin/apachectl -t  檢視配置檔案是否有誤

/usr/local/apache/bin/apachectl start  啟動httpd服務

/usr/local/php/bin/php 1.php   一定可以解析

 #拷貝php配置檔案,把樣闆檔案拷貝到php安裝路徑etc下

 cp php.ini-production /usr/local/php/etc/php.ini

編輯測試頁:vim /usr/local/apache2/htdocs/1.php 

測試: curl localhost/1.php 

vim 1.php

<?php

echo "this is my php web";

?>

vim phpinfo.php

phpinfo();

5 . 測試php連接配接mysql

vim test_conn_mysql.php

     $conn=mysql_connect('localhost','root','PSAAWORD');

     if ($conn)

            echo "connect mysql Success.......";

      else

            echo "Failure.......";

結果:

6. LAMP中的幾個常用的技巧

檢視版本環境,檢視編譯參數 檢視加載子產品

檢視apache編譯參數 cat /usr/local/apache2/build/config.nice

注意:檢視nginx的編譯參數/usr/local/nginx/bin/nginx -V

檢視apache加載的子產品 apachectl -M 

檢視apache的版本和環境,工作模式 apachectl -V

測試apache配置檔案是否正确  apachectl -t

更改配置檔案後,重新加載apache  apachectl graceful 

檢視mysql編譯參數  cat /usr/local/mysql/bin/mysqlbug|grep configure 

檢視php編譯參數 php -i |head

檢視php加載子產品 php –m

檢視php的版本和環境 /usr/local/php/bin/php -v

檢視php.ini在哪裡  php -i |grep 'Configuration File‘

檢視extension_dir路徑 /usr/local/php/bin/php -i |grep 'extension_dir'

動态子產品放在 /usr/local/apache2/modules/目錄下面

檢視apache的工作模式:

  prefork.c

本文轉自殘劍部落格51CTO部落格,原文連結http://blog.51cto.com/cuidehua/1761479如需轉載請自行聯系原作者

cuizhiliang