以home目錄為例,進入/home
cd /home
是否安裝gcc與gcc-c++,沒有則安裝
yum -y install gcc gcc-c++
一、安裝Apache
- 下載httpd
wget https://mirrors.tuna.tsinghua.edu.cn/apache//httpd/httpd-2.4.39.tar.gz
- 下載依賴
wget https://mirrors.tuna.tsinghua.edu.cn/apache//apr/apr-1.7.0.tar.gz wget https://mirrors.tuna.tsinghua.edu.cn/apache//apr/apr-util-1.6.1.tar.gz wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.40.tar.gz wget https://github.com/libexpat/libexpat/releases/download/R_2_0_1/expat-2.0.1.tar.gz
- 解壓
// 根據自己實際包名解壓 tar zxvf apr-1.7.0.tar.gz tar zxvf apr-util-1.6.1.tar.gz tar zxvf pcre-8.40.tar.gz tar zxvf expat-2.0.1.tar.gz tar zxvf httpd-2.4.39.tar.gz
- 安裝依賴
- 安裝apr
cd /home/apr-1.7.0 ./configure --prefix=/usr/local/apr make && make install
--prefix=路徑 表示安裝地址
-
- 安裝expat
cd /home/expat-2.0.1 ./configure make && make install
注:需要先安裝expat,再安裝apr-util。安裝apr-util可能會報
-
- 安裝apr-util
cd /home/apr-util-1.6.1 ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr make && make install
--without-名稱=路徑 表示不包含的
--with-名稱=路徑 表示包含
-
- 安裝pcre
cd /home/cd pcre-8.40 ./configure --prefix=/usr/local/pcre make && make install
- 安裝apache
cd /home/httpd-2.4.39 ./configure --prefix=/usr/local/apache --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util --with-pcre=/usr/local/pcre --enable-so --enable-rewrite make && make install
--enable-so 將apache的其它模塊設置為動態開啟,如果不能動態開啟,就需要重新安裝了
--enable-rewrite 開啟apache重寫機制
- 啟動apache
// 啟動 /usr/local/apache/bin/apachectl // 讓文件在任意位置可調用 cp /usr/local/apache/bin/apachectl /etc/init.d/httpd // 現在任意位置即可調用httpd來 開啟/關閉 apache
// 關閉 service httpd stop // 開啟 service httpd start // 重啟 service httpd restart
二、安裝MySQL
- 下載mysql
wget https://dev.mysql.com/get/Downloads/MySQL-5.6/mysql-5.6.43.tar.gz
- 安裝依賴
yum -y install cmake ncurses ncurses-devel autoconf
- 解壓
tar zxvf mysql-5.6.43.tar.gz
- 為mysql添加用戶組
groupadd mysql
useradd -r -g mysql mysql -s /sbin/nologin
- 安裝MySQL
cd /home/mysql-5.6.43 cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_DATADIR=/usr/local/mysql/data -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci make && make install
-DCMAKE_INSTALL_PREFIX 指定mysql的安裝地址
-DMYSQL_DATADIR 指定mysql的數據存儲地址
- 配置mysql
cd /usr/local/mysql
cp support-files/my-default.cnf /etc/my.cnf // 編輯 vi my.cnf // 修改內容 [client] port = 3306 default-character-set=utf8 [mysqld] port = 3306 character_set_server=utf8 skip-external-locking key_buffer_size = 16M max_allowed_packet = 1M table_open_cache = 64 sort_buffer_size = 512K net_buffer_length = 8K read_buffer_size = 256K read_rnd_buffer_size = 512K myisam_sort_buffer_size = 8M socket = /data/mysql/mysql.sock basedir=/data/mysql datadir=/data/mysql/data
// 初始化數據 ./scripts/mysql_install_db --user=mysql --datadir=/usr/local/mysql/data/
// 任意位置啟動/關閉mysql cp support-files/mysql.server /etc/init.d/mysqld service mysqld start service mysqld restart service mysqld stop
// 設置root賬號的密碼 ./bin/mysqladmin -u root password 'youpassword'
// 把mysql的相關文件 改為mysql組的mysql用戶 chown -R mysql:mysql /usr/local/mysql chown mysql:mysql /etc/my.cnf
三、安裝PHP
- 下載php
wget https://www.php.net/distributions/php-7.1.13.tar.gz
- 安裝依賴
yum -y install jpeg8 gd libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel zlib zlib-devel curl curl-devel openssl openssl-devel
- 安裝php
tar zxvf php-7.1.13.tar.gz cd /home/php-7.1.13 ./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --with-apxs2=/usr/local/apache/bin/apxs --with-pdo-mysql=mysqlnd --with-mysqli=mysqlnd --with-zlib --with-curl --with-gd --with-jpeg-dir --with-png-dir --with-freetype-dir --with-openssl --enable-mbstring --enable-xml --enable-pdo --enable-mbstring=all --enable-mbregex --enable-shared make && make install
參數作用,詳見:https://www.cnblogs.com/hubing/p/3735452.html
- 添加apache與php交互
vi /usr/local/apache/conf/httpd.cnf
151行后添加如下內容
AddType application/x-httpd-php .php
- 添加配置文件
// 拷貝配置文件到安裝目錄 cp ./php.ini-development /usr/local/php/etc/php.ini
在/usr/local/apache/htdocs/添加一個php文件,啟動apache,能解析配置成功