天天看點

DELL R420真機搭建LAMP環境

一直都是在虛拟機中做實驗,頭一次在真機安裝CentOS6.6 x86_64位系統,并安裝LAMP環境。提前安裝必備的軟體包,在安裝過程中未出現錯誤;可以使用一鍵安裝LAMP腳本執行。

DELL R420配置 E5-2403雙cpu,4核心8線程;

1

2

3

4

5

6

<code>[root@localhost ~]</code><code># grep "model name" /proc/cpuinfo |uniq</code>

<code>model name: Intel(R) Xeon(R) CPU E5-2403 v2 @ 1.80GHz</code>

<code>[root@localhost ~]</code><code># grep  -c "processor" /proc/cpuinfo</code>

<code>8</code>

<code>[root@localhost ~]</code><code># grep "core id" /proc/cpuinfo |sort |uniq|wc -l</code>

<code>4</code>

linux版本及核心版本

<code>[root@localhost ~]</code><code># cat /etc/issue</code>

<code>CentOS release 6.6 (Final)</code>

<code>Kernel \r on an \m</code>

<code>[root@localhost ~]</code><code># uname -r</code>

<code>2.6.32-504.el6.x86_64</code>

安裝LAMP環境之前需要安裝必備的包

<code>yum </code><code>install</code> <code>wget gcc gcc-c++ </code><code>make</code> <code>re2c curl curl-devel libxml2 libxml2-devel libjpeg libjpeg-devel libpng libpng-devel libmcrypt libmcrypt-devel zlib zlib-devel openssl openssl-devel freetype freetype-devel gd gd-devel perl perl-devel ncurses ncurses-devel bison bison-devel libtool gettext gettext-devel cmake </code><code>bzip2</code> <code>bzip2</code><code>-devel pcre pcre-devel</code>

軟體版本:

編譯安裝mysql 5.6.24

<code>#cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_DATADIR=/data/mysql -DMYSQL_UNIX_ADDR=/usr/local/mysql/mysql.sock -DSYSCONFDIR=/etc -DWITH_MYISAM_STORAGE_ENGINE=1 -DWITH_ARCHIVE_STORAGE_ENGINE=1 -DWITH_BLACKHOLE_STORAGE_ENGINE=1 -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_MEMORY_STORAGE_ENGINE=1 -DWITH_READLINE=1 -DMYSQL_TCP_PORT=3306 -DENABLED_LOCAL_INFILE=1 -DWITH_PARTITION_STORAGE_ENGINE=1 -DEXTRA_CHARSETS=all -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci</code>

<code># make &amp;&amp; make install </code>

<code># echo $?</code>

<code># 0</code>

建立mysql使用者,資料庫目錄,更改權限

<code># useradd -M -s /sbin/nologin mysql</code>

<code># mkdir -p /data/mysql </code>

<code># chown -R mysql:mysql /data/mysql/</code>

<code># chown -R mysql:mysql /usr/local/mysql/</code>

初始化資料庫

<code># cd /usr/local/mysql/scripts/ </code>

<code>#  ./mysql_install_db --basedir=/usr/local/mysql/ --datadir=/data/mysql/ --user=mysql</code>

拷貝配置檔案,修改my.cnf

<code>#  cp /usr/local/mysql/my.cnf /etc/my.cnf </code>

<code>#  vi /etc/my.cnf</code>

<code>[mysqld]</code>

<code>user=mysql </code>

<code>datadir=</code><code>/data/mysql</code>

<code>default-storage-engine=MyISAM</code>

拷貝啟動腳本

<code># cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld</code>

添加iptables規則,允許3306端口,并儲存防火牆設定。

<code># iptables -A INPUT -m state --state NEW -m tcp -p tcp --dport 3306 -j ACCEPT</code>

<code># /etc/init.d/iptables save</code>

啟動mysqld服務,并加入開機啟動;

<code># service mysqld start</code>

<code># chkconfig --add mysqld</code>

<code># chkconfig mysqld on</code>

設定環境變量,最後一行加入以下内容,儲存退出後,source生效;

<code># vi /etc/profile</code>

<code>PATH=$PATH:</code><code>/usr/local/mysql/bin</code>

<code>export</code> <code>PATH</code>

<code># source /etc/profile</code>

編輯mysqld啟動腳本,找到basedir和datadir添加路徑;

<code>#vi /etc/init.d/mysqld</code>

<code>basedir=</code><code>/usr/local/mysql</code>

編譯安裝apache2.4.12

Centos6 yum安裝的apr版本已經不适用httpd-2.4版本了。是以,需要源碼編譯安裝apr以及apr-util

<code>#cd /usr/local/src/</code>

<code>#wget http://mirrors.cnnic.cn/apache/apr/apr-1.5.2.tar.gz</code>

<code>#wget http://mirrors.cnnic.cn/apache/apr/apr-util-1.5.4.tar.gz</code>

編譯安裝apr

<a href="http://mirrors.cnnic.cn/apache/apr/apr-util-1.5.4.tar.gz" target="_blank"></a>

<code>[root@localhost src]</code><code># tar zxf apr-1.5.2.tar.gz </code>

<code>[root@localhost src]</code><code># cd apr-1.5.2</code>

