導讀:什麼是LAMP?
LAMP指的Linux(操作系統)、ApacheHTTP 服務器,MySQL(有時也指MariaDB,數據庫軟件) 和PHP(有時也是指Perl或Python) 的第一個字母,一般用來建立web應用平臺。
本案環境與說明:
環境
[root@bright ~]# cat /etc/centos-release && uname -r CentOS release 6.6 (Final) 2.6.32-504.el6.x86_64
軟件版本:
mysql-5.7.6-m16-linux-glibc2.5-x86_64.tar.gz httpd-2.4.10.tar.gz apr-1.5.1.tar.gz apr-util-1.5.4.tar.gz libmcrypt-2.5.6.tar.gz php-5.6.6.tar.gz
文中所用軟件下載地址:
http://mirrors.sohu.com/
http://mirrors.cnnic.cn/apache/
ftp://mcrypt.hellug.gr/pub/crypto/mcrypt/libmcrypt
一、安裝MySQL
wget http://mirrors.sohu.com/mysql/MySQL-5.7/mysql-5.7.6-m16-linux-glibc2.5-x86_64.tar.gz
[root@bright ~]# useradd -s /sbin/nologin mysql [root@bright ~]# tar zxvf mysql-5.7.6-m16-linux-glibc2.5-x86_64.tar.gz [root@bright ~]# cd /usr/local/ [root@bright local]# mv /root/mysql-5.7.6-m16-linux-glibc2.5-x86_64 . [root@bright local]# ln -s mysql-5.7.6-m16-linux-glibc2.5-x86_64 mysql [root@bright local]# cd mysql [root@bright mysql]# mkdir /data/mysql [root@bright mysql]# chown -R root . [root@bright mysql]# chown -R mysql /data/mysql [root@bright mysql]# chgrp -R mysql . [root@bright mysql]# bin/mysql_install_db --user=mysql --datadir=/data/mysql [root@bright mysql]# cp support-files/my-default.cnf /etc/my.cnf cp:是否覆蓋"/etc/my.cnf"? y [root@bright mysql]# cp support-files/mysql.server /etc/init.d/mysqld [root@bright mysql]# chmod 755 /etc/init.d/mysqld [root@bright mysql]# vim /etc/init.d/mysqld [root@bright mysql]# chkconfig --add mysqld [root@bright mysql]# service mysqld start Starting MySQL. SUCCESS!
二、安裝Apache
Centos6 yum安裝的apr版本已經不適用httpd-2.4版本了。所以,需要源碼編譯apr以及apr-util
wget http://mirrors.cnnic.cn/apache/apr/apr-util-1.5.4.tar.gz
wget http://mirrors.cnnic.cn/apache/apr/apr-1.5.1.tar.gz
wget http://archive.apache.org/dist/httpd/httpd-2.4.10.tar.gz
2.1 安裝apr
[root@bright ~]# tar zxvf apr-1.5.1.tar.gz [root@bright ~]# cd apr-1.5.1 [root@bright apr-1.5.1]# ./configure --prefix=/usr/local/apr [root@bright apr-1.5.1]# make && make install
2.2 安裝apr-util
[root@bright ~]# cd apr-util-1.5.4 [root@bright apr-util-1.5.4]# ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr/ [root@bright apr-util-1.5.4]# make && make install [root@bright apr-util-1.5.4]# echo $?
2.3 安裝Apache
檢查開發環境,沒有的直接yum
[root@bright ~]# rpm -q gcc cmake pcre-devel gcc-4.4.7-11.el6.x86_64 cmake-2.8.12.2-4.el6.x86_64 package pcre-devel is not installed [root@bright ~]# yum install pcre-devel
安裝:
[root@bright ~]# tar -zxvf httpd-2.4.10.tar.gz [root@bright ~]# cd httpd-2.4.10 [root@bright httpd-2.4.10]# ./configure --prefix=/usr/local/apache2 --with-apr=/usr/local/apr/ --with-apr-util=/usr/local/apr-util/ --with-pcre --enable-mods-shared=most [root@bright httpd-2.4.10]# make && make install [root@bright ~]# cp /usr/local/apache2/bin/apachectl /etc/rc.d/init.d/httpd [root@bright ~]# ln -s /etc/rc.d/init.d/httpd /etc/rc.d/rc3.d/S61httpd [root@bright ~]# vi /etc/rc.d/init.d/httpd #在第二行插入添加下面兩行 # chkconfig: 35 61 61 # description: Apache [root@bright ~]# chkconfig --add httpd
三、安裝PHP
wget http://mirrors.sohu.com/php/php-5.6.6.tar.gz
wget ftp://mcrypt.hellug.gr/pub/crypto/mcrypt/libmcrypt/libmcrypt-2.5.6.tar.gz
3.1 檢查開發環境,沒有的直接yum
(如有某某.so,.h文件無法找到,用yum provides "*/*.h"去查找)
[root@bright ~]# rpm -q libxml2-devel libjpeg-turbo libpng-devel freetype-devel gd-devel libmcrypt-devel openssl-devel libxml2-devel-2.7.6-14.el6_5.2.x86_64 libjpeg-turbo-1.2.1-3.el6_5.x86_64 libpng-devel-1.2.49-1.el6_2.x86_64 freetype-devel-2.3.11-14.el6_3.1.x86_64 package gd-devel is not installed package libmcrypt-devel is not installed openssl-devel-1.0.1e-30.el6.x86_64 [root@bright ~]# yum install gd-devel
3.2 Centos6 默認的yum源沒有libmcrypt-devel 這個包,只能藉助第三方yum源,本案tar包安裝
[root@bright ~]# tar zxvf libmcrypt-2.5.6.tar.gz [root@bright ~]# cd libmcrypt-2.5.6 [root@bright libmcrypt-2.5.6]# ./configure --prefix=/usr/local/libmcrypt [root@bright libmcrypt-2.5.6]# make && make install
3.3 安裝php
[root@bright ~]# tar zxvf php-5.6.6.tar.gz [root@bright ~]# cd php-5.6.6 [root@bright php-5.6.6]# ./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=/usr/local/libmcrypt --enable-soap --enable-gd-native-ttf --enable-mbstring --enable-sockets --enable-exif --disable-ipv6 [root@bright php-5.6.6]# make && make install [root@bright php-5.6.6]# echo $? 0
四、配置apache和php與測試
1.修改AddType參數
[root@bright ~]# vi /usr/local/apache2/conf/httpd.conf [root@bright ~]# cat /usr/local/apache2/conf/httpd.conf | grep AddType | grep -v ^$ | grep -v ^# # 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.修改DirectoryIndex 參數
[root@bright ~]# cat /usr/local/apache2/conf/httpd.conf | grep index.html | grep -v ^$ # DirectoryIndex index.html DirectoryIndex index.html index.htm index.php #修改後的內容
3.修改ServerName參數
[root@bright ~]# cat /usr/local/apache2/conf/httpd.conf | grep ServerName| grep -v ^$ # ServerName gives the name and port that the server uses to identify itself. #ServerName www.example.com:80 ServerName localhost:80 #修改後的內容
4. 測試解析php
在/usr/local/apache2/htdocs/中創建一個文件,內容如下。
[root@bright ~]# cat /usr/local/apache2/htdocs/index.php <?php echo "php解析正常\n"; ?> [root@bright ~]# service httpd restart [root@bright ~]# curl localhost/index.php php解析正常
MySQL密碼修改之官方文檔: