下載打包好的文件
查看Centos版本
[root@localhost ~]# cat /etc/redhat-release
CentOS Linux release 7.4.1708 (Core)
鏈接:https://download.csdn.net/download/code_pupil/10963295
放到路徑/usr/local/src
cd目錄
cd /usr/local/src/
解壓下載的壓縮包
安裝apache
安裝依賴: zlib-devel pcre-devel pcre apr apr-util
yum install zlib-devel pcre-devel pcre
yum -y install gcc gcc-c++ make automake
解壓apr壓縮包,進入目錄配置編譯安裝
tar -zxvf apr-1.5.2.tar.gz
cd apr-1.5.2
./configure --prefix=/usr/local/apr/
make && make install
編譯安裝apr 1.5.2 時報 rm: cannot remove `libtoolT': No such file or directory
解決辦法
(1):編輯 configure文件,查找 $RM "$cfgfile" 這個地方,用#註釋掉
解壓apr-util壓縮包,進入目錄配置編譯安裝
cd /usr/local/src/
tar -zxvf apr-util-1.5.4.tar.gz
cd apr-util-1.5.4
./configure --prefix=/usr/local/apr-util/ --with-apr=/usr/local/apr/
make && make install
解壓apache壓縮包,進入目錄配置編譯安裝
cd /usr/local/src/
tar -zxvf httpd-2.4.28.tar.gz
cd httpd-2.4.28
./configure \
--prefix=/usr/local/apache/ \
--with-apr=/usr/local/apr/ \
--with-apr-util=/usr/local/apr-util/ \
--enable-so \
--enable-deflate=shared \
--enable-expires=shared \
--enable-rewrite=shared \
--enable-static-support
make && make install
等安裝個完以後進入到安裝目錄,開啓apache服務
cd /usr/local/apache/bin/
./apachectl start
啓動報錯:httpd: Could not reliably determine the server's fully qualified domain name, using localhost.localdomain. Set the 'ServerName' directive globally to suppress this message
解決辦法
vi /usr/local/apache/conf/httpd.conf
(1):增加 ServerName localhost
重新啓動
[root@localhost bin]# ./apachectl start
httpd (pid 38347) already running
打開80端口並重啓
firewall-cmd --zone=public --add-port=80/tcp --permanent
firewall-cmd --reload
設置開機自啓動
cp /usr/local/apache/bin/apachectl /etc/init.d/httpd
執行 chkconfig --add httpd 目的是想新增所制定的系統服務 但是會出現以下警告:
[root@localhost bin]# chkconfig --add httpd
service httpd does not support chkconfig
這裏說的是httpd服務不支持chkconfig , 添加支持: vi /etc/init.d/httpd 在 #!/bin/sh 下添加這兩句:
#chkconfig:345 85 15
#description:Start and stop the Apache HTTP Server 最終結果爲:
vi /etc/init.d/httpd
chkconfig --add httpd
安裝mysql
安裝依賴:
yum -y install make gcc-c++ cmake bison-devel ncurses-devel
解壓cmake壓縮包,進入目錄配置編譯安裝
cd /usr/local/src/
tar -zxvf cmake-2.8.10.2.tar.gz
cd cmake-2.8.10.2
./bootstrap
gmake
gmake install
建立mysql的用戶和
groupadd mysql
useradd -g mysql mysql -s /usr/sbin/nologin
mkdir /usr/local/mysql
mkdir /usr/local/mysql/data
解壓mysql壓縮包,進入目錄配置編譯安裝
cd /usr/local/src/
tar -zxvf mysql-5.6.28.tar.gz
cd mysql-5.6.28
cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql && make && make install
cd /usr/local/mysql/
scripts/mysql_install_db --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --user=mysql
cp support-files/mysql.server /etc/rc.d/init.d/mysqld
chown -R mysql:mysql /usr/local/mysql
編輯配置文件
vi /usr/local/mysql/my.cnf
加上以下內容
[mysqld]
basedir = /usr/local/mysql
datadir = /usr/local/mysql/data
log-error = /usr/local/mysql/mysql_error.log
pid-file = /usr/local/mysql/mysql.pid
user = mysql
tmpdir = /tmp
lower_case_table_names=1
Linux系統 vi /etc/my.cnf 註釋log-error、pid-file 兩行
vi /etc/my.cnf
[mysqld]
#datadir=/var/lib/mysql
[mysqld_safe]
#log-error=/var/log/mariadb/mariadb.log
#pid-file=/var/run/mariadb/mariadb.pid
並加上以下內容
[mysqld]
basedir = /usr/local/mysql
datadir = /usr/local/mysql/data
log-error = /usr/local/mysql/mysql_error.log
pid-file = /usr/local/mysql/mysql.pid
user = mysql
tmpdir = /tmp
vi /usr/local/mysql/my.cnf
註釋:
#datadir=/var/lib/mysql
加上以下內容
[mysqld]
basedir = /usr/local/mysql
datadir = /usr/local/mysql/data
log-error = /usr/local/mysql/mysql_error.log
pid-file = /usr/local/mysql/mysql.pid
user = mysql
tmpdir = /tmp
使用下列命令把mysql添加爲系統服務。
cd /usr/local/mysql/support-files/
cp ./mysql.server /etc/init.d/mysqld
/etc/init.d/mysqld start
chkconfig --add mysqld
service mysqld start
[root@localhost /]# mysql -u root
-bash: mysql: command not found
原因:這是由於系統默認會查找/usr/bin下的命令,如果這個命令不在這個目錄下,當然會找不到命令,我們需要做的就是映射一個鏈接到/usr/bin目錄下,相當於建立一個鏈接文件。
首先得知道mysql命令或mysqladmin命令的完整路徑,比如mysql的路徑是:/usr/local/mysql/bin/mysql,我們則可以這樣執行命令:
ln -s /usr/local/mysql/bin/mysql /usr/bin
[root@localhost /]# mysql -u root
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)
查找mysql.sock文件
[root@localhost /]# find / -name mysql.sock
/var/lib/mysql/mysql.sock
ln -s /var/lib/mysql/mysql.sock /tmp/mysql.sock
設置root用戶的遠程訪問權限
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%'WITH GRANT OPTION;
SET PASSWORD FOR 'root'@'%' = PASSWORD('123456');
安裝PHP
安裝依賴:php-mcrypt libmcrypt libmcrypt-devel autoconf freetype gd jpegsrc libmcrypt libpng libpng-devel libjpeg libxml2 libxml2-devel zlib curl curl-devel
yum -y install php-mcrypt libmcrypt libmcrypt-devel autoconf freetype gd jpegsrc libmcrypt libpng libpng-devel libjpeg libxml2 libxml2-devel zlib curl curl-devel
解壓php壓縮包,進入目錄配置編譯安裝
cd /usr/local/src/
tar -zxvf php-7.2.3.tar.gz
cd php-7.2.3
./configure --prefix=/usr/local/php/ --with-apxs2=/usr/local/apache/bin/apxs --enable-mbstring --with-curl --with-gd --enable-fpm --enable-mysqlnd --with-pdo-mysql=mysqlnd --with-config-file-path=/usr/local/php/etc/ --with-mysqli=mysqlnd --with-mysql-sock=/var/lib/mysql/mysql.sock--with-mysql-sock=/var/lib/mysql/mysql.sock
make && make install
cp php.ini-development /usr/local/php/etc/php.ini
編輯apache配置文件
vi /usr/local/apache/conf/httpd.conf
設置環境變量
ln -s /usr/local/php/bin/php /usr/bin/php
加入以下內容
Addtype application/x-httpd-php .php .phtml
/usr/local/apache/bin/apachectl restart