首先说下思路,因为一开始系统上已经跑了一套完成的 PHP 环境,那时候都是快速自动安装的,如果是跑一些5.3以下版本的话,很简单,几个指令,10分钟搞定了。
但现在要升级,彻底一点的话,唯有推倒重来了。所以步骤有:
1. 卸载掉当前的 Apache、php、mysql;
2. 清除残留的一些配置文件;
3. 一步步安装 Apache 、mysql、php,当然在过程当中需要注意每个软件的依赖控件不可少。
下面是整体的步骤,从卸载后开始(同理适合刚刚安装好的全新系统):
1. 准备工作
,工欲善其事必先利其器,各个软件的安装包是必须的, 有:
apr-1.5.1.tar.bz2
apr-util-1.5.4.tar.bz2
pcre-8.36.tar.bz2
httpd-2.4.10.tar.bz2
mysql-5.6.21.tar.gz
php-5.6.4.tar.bz2
2. 安装Apache2.4
apr-1.5.1.tar.bz2
cd apr-1.5.1 ./configure --prefix=/usr/local/apr make && make install
apr-util-1.5.4.tar.bz2
cd apr-util-1.5.4 ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr make && make install
pcre-8.36.tar.bz2
cd pcre-8.36 ./configure make && make install
这些是Apache依赖的一些安装包,解压,安装。
都完成后正式安装Apache
cd httpd-2.4.10 ./configure --prefix=/usr/local/apache2 --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util --with-pcre=/usr/local/pcre --enable-so --enable-rewrite make && make install
cp /usr/local/apache2/bin/apachectl /etc/rc.d/init.d/httpd
service httpd start
测试是否安装成功
出现“It works”就说明Apache已经正常安装。
linux下面安装Mysql5.6.21
安装Mysql,需要先安装好 cmake
yum -y install cmake make
一、编安装MySQL前的准备工作
安装编译源码所需的工具和库
yum install gcc gcc-c++ ncurses-devel perl
安装cmake,从http://www.cmake.org下载源码并编译安装
2. tar -xzvf cmake-2.8.10.2.tar.gz 3. cd cmake-2.8.10.2 4. ./bootstrap ; make ; make install 5. cd ~
二、设置MySQL用户和组
新增mysql用户组
- groupadd mysql
新增mysql用户
- useradd -r -g mysql mysql
三、新建MySQL所需要的目录
新建mysql安装目录
- mkdir -p /usr/local/mysql
新建mysql数据库数据文件目录
- mkdir -p /data/mysqldb
四、下载MySQL源码包并解压
解压mysql-5.6.16.tar.gz
- tar -zxv -f mysql-5.6.16.tar.gz
- cd mysql-5.6.16
p
cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_DATADIR=/usr/local/mysql/data -DSYSCONFIGDIR=/usr/local/mysql/etc -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_ARCHIVE_STORAGE_ENGINE=1 -DWITH_BLACKHOLE_STORAGE_ENGINE=1 -DWITH_PARTITION_STORAGE_ENGINE=1 -DMYSQL_UNIX_ADDR=/tmp/mysqld.sock -DMYSQL_TCP_PORT=3306 -DENABLED_LOCAL_INFILE=1 -DEXTRA_CHARSETS=all -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DMYSQL_USER=mysql
配置
rm CMakeCache.txt
编译源码
- make
安装
- make install
六、修改mysql目录所有者和组
修改mysql安装目录
1. cd /usr/local/mysql 2. chown -R mysql:mysql .
修改mysql数据库文件目录
cd /data/mysqldb chown -R mysql:mysql .
七、初始化mysql数据库
1. cd /usr/local/mysql 2. scripts/mysql_install_db --user=mysql --datadir=/data/mysqldb
八、复制mysql服务启动配置文件
cp /usr/local/mysql/support-files/my-default.cnf /etc/my.cnf
注:如果/etc/my.cnf文件存在,则覆盖。
九、复制mysql服务启动脚本及加入PATH路径
1. cp support-files/mysql.server /etc/init.d/mysqld 2. 3. vim /etc/profile 4. export MYSQL_HOME="/usr/local/mysql" export PATH="$PATH:$MYSQL_HOME/bin" 5. source /etc/profile
十、启动mysql服务并加入开机自启动(可选这个步骤,以后可以自己启动的)
service mysqld start chkconfig --level 35 mysqld on
十一、检查mysql服务是否启动
1. netstat -tulnp | grep 3306 2. mysql -u root -p
密码为空,如果能登陆上,则安装成功。
十二、修改MySQL用户root的密码
1. mysqladmin -u root password ‘123456‘
Normal
0
7.8 磅
0
2
false
false
false
EN-US
ZH-CN
X-NONE
/* Style Definitions */
table.MsoNormalTable
{mso-style-name:普通表格;
mso-tstyle-rowband-size:0;
mso-tstyle-colband-size:0;
mso-style-noshow:yes;
mso-style-priority:99;
mso-style-parent:"";
mso-padding-alt:0cm 5.4pt 0cm 5.4pt;
mso-para-margin:0cm;
mso-para-margin-bottom:.0001pt;
mso-pagination:widow-orphan;
font-size:10.5pt;
mso-bidi-font-size:11.0pt;
font-family:"Calibri","sans-serif";
mso-ascii-font-family:Calibri;
mso-ascii-theme-font:minor-latin;
mso-hansi-font-family:Calibri;
mso-hansi-theme-font:minor-latin;
mso-font-kerning:1.0pt;}
注:也可运行安全设置脚本,修改MySQL用户root的密码,同时可禁止root远程连接,移除test数据库和匿名用户。
1. /usr/local/mysql/bin/mysql_secure_installation
Normal
0
7.8 磅
0
2
false
false
false
EN-US
ZH-CN
X-NONE
/* Style Definitions */
table.MsoNormalTable
{mso-style-name:普通表格;
mso-tstyle-rowband-size:0;
mso-tstyle-colband-size:0;
mso-style-noshow:yes;
mso-style-priority:99;
mso-style-parent:"";
mso-padding-alt:0cm 5.4pt 0cm 5.4pt;
mso-para-margin:0cm;
mso-para-margin-bottom:.0001pt;
mso-pagination:widow-orphan;
font-size:10.5pt;
mso-bidi-font-size:11.0pt;
font-family:"Calibri","sans-serif";
mso-ascii-font-family:Calibri;
mso-ascii-theme-font:minor-latin;
mso-hansi-font-family:Calibri;
mso-hansi-theme-font:minor-latin;
mso-font-kerning:1.0pt;}
十三、可能会出现的错误
1. 问题: 2. Starting MySQL..The server quit without updating PID file ([FAILED]/mysql/Server03.mylinux.com.pid). 3. 解决: 4. 修改/etc/my.cnf 中datadir,指向正确的mysql数据库文件目录
2. ERROR 2002 (HY000): Can‘t connect to local MySQL server through socket ‘/tmp/mysql.sock‘ (2) 3. 解决: 4. 新建一个链接或在mysql中加入-S参数,直接指出mysql.sock位置。 5. ln -s /usr/local/mysql/data/mysql.sock /tmp/mysql.sock 6. 7. /usr/local/mysql/bin/mysql -u root -S /usr/local/mysql/data/mysql.sock
1. MySQL问题解决:-bash:mysql:command not found 2. 因为mysql命令的路径在/usr/local/mysql/bin下面,所以你直接使用mysql命令时, 3. 系统在/usr/bin下面查此命令,所以找不到了 4. 解决办法是: 5. ln -s /usr/local/mysql/bin/mysql /usr/bin 做个链接即可 6. 以下命令为mysql 启动及自启动配置 cp /usr/loacl/mysql/support-files/mysql.server /etc/init.d/mysqld /usr/local/mysql/scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data & chkconfig --add mysqld chkconfig --level 345 mysqld on service mysqld start 一般只要把my.cnf设置好这里就不会报错
Normal
0
7.8 磅
0
2
false
false
false
EN-US
ZH-CN
X-NONE
/* Style Definitions */
table.MsoNormalTable
{mso-style-name:普通表格;
mso-tstyle-rowband-size:0;
mso-tstyle-colband-size:0;
mso-style-noshow:yes;
mso-style-priority:99;
mso-style-parent:"";
mso-padding-alt:0cm 5.4pt 0cm 5.4pt;
mso-para-margin:0cm;
mso-para-margin-bottom:.0001pt;
mso-pagination:widow-orphan;
font-size:10.5pt;
mso-bidi-font-size:11.0pt;
font-family:"Calibri","sans-serif";
mso-ascii-font-family:Calibri;
mso-ascii-theme-font:minor-latin;
mso-hansi-font-family:Calibri;
mso-hansi-theme-font:minor-latin;
mso-font-kerning:1.0pt;}
安装PHP5.6
cd php-5.6.4 ./configure --prefix=/usr/local/php --with-apxs2=/usr/local/apache2/bin/apxs --with-libxml-dir=/usr/include/libxml2 --with-config-file-path=/usr/local/apache2/conf --with-mysql=/usr/local/mysql --with-mysqli=/usr/local/mysql/bin/mysql_config --with-gd --enable-gd-native-ttf --with-zlib --with-mcrypt --with-pdo-mysql=/usr/local/mysql --enable-shmop --enable-soap --enable-sockets --enable-wddx --enable-zip --with-xmlrpc --enable-fpm --enable-mbstring --with-zlib-dir --with-bz2 --with-curl --enable-exif --enable-ftp --with-jpeg-dir=/usr/lib --with-png-dir=/usr/lib --with-freetype-dir=/usr/lib/
make && make install
Normal
0
7.8 磅
0
2
false
false
false
EN-US
ZH-CN
X-NONE
/* Style Definitions */
table.MsoNormalTable
{mso-style-name:普通表格;
mso-tstyle-rowband-size:0;
mso-tstyle-colband-size:0;
mso-style-noshow:yes;
mso-style-priority:99;
mso-style-parent:"";
mso-padding-alt:0cm 5.4pt 0cm 5.4pt;
mso-para-margin:0cm;
mso-para-margin-bottom:.0001pt;
mso-pagination:widow-orphan;
font-size:10.5pt;
mso-bidi-font-size:11.0pt;
font-family:"Calibri","sans-serif";
mso-ascii-font-family:Calibri;
mso-ascii-theme-font:minor-latin;
mso-hansi-font-family:Calibri;
mso-hansi-theme-font:minor-latin;
mso-font-kerning:1.0pt;}
apache配置文件httpd.conf相关修改以支持PHP
vim /usr/local/apache/conf/httpd.conf
1. 添加php支持。
AddType application/x-httpd-php .php .phtml AddType application/x-httpd-php-source .phps
2. 添加默认索引页面index.php,再找到“DirectoryIndex”,在index.html后面加上“ index.php”
DirectoryIndex index.html index.php
3. 不显示目录结构,找到“Options Indexes FollowSymLinks”,修改为
Options FollowSymLinks
Normal
0
7.8 磅
0
2
false
false
false
EN-US
ZH-CN
X-NONE
/* Style Definitions */
table.MsoNormalTable
{mso-style-name:普通表格;
mso-tstyle-rowband-size:0;
mso-tstyle-colband-size:0;
mso-style-noshow:yes;
mso-style-priority:99;
mso-style-parent:"";
mso-padding-alt:0cm 5.4pt 0cm 5.4pt;
mso-para-margin:0cm;
mso-para-margin-bottom:.0001pt;
mso-pagination:widow-orphan;
font-size:10.5pt;
mso-bidi-font-size:11.0pt;
font-family:"Calibri","sans-serif";
mso-ascii-font-family:Calibri;
mso-ascii-theme-font:minor-latin;
mso-hansi-font-family:Calibri;
mso-hansi-theme-font:minor-latin;
mso-font-kerning:1.0pt;}
4. 开启Apache支持伪静态,找到“AllowOverride None”,修改为
AllowOverride All 保存httpd.conf配置,然后再执行以下两行命令 chown -R nobody. /usr/local/apache/htdocs/ chmod -R 777 /usr/local/apache/htdocs/ service httpd restart
Normal
0
7.8 磅
0
2
false
false
false
EN-US
ZH-CN
X-NONE
/* Style Definitions */
table.MsoNormalTable
{mso-style-name:普通表格;
mso-tstyle-rowband-size:0;
mso-tstyle-colband-size:0;
mso-style-noshow:yes;
mso-style-priority:99;
mso-style-parent:"";
mso-padding-alt:0cm 5.4pt 0cm 5.4pt;
mso-para-margin:0cm;
mso-para-margin-bottom:.0001pt;
mso-pagination:widow-orphan;
font-size:10.5pt;
mso-bidi-font-size:11.0pt;
font-family:"Calibri","sans-serif";
mso-ascii-font-family:Calibri;
mso-ascii-theme-font:minor-latin;
mso-hansi-font-family:Calibri;
mso-hansi-theme-font:minor-latin;
mso-font-kerning:1.0pt;}