安装前准备
CentOS 6.9 64位 最小化安装
yum install -y make gcc gcc-c++ perl zlib-devel libaio libpng libpng-devel libjpeg-devel pcre-devel
yum install -y libXpm-devel openssl openssl-devel libxml2-devel bzip2-devel.x86_64 libjpeg-turbo-devel
yum install -y freetype freetype-devel libtool cmake ncurses-devel bison re2c curl-devel wget
rpm -ivh "http://mirrors.sohu.com/fedora-epel/epel-release-latest-6.noarch.rpm"
yum install -y libmcrypt-devel re2c
一、安装MysqL
1.编译安装
下载软件包
cd /usr/local/src/
wget http://mirrors.sohu.com/MysqL/MysqL-5.7/http://mirrors.sohu.com/MysqL/MysqL-5.7/MysqL-boost-5.7.17.tar.gz
解压
tar zxvf MysqL-boost-5.7.17.tar.gz
编译&安装
cd MysqL-5.7.17
cmake \
-DCMAKE_INSTALL_PREFIX=/usr/local/MysqL \
-DMysqL_DATADIR=/data/MysqL \
-DSYSCONFDIR=/etc \
-DWITH_MYISAM_STORAGE_ENGINE=1 \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_MEMORY_STORAGE_ENGINE=1 \
-DWITH_READLINE=1 \
-DMysqL_UNIX_ADDR=/tmp/MysqL.sock \
-DMysqL_TCP_PORT=3306 \
-DENABLED_LOCAL_INFILE=1 \
-DWITH_PARTITION_STORAGE_ENGINE=1 \
-DEXTRA_CHARSETS=all \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci \
-DWITH_BOOST=./boost/boost_1_59_0/
make && make install
注意:如果编译出错,执行如下操作,然后重新配置。
make clean
rm CMakeCache.txt
2.二进制包安装
若编译过程较慢,可以下载编译好的二进制包直接安装
cd /usr/local/src/
wget http://mirrors.sohu.com/MysqL/MysqL-5.7/MysqL-5.7.17-linux-glibc2.5-x86_64.tar.gz
tar zxvf MysqL-5.7.17-linux-glibc2.5-x86_64.tar.gz
移至/usr/local/MysqL目录
mv MysqL-5.7.17-linux-glibc2.5-x86_64 /usr/local/MysqL
3.建立MysqL用户
useradd -s /sbin/nologin MysqL
mkdir -p /data/MysqL
chown -R MysqL:MysqL /data/MysqL
cd /usr/local/MysqL
bin/MysqLd --initialize --basedir=/usr/local/MysqL --datadir=/data/MysqL --user=MysqL
(5.7初始化方式已经变更,直接使用MysqLd命令初始化,5.6之前版本初始化执行下面这句:
scripts/MysqL_install_db --basedir=/usr/local/MysqL --datadir=/data/MysqL --user=MysqL)
结束后会生成一个密码,记下来
初始化时会出现如下警告:
[Warning] TIMESTAMP with implicit DEFAULT value is deprecated.
Please use --explicit_defaults_for_timestamp server option (see
documentation for more details).
要想取消该警告,在启动MysqL时,my.cnf中加入
[MysqLd]
explicit_defaults_for_timestamp=true
添加服务,拷贝服务脚本到init.d目录,并设置开机启动
cp support-files/my-default.cnf /etc/my.cnf
cp support-files/MysqL.server /etc/init.d/MysqLd
chmod 755 /etc/init.d/MysqLd
vi /etc/init.d/MysqLd
修改datadir
basedir=/usr/local/MysqL
datadir=/data/MysqL
chkconfig --add MysqLd
chkconfig MysqLd on
service MysqLd start
修改密码
/usr/local/MysqL/bin/MysqLadmin -uroot -p'刚才记下的密码' password "新密码"
二、安装apache2.4
下载源码:
cd /usr/local/src
wget http://mirrors.cnnic.cn/apache/httpd/httpd-2.4.25.tar.gz
wget http://mirrors.cnnic.cn/apache/apr/apr-1.5.2.tar.gz
wget http://mirrors.cnnic.cn/apache/apr/apr-util-1.5.4.tar.gz
tar zxvf /usr/local/src/httpd-2.4.25.tar.gz
tar zxvf /usr/local/src/apr-1.5.2.tar.gz
tar zxvf /usr/local/src/apr-util-1.5.4.tar.gz
mv /usr/local/src/apr-1.5.2 /usr/local/src/httpd-2.4.25/srclib/apr
mv /usr/local/src/apr-util-1.5.4 /usr/local/src/httpd-2.4.25/srclib/apr-util
cd /usr/local/src/httpd-2.4.25
./configure \--prefix=/usr/local/apache2 \--with-included-apr \--enable-so \--enable-deflate=shared \--enable-expires=shared \--enable-rewrite=shared
make && make install
cd /usr/local/apache2/
vi conf/httpd.conf
找到
#ServerName www.example.com:80
改成
ServerName localhost:80
检查配置文件语法
bin/apachectl -t
配置启动脚本
cp /usr/local/src/httpd-2.4.25/build/rpm/httpd.init /etc/init.d/httpd
httpd=${HTTPD-/usr/local/apache2/bin/httpd}
pidfile=${PIDFILE-/usr/local/apache2/logs/${prog}.pid}
CONFFILE=/usr/local/apache2/conf/httpd.conf
请根据自己的实际情况更改相应的路径!
然后运行如下命令:
chmod +x /etc/init.d/httpd
chkconfig --add httpd
chkconfig httpd on
/etc/init.d/httpd start
netstat -lnp |grep httpd
三、PHP安装
cd /usr/local/src
wget http://mirrors.sohu.com/PHP/PHP-7.1.3.tar.gz
tar zxvf PHP-7.1.3.tar.gz
cd PHP-7.1.3
./configure \
--prefix=/usr/local/PHP \
--with-apxs2=/usr/local/apache2/bin/apxs \
--with-config-file-path=/usr/local/PHP/etc \
--with-MysqL-sock=/tmp/MysqL.sock \
--enable-MysqLnd \
--with-MysqLi=MysqLnd \
--with-pdo-MysqL=MysqLnd \
--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
make && make install
cp PHP.ini-production /usr/local/PHP/etc/PHP.ini
四、apache结合PHP
vi /usr/local/apache2/conf/httpd.conf
找到
#ServerName www.example.com:80
改成
ServerName localhost:80
找到:
AddType application/x-gzip .gz .tgz
在该行下面添加:
AddType application/x-httpd-PHP .PHP
找到:
<IfModule dir_module>
DirectoryIndex index.html
</IfModule>
将该行改为:
<IfModule dir_module>
DirectoryIndex index.html index.htm index.PHP
</IfModule>
/usr/local/apache2/bin/apachectl -t
service httpd restart
测试解析PHP
vi /usr/local/apache2/htdocs/1.PHP
写入:
<?PHP
echo "PHP解析正常";
echo PHPinfo();
?>
保存后,继续测试:
curl localhost/1.PHP
查看结果已经可以成功解析。
原文链接:https://www.f2er.com/centos/378014.html