一、部署規劃
1.1 版本控制
版本 | 作者 | 日期 | 修改記錄 | 備註 |
---|---|---|---|---|
V1.0 | XXX | 2018-4-27 | 初始創建 | |
1.2 設備部署
角色 | IP地址 | 主機名 | 功能 | 備註 |
---|---|---|---|---|
server | 192.168.10.8 | min.linux.yu | 提供LAMP環境 | |
client | 192.168.10.2 | client.linux.yu | 訪問、測試 |
二、環境說明
2.1 系統版本
Distributor ID: CentOS Description: CentOS release 6.5 (Final) Release: 6.5 Codename: Final
2.2 軟件版本
MySQL版本
mysql-5.6.25.tar.gz
Apache版本
httpd-2.4.12.tar.bz2
PHP版本
php-5.6.11.tar.xz
2.3 系統初始化
2.3.1 關閉防火牆和selinux
[root@min ~]# service iptables stop [root@min ~]# chkconfig iptables off [root@min ~]# chkconfig --list |grep iptables iptables 0:off 1:off 2:off 3:off 4:off 5:off 6:off [root@min ~]# setenforce 0 setenforce: SELinux is disabled [root@min ~]# vim /etc/selinux/config # This file controls the state of SELinux on the system. # SELINUX= can take one of these three values: # enforcing - SELinux security policy is enforced. # permissive - SELinux prints warnings instead of enforcing. # disabled - No SELinux policy is loaded. SELINUX=disabled //設爲disabled,永久關閉 # SELINUXTYPE= can take one of these two values: # targeted - Targeted processes are protected, # mls - Multi Level Security protection. SELINUXTYPE=targeted
2.3.2 配置yum源
[root@min yum.repos.d]# cd /etc/yum.repos.d/ [root@min yum.repos.d]# ll total 24 drwxr-xr-x. 2 root root 4096 Apr 27 15:15 backup -rw-r--r--. 1 root root 1926 Nov 27 2013 CentOS-Base.repo -rw-r--r--. 1 root root 638 Nov 27 2013 CentOS-Debuginfo.repo -rw-r--r--. 1 root root 630 Nov 27 2013 CentOS-Media.repo -rw-r--r--. 1 root root 3664 Nov 27 2013 CentOS-Vault.repo //爲原來的yum源備份 [root@min yum.repos.d]# mv Cent* backup [root@min yum.repos.d]# ll total 8 drwxr-xr-x. 2 root root 4096 Apr 27 15:16 backup //搭建新的本地yum源 [root@min yum.repos.d]# vim mylocal.repo [mylocal] name=mylocal baseurl=file:///mnt/dvd enabled=1 gpgcheck=0 //清理緩存 [root@min yum.repos.d]# yum clean all Loaded plugins: fastestmirror Cleaning repos: mylocal Cleaning up Everything Cleaning up list of fastest mirrors //創建新緩存 [root@min yum.repos.d]# yum makecache Loaded plugins: fastestmirror Determining fastest mirrors mylocal | 4.0 kB 00:00 ... mylocal/group_gz | 220 kB 00:00 ... mylocal/filelists_db | 5.8 MB 00:00 ... mylocal/primary_db | 4.4 MB 00:00 ... mylocal/other_db | 2.7 MB 00:00 ... Metadata Cache Created
2.3.3 需要安裝的其他軟件包
# yum groupinstall "Development tools" -y # yum groupinstall "Desktop Platform Development" -y 桌面開發工具包(圖形化相關包) # yum install cmake # yum install ncurses-devel //必須安裝
三、安裝步驟
說明:注意安裝順序,不同版本MySQL、Apache、PHP之間的依賴關係不同,所以安裝順序有一定要求,本手冊所使用的軟件沒有要求,但最好是MySQL、Apache、PHP的順序。
3.1 編譯安裝MySQL
3.1.1 安裝規劃
1. 安裝目錄 /mysql25/base_dir 2. 數據目錄 /mysql25/data 3. 端口 3307 4. socket文件 /mysql25/base_dir
3.1.2 解壓軟件包
//所有軟件都放在 /LAMP文件夾下 [root@min ~]# cd /LAMP/ [root@min LAMP]# ls apr-1.5.2.tar.bz2 mysql-5.6.25.tar.gz phpMyAdmin-4.4.11-all-languages.zip apr-util-1.5.4.tar.bz2 mysql-5.6.30-linux-glibc2.5-x86_64.tar.gz phpwind_v9.0.1_utf8.zip Discuz_X2.5_SC_UTF8.zip mysql-5.6.31.tar.gz wordpress-4.7.3-zh_CN.tar.gz httpd-2.4.12.tar.bz2 php-5.6.11.tar.xz mysql-5.6.25-linux-glibc2.5-x86_64.tar.gz php-5.6.23.tar.xz [root@min LAMP]# tar -xf mysql-5.6.25.tar.gz -C /usr/src/ [root@min LAMP]# ls /usr/src/ debug kernels mysql-5.6.25
3.1.3 安裝
創建相應的目錄和用戶並授權
[root@min LAMP]# mkdir /mysql25/base_dir -p [root@min LAMP]# mkdir /mysql25/data //-r創建一個系統用戶,-s指定默認的shell /sbin/nologin 不能登錄操作系統 [root@min LAMP]# useradd -r mysql -s /sbin/nologin [root@min yum.repos.d]# id mysql uid=498(mysql) gid=498(mysql) groups=498(mysql) [root@min LAMP]# ll -d /mysql25/ drwxr-xr-x 4 root root 4096 Apr 26 10:09 /mysql25/ [root@min LAMP]# chown -R mysql.mysql /mysql25/ [root@min LAMP]# ll -d /mysql25/ drwxr-xr-x 4 mysql mysql 4096 Apr 26 10:09 /mysql25/ [root@min yum.repos.d]# ll /mysql25/ total 8 drwxr-xr-x. 13 mysql mysql 4096 Apr 27 12:23 base_dir drwx------. 6 mysql mysql 4096 Apr 27 12:23 data
進入到解壓目錄進行安裝
[root@min LAMP]# cd /usr/src/mysql-5.6.25/ [root@min mysql-5.6.25]# pwd /usr/src/mysql-5.6.25
配置、編譯、安裝
vim /usr/src/mysql-5.6.25/cmake.sh //用腳本進行配置 cmake . \ -DCMAKE_INSTALL_PREFIX=/mysql25/base_dir/ \ -DMYSQL_DATADIR=/mysql25/data \ -DENABLED_LOCAL_INFILE=1 \ -DWITH_INNOBASE_STORAGE_ENGINE=1 \ -DSYSCONFDIR=/mysql25/base_dir/etc \ -DMYSQL_UNIX_ADDR=/mysql25/base_dir/mysql.sock \ -DMYSQL_TCP_PORT=3307 \ -DDEFAULT_CHARSET=utf8 \ -DDEFAULT_COLLATION=utf8_general_ci \ -DWITH_EXTRA_CHARSETS=all \ -DMYSQL_USER=mysql chmod +x cmake.sh 編譯: make 安裝: make install
安裝完成後配置數據庫
[root@min etc]# mv /etc/my.cnf /opt/ //這一步很重要,這是系統遺留文件,它會指定MySQL到/var/lib/mysql裏去找文件,但是安裝目錄並不在/var/lib/mysql 中,所以會報錯,所以要把這個文件移走,或者更改其內容,改爲真實安裝的目錄。 //初始化數據到/mysql25/data [root@min base_dir]# scripts/mysql_install_db --user=mysql --basedir=/mysql25/base_dir --datadir=/mysql25/data
3.1.4 測試、驗證、啓動
[root@min base_dir]# bin/mysqld_safe --user=mysql & //用安全模式登錄驗證 [root@min mysql25]# ps -ef|grep mysql root 56548 3186 0 11:27 pts/0 00:00:00 /bin/sh bin/mysqld_safe --user=mysql mysql 56638 56548 1 11:27 pts/0 00:00:00 /mysql25/base_dir/bin/mysqld --basedir=/mysql25/base_dir --datadir=/mysql25/data --plugin-dir=/mysql25/base_dir/lib/plugin --user=mysql --log-error=/mysql25/data/server.itcast.cc.err --pid-file=/mysql25/data/server.itcast.cc.pid root 56664 52572 0 11:27 pts/1 00:00:00 grep mysql [root@min mysql25]# netstat -nltp|grep 3307 tcp 0 0 :::3307 :::* LISTEN 56638/mysqld
更改啓動方式,用service啓動
[root@min base_dir]# cp support-files/mysql.server /etc/init.d/mysql25 [root@min base_dir]# netstat -nltp|grep 3307 [root@min base_dir]# service mysql25 start Starting MySQL [ OK ] [root@min base_dir]# netstat -nltp|grep 3307 tcp 0 0 :::3307 :::* LISTEN 56820/mysqld
登錄驗證
[root@min base_dir]# /mysql25/base_dir/bin/mysql Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 2 Server version: 5.6.25 Source distribution Copyright (c) 2000, 2015, Oracle and/or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. mysql> exit Bye
用mysql命令直接登錄
[root@min base_dir]# vim /etc/profile export PATH=/mysql25/base_dir/bin:$PATH //在文件的最後增加 [root@min base_dir]# source /etc/profile //重新讀取該配置文件 [root@min ~]# mysql Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 4 Server version: 5.6.25 Source distribution Copyright (c) 2000, 2015, Oracle and/or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. mysql>
設置數據庫密碼
[root@min ~]# mysqladmin -uroot password '123456' Warning: Using a password on the command line interface can be insecure.
3.2 編譯安裝Apache
3.2.1 安裝依賴包apr
說明:系統自帶apr版本過低,需要重新安裝apr
# tar xf apr-1.5.2.tar.bz2 -C /usr/src/ # cd /usr/src/apr-1.5.2 # ./configure //一定要進入解壓文件夾內執行 # make # make install # tar xf apr-util-1.5.4.tar.bz2 -C /usr/src/ # cd /usr/src/apr-util-1.5.4/ # ./configure --with-apr=/usr/local/apr/bin/apr-1-config //指定軟件apr的路徑 # make # make install
3.2.2 安裝httpd(Apache)軟件
解壓軟件
[root@min LAMP]# tar -xf httpd-2.4.12.tar.bz2 -C /usr/src/ [root@min LAMP]# cd /usr/src/ [root@min src]# ls apr-1.5.2 apr-util-1.5.4 debug httpd-2.4.12 kernels mysql-5.6.25 [root@min src]# cd httpd-2.4.12/ //進入解壓文件夾進行安裝 [root@min httpd-2.4.12]# pwd /usr/src/httpd-2.4.12
安裝相關軟件
[root@min httpd-2.4.12]# yum -y install pcre-devel //若沒有安裝會報錯,顯示缺少依賴軟件
配置
vim /usr/src/httpd-2.4.12/apache.sh //用腳本配置 ./configure \ --enable-modules=all \ --enable-mods-shared=all \ --enable-so \ --enable-rewrite \ --with-mpm=prefork \ --with-apr=/usr/local/apr/bin/apr-1-config \ --with-apr-util=/usr/local/apr/bin/apu-1-config [root@min httpd-2.4.12]# chmod +x apache.sh [root@min httpd-2.4.12]# ./apache.sh //執行腳本
編譯、安裝
# make # make install
驗證
# ls /usr/local/apache2/ //確認這個目錄產生後,說明apache編譯安裝成功 bin build cgi-bin conf error htdocs icons include logs man manual modules
3.3 編譯安裝PHP
3.3.1 安裝前裝備
安裝可能缺少的軟件
[root@min php-5.6.11]# yum -y install libcurl-devel //可以先配置,若報錯缺少此軟件,再安裝也可以
解壓到指定目錄中
[root@min LAMP]# tar -xf php-5.6.11.tar.xz -C /usr/src/ [root@min LAMP]# cd /usr/src/ [root@min src]# ls apr-1.5.2 apr-util-1.5.4 debug httpd-2.4.12 kernels mysql-5.6.25 php-5.6.11 [root@min src]# cd php-5.6.11/ [root@min php-5.6.11]# pwd /usr/src/php-5.6.11 //安裝前一定要進入解壓目錄
3.3.2 安裝
配置
vim /usr/src/php-5.6.11/php.sh ./configure \ --with-apxs2=/usr/local/apache2/bin/apxs \ --with-mysql=/mysql25/base_dir/ \ --with-mysqli=/mysql25/base_dir/bin/mysql_config \ --with-pdo-mysql=/mysql25/base_dir \ --with-zlib \ --with-zlib-dir=/mysql25/base_dir/zlib \ --with-curl \ --enable-zip \ --with-gd \ --with-freetype-dir \ --with-jpeg-dir \ --with-png-dir \ --enable-sockets \ --with-xmlrpc \ --enable-soap \ --enable-opcache \ --enable-mbstring \ --enable-mbregex \ --enable-pcntl \ --enable-shmop \ --enable-sysvmsg \ --enable-sysvsem \ --enable-sysvshm \ --enable-calendar \ --enable-bcmath chmod +x /usr/src/php-5.6.11/php.sh [root@min php-5.6.11]# ./php.sh
編譯、安裝
# make //make成功後,會顯示讓你make test,不用做 # make install
驗證
# ls /usr/local/apache2/modules/libphp5.so //確認有這個.so模塊文件,就表示編譯php成功
四、後續配置
4.1 配置Apache
修改Apache配置文件
# vim /usr/local/apache2/conf/httpd.conf 1> 配置優先支持中文 LoadModule negotiation_module modules/mod_negotiation.so //此模塊打開註釋 Include conf/extra/httpd-languages.conf //打開此選項,擴展配置文件就生效了 # vim /usr/local/apache2/conf/extra/httpd-languages.conf //修改子配置文件 DefaultLanguage zh-CN //打開註釋,默認語言集改爲中文
配置Apache對PHP支持
# vim /usr/local/apache2/conf/httpd.conf LoadModule php5_module modules/libphp5.so //在這句下面加上以下命令 AddHandler php5-script .php AddType text/html .php //向Apache中加入支持PHP <IfModule dir_module> DirectoryIndex index.php index.html </IfModule> //默認主頁加上index.php,並放在index.html前,支持php的首頁文件
配置網站家目錄
DocumentRoot "/web" //修改網站家目錄 <Directory "/web"> ...... </Directory> //默認的網站目錄:/usr/local/apache2/htdocs/
4.2 讓PHP支持鏈接本地數據庫
指定socket文件路徑
# cp /usr/src/php-5.6.11/php.ini-production /usr/local/lib/php.ini //告訴PHP從哪裏讀取socket文件。
修改配置文件
# vim /usr/local/lib/php.ini [MySQL] mysql.default_port = 3307 改成對應的mysql的端口 mysql.default_socket = /mysql25/base_dir/ 對應的socket文件地址 [MySQLi] mysqli.default_port = 3307 mysqli.default_socket = /mysql25/base_dir/
向網站家目錄裏寫入測試頁
[root@min ~]# vim /web/index.php <?php phpinfo(); >
五、測試
5.1 啓動MySQL和Apache
MySQL啓動見3.1.4
使用service啓動Apache
# cp /usr/local/apache2/bin/apachectl /etc/init.d/apache # service apache start
5.2 測試是否支持PHP
登錄client ,在瀏覽器裏輸入:http:/192.168.10.8/
顯示PHP測試頁面,登入成功!