LAMP环境搭建
MySQL和Apache安装没有先后顺序,但PHP一定是最后装
1、安装myaql
32位下载地址 http://syslab.comsenz.com/downloads/linux/mysql-5.1.40-linux-i686-icc-glibc23.tar.gz
64位下载地址 http://syslab.comsenz.com/downloads /linux/mysql-5.1.40-linux-x86_64-icc-glibc23.tar.gz
把下载文件放到该目录
[root@CentOS6 ~]# cd /usr/local/src/ [root@CentOS6 src]# ls mysql-5.1.40-linux-i686-icc-glibc23.tar.gz
可以查看一下该文件大小
[root@CentOS6 src]# du -sh mysql-5.1.40-linux-i686-icc-glibc23.tar.gz 118M mysql-5.1.40-linux-i686-icc-glibc23.tar.gz
解压
[root@CentOS6 src]# tar zxvf mysql-5.1.40-linux-i686-icc-glibc23.tar.gz [root@CentOS6 src]# ls mysql-5.1.40-linux-i686-icc-glibc23 mysql-5.1.40-linux-i686-icc-glibc23.tar.gz
把文件移动到/usr/local/mysql目录
[root@CentOS6 src]# mv mysql-5.1.40-linux-i686-icc-glibc23 /usr/local/mysql
增加一个叫mysql的用户,但现在先不登陆
[root@CentOS6 src]# useradd -s /sbin/nologin mysql
创建数据保存目录
[root@CentOS6 src]# mkdir -p /data/mysql
给该目录赋权限
[root@CentOS6 mysql]# chown -R mysql:mysql /data/mysql
这句话我还没弄明白是什么意思,先这样写,以后明白了再改
[root@CentOS6 mysql]# ./scripts/mysql_install_db --user=mysql --datadir=/data/mysql
检查安装是否成功(该命令适合所有,0表示安装成功)
[root@CentOS6 mysql]# echo $? 0
查看一些信息
[root@CentOS6 mysql]# ls /data/mysql/ mysql test [root@CentOS6 mysql]# ls bin docs INSTALL-BINARY mysql-test share COPYING EXCEPTIONS-CLIENT lib README sql-bench data include man scripts support-files [root@CentOS6 mysql]# ls support-files/ binary-configure my-huge.cnf mysqld_multi.server config.huge.ini my-innodb-heavy-4G.cnf mysql-log-rotate config.medium.ini my-large.cnf mysql.server config.small.ini my-medium.cnf ndb-config-2-node.ini magic my-small.cnf
我也不太明白这样写
[root@CentOS6 mysql]# cp support-files/mysql.server /etc/init.d/mysqld [root@CentOS6 mysql]# chkconfig --list mysqld mysqld 服务支持 chkconfig,但它在任何级别中都没有被引用(运行“chkconfig --add mysqld”) [root@CentOS6 mysql]# chmod 755 /etc/init.d/mysqld [root@CentOS6 mysql]# chkconfig --add mysqld [root@CentOS6 mysql]# chkconfig mysqld on [root@CentOS6 mysql]# chkconfig --list mysqld mysqld 0:关闭 1:关闭 2:启用 3:启用 4:启用 5:启用 6:关闭
编辑该文件
[root@CentOS6 mysql]# vim /etc/init.d/mysqld
改动的是这2条配置
basedir=/usr/local/mysql datadir=/data/mysql
拷贝文件,并同意覆盖
[root@CentOS6 mysql]# cp support-files/my-huge.cnf /etc/my.cnf cp:是否覆盖"/etc/my.cnf"? y
启动服务
[root@CentOS6 mysql]# service mysqld start Starting MySQL.. SUCCESS!
或者这样启动也行
[root@CentOS6 mysql]# /etc/init.d/mysqld restart Shutting down MySQL. SUCCESS! Starting MySQL. SUCCESS!
查看服务进程
[root@CentOS6 mysql]# ps aux | grep mysql root 1684 0.0 0.1 6676 1340 pts/1 S 13:40 0:00 /bin/sh /usr/local/mysql/bin/mysqld_safe --datadir=/data/mysql --pid-file=/data/mysql/CentOS6.6.pid mysql 1790 0.2 5.8 539328 60120 pts/1 Sl 13:40 0:00 /usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql --datadir=/data/mysql --user=mysql --log-error=/data/mysql/CentOS6.6.err --pid-file=/data/mysql/CentOS6.6.pid --socket=/tmp/mysql.sock --port=3306 root 1803 0.0 0.0 5976 744 pts/1 S+ 13:41 0:00 grep mysql
查看3306这个端口
[root@CentOS6 mysql]# netstat -lnp | grep 3306 tcp 0 0 0.0.0.0:3306 0.0.0.0:* LISTEN 1790/mysqld
查看里面的一些文件,.err是日志文件
[root@CentOS6 mysql]# ls /data/mysql/ CentOS6.6.err ib_logfile0 mysql-bin.000001 test CentOS6.6.pid ib_logfile1 mysql-bin.000002 ibdata1 mysql mysql-bin.index
2、安装apache
下载地址 wget http://syslab.comsenz.com/downloads/linux/httpd-2.2.16.tar.gz
把下载文件放到该目录
[root@CentOS6 ~]# cd /usr/local/src/ [root@CentOS6 src]# ls httpd-2.2.16.tar.gz mysql-5.1.40-linux-i686-icc-glibc23.tar.gz
可以查看一下该文件大小
[root@CentOS6 src]# du -sh httpd-2.2.16.tar.gz 6.1M httpd-2.2.16.tar.gz
解压
[root@CentOS6 src]# tar zxvf httpd-2.2.16.tar.gz [root@CentOS6 src]# ls httpd-2.2.16 httpd-2.2.16.tar.gz mysql-5.1.40-linux-i686-icc-glibc23.tar.gz
进入目录
[root@CentOS6 src]# cd httpd-2.2.16 [root@CentOS6 httpd-2.2.16]# ./configure --prefix=/usr/local/apache2 --enable-mods-shared=most --enable-so
编译
[root@CentOS6 httpd-2.2.16]# make && make install
检查安装是否成功(该命令适合所有,0表示安装成功)
[root@CentOS6 httpd-2.2.16]# echo $? 0
查看信息
[root@CentOS6 httpd-2.2.16]# ls /usr/local/apache2/ bin cgi-bin error icons lib man modules build conf htdocs include logs manual
启动服务
[root@CentOS6 httpd-2.2.16]# /usr/local/apache2/bin/apachectl start httpd: apr_sockaddr_info_get() failed for CentOS6.6 httpd: Could not reliably determine the server's fully qualified domain name, using 127.0.0.1 for ServerName
查看进程,一切OK
[root@CentOS6 httpd-2.2.16]# ps aux | grep httpd root 25902 0.1 0.2 5408 2316 ? Ss 15:55 0:00 /usr/local/apache2/bin/httpd -k start daemon 25903 0.0 0.1 5540 1588 ? S 15:55 0:00 /usr/local/apache2/bin/httpd -k start daemon 25904 0.0 0.1 5540 1588 ? S 15:55 0:00 /usr/local/apache2/bin/httpd -k start daemon 25905 0.0 0.1 5540 1588 ? S 15:55 0:00 /usr/local/apache2/bin/httpd -k start daemon 25906 0.0 0.1 5540 1588 ? S 15:55 0:00 /usr/local/apache2/bin/httpd -k start daemon 25907 0.0 0.1 5540 1588 ? S 15:55 0:00 /usr/local/apache2/bin/httpd -k start root 25909 1.0 0.0 5980 752 pts/1 S+ 15:56 0:00 grep httpd
3、安装php
下载地址 wget http://cn2.php.net/distributions/php-5.3.28.tar.gz
把下载文件放到该目录
[root@CentOS6 ~]# cd /usr/local/src/ [root@CentOS6 src]# ls httpd-2.2.16 mysql-5.1.40-linux-i686-icc-glibc23.tar.gz httpd-2.2.16.tar.gz php-5.3.28.tar.gz
可以查看一下该文件大小
[root@CentOS6 src]# du -sh php-5.3.28.tar.gz 14M php-5.3.28.tar.gz
解压
[root@CentOS6 src]# tar zxvf php-5.3.28.tar.gz [root@CentOS6 src]# ls httpd-2.2.16 php-5.3.28 httpd-2.2.16.tar.gz php-5.3.28.tar.gz mysql-5.1.40-linux-i686-icc-glibc23.tar.gz
进入目录,执行命令
[root@CentOS6 src]# cd php-5.3.28 [root@CentOS6 php-5.3.28]# ./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
检测到错误,然后安装
configure: error: xml2-config not found. Please check your libxml2 installation. [root@CentOS6 php-5.3.28]# yum install -y libxml2-devel
继续执行命令,检测到错误,继续安装
configure: error: Cannot find OpenSSL's <evp.h> [root@CentOS6 php-5.3.28]# yum install -y openssl-devel
继续执行命令,检测到错误,继续安装
configure: error: Please reinstall the BZip2 distribution [root@CentOS6 php-5.3.28]# yum install -y bzip2-devel
继续执行命令,检测到错误,继续安装
configure: error: jpeglib.h not found. [root@CentOS6 php-5.3.28]# yum install -y libjpeg-devel
继续执行命令,检测到错误,继续安装
configure: error: png.h not found. [root@CentOS6 php-5.3.28]# yum install -y libpng-devel
继续执行命令,检测到错误,继续安装
configure: error: freetype.h not found. [root@CentOS6 php-5.3.28]# yum install -y freetype-devel
继续执行命令,检测到错误,继续安装,出现下面情况说明之前没有安装过epel yum源
configure: error: mcrypt.h not found. Please reinstall libmcrypt. [root@CentOS6 php-5.3.28]# yum list | grep -i mcrypt [root@CentOS6 php-5.3.28]#
接下来下载并安装epel yum 源
32位epel yum源下载地址: www.lishiming.net/data/attachment/forum/epel-release-6-8_32.noarch.rpm
[root@CentOS6 ~]# cd /usr/local/src/ [root@CentOS6 src]# rz rz waiting to receive. Starting zmodem transfer. Press Ctrl+C to cancel. Transferring epel-release-6-8_32.noarch.rpm... 100% 14 KB 14 KB/sec 00:00:01 0 Errors [root@CentOS6 src]# rpm -ivh epel-release-6-8_32.noarch.rpm warning: epel-release-6-8_32.noarch.rpm: Header V3 RSA/SHA256 Signature, key ID 0608b895: NOKEY Preparing... (########################################### [100%] 1:epel-release (########################################### [100%]
安装后查看yum list
[root@CentOS6 php-5.3.28]# yum list | grep -i mcrypt libmcrypt.i686 2.5.8-9.el6 epel libmcrypt-devel.i686 2.5.8-9.el6 epel libtomcrypt.i686 1.17-21.el6 epel libtomcrypt-devel.i686 1.17-21.el6 epel libtomcrypt-doc.noarch 1.17-21.el6 epel mcrypt.i686 2.6.8-10.el6 epel php-mcrypt.i686 5.3.3-3.el6 epel
继续安装
[root@CentOS6 php-5.3.28]# yum install -y libmcrypt-devel
继续执行命令,检测安装成功
+--------------------------------------------------------------------+
| License: |
| This software is subject to the PHP License, available in this |
| distribution in the file LICENSE. By continuing this installation |
| process, you are bound by the terms of this license agreement. |
| If you do not agree with the terms of this license, you must abort |
| the installation process at this point. |
+--------------------------------------------------------------------+
Thank you for using PHP.
也可以这样检测
[root@CentOS6 php-5.3.28]# echo $? 0
然后执行
[root@CentOS6 php-5.3.28]# make && make install
至此,所有安装已经搞定。
4、配置apache结合php
[root@CentOS6 php-5.3.28]# /usr/local/apache2/bin/apachectl -l
Compiled in modules:
core.c
prefork.c
http_core.c
mod_so.c
[root@CentOS6 php-5.3.28]# /usr/local/apache2/bin/apachectl -t
httpd: apr_sockaddr_info_get() failed for CentOS6.6
httpd: Could not reliably determine the server's fully qualified domain name, using 127.0.0.1 for ServerName
编辑配置文件
[root@CentOS6 php-5.3.28]# vim /usr/local/apache2/conf/httpd.conf
找到该模块,把默认的Deny from all改为Allow from all
<Directory /> Options FollowSymLinks AllowOverride None Order deny,allow Allow from all </Directory>
找到该配置在后面加上 index.php
DirectoryIndex index.html index.php
找到该配置在后面加上 AddType application/x-httpd-php .php
AddType application/x-compress .Z AddType application/x-gzip .gz .tgz AddType application/x-httpd-php .php
如果是第一次操作该配置一定要重启,否则浏览器不能解析你的网页
[root@CentOS6 php-5.3.28]# /usr/local/apache2/bin/apachectl restart
如果之前操作成功过该配置,只是改动里面的部分配置信息的话,也可以重新加载一下配置就行了
[root@CentOS6 php-5.3.28]# /usr/local/apache2/bin/apachectl graceful
5、 测试解析php
创建1.php文件
vim /usr/local/apache2/htdocs/1.php
写入php代码
<?php echo "php解析正常"; ?>
保存后,继续在浏览器测试
LAMP配置