<code>[root@localhost apr-1.5.2]</code><code># ./configure --prefix=/usr/local/apr</code>

<code>[root@localhost apr-1.5.2]</code><code># make &amp;&amp; make install</code>

<code>[root@localhost apr-1.5.2]</code><code># echo $?</code>

<code>0</code>

編譯安裝apr-util

<code>[root@localhost src]</code><code># tar zxf apr-util-1.5.4.tar.gz </code>

<code>[root@localhost src]</code><code># cd apr-util-1.5.4</code>

<code>[root@localhost apr-util-1.5.4]</code><code># ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr</code>

<code>[root@localhost apr-util-1.5.4]</code><code># make &amp;&amp; make install</code>

<code>[root@localhost apr-util-1.5.4]</code><code># echo $?</code>

檢查開發環境,沒有安裝的話使用yum安裝;

<code>[root@localhost ~]</code><code># rpm -qa gcc cmake pcre-devel libmcrypt</code>

<code>libmcrypt-2.5.8-9.el6.x86_64</code>

<code>gcc-4.4.7-11.el6.x86_64</code>

<code>cmake-2.8.12.2-4.el6.x86_64</code>

<code>pcre-devel-7.8-6.el6.x86_64</code>

編譯安裝apache

<code>[root@localhost src]</code><code># tar zxf httpd-2.4.12.tar.gz </code>

<code>[root@localhost src]</code><code># cd httpd-2.4.12</code>

<code>[root@localhost httpd-2.4.12]</code><code># ./configure --prefix=/usr/local/apache2 --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util/ --with-pcre --enable-mods-shared=most --enable-so</code>

<code>[root@localhost httpd-2.4.12]</code><code># echo $?</code>

apache執行指令目錄加入配置檔案,生效;

<code>[root@localhost ~]</code><code># vi /etc/profile</code>

<code>PATH=$PATH:</code><code>/usr/local/apache2/bin</code>

<code>[root@localhost ~]</code><code># . /etc/profile</code>

添加iptables規則,允許80端口,并儲存防火牆設定。

<code># iptables -A INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT</code>

編輯啟動腳本,更改權限,并加入系統服務,設定開機啟動;

<code>[root@localhost apache2]</code><code># vi /etc/init.d/httpd</code>

<code>[root@localhost apache2]</code><code># chmod 755 /etc/init.d/httpd</code>

<code>[root@localhost apache2]</code><code># chkconfig --add httpd</code>

<code>[root@localhost apache2]</code><code># chkconfig httpd on</code>

檢查apache配置參數;-l 列出加載的靜态子產品 -M列出所有加載的子產品;

<code>[root@localhost ~]</code><code># apachectl -t</code>

<code>Syntax OK</code>

<code>[root@localhost ~]</code><code># apachectl -l</code>

<code>[root@localhost ~]</code><code># apachectl -M</code>

編譯安裝php 5.6.8

<code>[root@localhost src]</code><code># tar zxvf php-5.6.8.tar.gz </code>

<code>[root@localhost src]</code><code># cd php-5.6.8</code>

<code>[root@localhost php-5.6.8]</code><code># ./configure   --prefix=/usr/local/php   --with-apxs2=/usr/local/apache2/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 </code>

<code>[root@localhost php-5.6.8]</code><code># make &amp;&amp; make install</code>

<code>[root@localhost php-5.6.8]</code><code># echo $?</code>

拷貝php配置檔案

<code>[root@localhost php-5.6.8]</code><code># cp /usr/local/src/php-5.6.8/php.ini-production /usr/local/php/etc/php.ini</code>

修改時區

<code>[root@localhost php-5.6.8]</code><code># vi /usr/local/php/etc/php.ini </code>

<code>date</code><code>.timezone =Asia</code><code>/Shanghai</code>

配置php與apache

1、修改AddType參數,紅色為新添加

[root@localhost php-5.6.8]# vi /usr/local/apache2/conf/httpd.conf

    # AddType allows you to add to or override the MIME configuration

    #AddType application/x-gzip .tgz

    AddType application/x-compress .Z

    AddType application/x-gzip .gz .tgz

    AddType application/x-httpd-php .php

    #AddType text/html .shtml

2、修改index.html,紅色為新添加

&lt;IfModule dir_module&gt; 

    DirectoryIndex index.html index.php

&lt;/IfModule&gt;

3、修改severname,紅色為新添加

#ServerName www.example.com:80

ServerName localhost:80

4、測試解析php,在/usr/local/apache2/htdocs/目錄下,寫一個測試php檔案

7

<code>[root@localhost php-5.6.8]</code><code># cat /usr/local/apache2/htdocs/test.php</code>

<code>&lt;?php</code>

<code>echo</code> <code>"PHP解析正常\n"</code><code>;</code>

<code>?&gt;</code>

<code>[root@localhost htdocs]</code><code># /etc/init.d/httpd restart</code>

<code>[root@localhost htdocs]</code><code># curl localhost/test.php</code>

<code>PHP解析正常</code>

或者寫一個phpinfo();

至此LAMP環境搭建完畢。

本文轉自 模範生 51CTO部落格,原文連結:http://blog.51cto.com/mofansheng/1671419,如需轉載請自行聯系原作者