centos7.4編譯安裝lamp
lamp簡介
Linux+Apache+Mysql/MariaDB+PHP一組常用來搭建動態網站或者服務器的開源軟件,本身都是各自獨立的程序,但是因為常被放在一起使用,擁有了越來越高的兼容度,共同組成了一個強大的Web應用程序平臺。apache相對nginx來說更加穩定,動態頁面的處理更加合適。
源碼包
httpd-2.4.33
mariadb-10.2.14
php-7.2.5
基本編譯環境構建
系統版本:CentOS 7.4 x86_64
安裝開發包:Development Tools
yum groupinstall Development\ Tools -y
編譯安裝mariadb需要cmake ncurses-devel
yum install cmake -y
yum install ncurses-devel.x86_64 -y
開始編譯
編譯安裝httpd-2.4.33
這裏我們構建MPM為默認模塊,這裏需要apr和apr-util 1.5以上的版本
因此先到官方網站去下載相應版本
官方網站地址 https://apr.apache.org/
先編譯安裝apr,apr-util之後要依賴apr
wget http://archive.apache.org/dist/apr/apr-1.5.1.tar.gz tar xvf apr-1.5.1.tar.gz cd apr-1.5.1/ ./configure --prefix=/usr/local/apr make && make install
之後編譯安裝apr-util
wget http://archive.apache.org/dist/apr/apr-util-1.5.4.tar.gz
tar xvf apr-util-1.5.4.tar.gz
cd apr-util-1.5.4/
./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr
#with-apr要指明apr的安裝目錄,apr-util要依賴apr編譯
make && make install
httpd編譯依賴的包yum安裝即可,這裏提前安裝以便編譯過程一次通過
yum install pcre-devel.x86_64 -y yum install openssl-devel.x86_64 -y
下載並且編譯安裝httpd
wget http://archive.apache.org/dist/httpd/httpd-2.4.33.tar.gz
tar xvf httpd-2.4.33.tar.gz
cd httpd-2.4.33/
./configure --prefix=/usr/local/apache --sysconfdir=/etc/httpd24 --enable-so --enable-ssl --enable-cgi --enable-rewrite --with-zlib --with-pcre --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util --enable-modules=most --enable-mpms-shared=all --with-mpm=event
註釋:
./configure下的第一行指明編譯安裝的路徑
第二行指明配置文件的路徑
第三行支持動態裝載卸載模塊
第四行支持https通信
第五行支持cgi協議
第六行支持url重寫
第七行支持數據壓縮
第八行兼容正則表達式
第九行和第十行指明apr和apr-util路徑
第十一行 支持大多數模塊
第十二行 支持全部的工作模型
第十三行 默認工作模式為event
make && make install
編輯/etc/httpd24/httpd.conf,添加如下行即可:
PidFile "/var/run/httpd.pid"
添加PATH變量
編輯/etc/profile
vim /etc/profile
添加如下字段
export PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin:/usr/local/apache/bin
保存之後重讀配置文件
source /etc/profile
啟動httpd驗證httpd能夠正常工作
apachectl start
curl 127.0.0.1
顯示如下字段證明可以正常工作
到此為止httpd編譯基本完成。
如果想要更改運行賬號和所屬組可以通過修改配置文件的user和group字段為apache
useradd -r -s /sbin/nologin apache
chown -R apache:apache /usr/local/apache
想要啟動腳本可以去yum安裝的httpd中拷貝一份放到對應目錄即可,這裏不再贅述。
編譯安裝mariadb
獲取mariadb的源碼包
wget http://mirrors.neusoft.edu.cn/mariadb//mariadb-10.2.14/source/mariadb-10.2.14.tar.gz
解壓並且進入目錄
tar xvf mariadb-10.2.14.tar.gz
cd mariadb-10.2.14/
使用cmake進行編譯安裝
cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DSYSCONFDIR=/etc -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DWITH_EXTRA_CHARSETS=all
# 註:
#第一行是mysql主程序安裝目錄
#第二行是配置文件目錄
#第三行默認字符集為utf8
#第四行默認的字符集效對規則
#第五行安裝所有字符集
make && make install
添加mysql用戶和組
useradd -r -M -s /sbin/nologin mysql
chown mysql:root /usr/local/mysql/
進行一些基本配置
cp support-files/my-large.cnf /etc/my.cnf
#復制配置文件
cp support-files/mysql.server /etc/init.d/mysqld
#復制啟動腳本
vim /etc/my.conf datadir = /mydata
#指定數據庫路徑,不然無法啟動mysql 自己定義
innodb_file_per_table = on
#設置後當創建數據庫的表的時候表文件都會分離開,方便復制表,不開啟創建的表都在一個文件
skip_name_resolve = on
#跳過名稱反解,Mysql每次使用客戶端鏈接時都會把ip地址反解成主機名
添加環境變量
vim /etc/profile
export PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin:/usr/local/apache/bin:/usr/local/mysql/bin
#添加mysql的目錄
source /etc/profile
初始化數據庫
/usr/local/mysql/scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql --datadir=/mydata/
#初始化數據庫
啟動數據庫
service mysql start
安全初始化,這裏會要求設置密碼
/usr/local/mysql/bin/mysql_secure_installation
mysql基本完成
編譯安裝php
編譯過程中缺少的一些包
yum install libxml2-devel.x86_64 -y
yum install bzip2-devel.x86_64 -y
下載php-7.2.5並且解壓
wget http://us1.php.net/distributions/php-7.2.5.tar.bz2
tar xvf php-7.2.5.tar.bz2
cd php-7.2.5/
編譯安裝php
./configure --prefix=/usr/local/php --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --with-openssl --enable-mbstring --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir=/usr --enable-xml --enable-sockets --with-apxs2=/usr/local/apache/bin/apxs --with-config-file-path=/etc --with-config-file-scan-dir=/etc/php.d --with-bz2 --enable-maintainer-zts
#這裏要註意的是原來的--with-mysql在5.5廢棄,在php7開始被移除,之後推薦使用 MySQLi 或 PDO_MySQL 擴展來替換
官方示例mysqli
make && make install
配置文件
為php提供配置文件:
cp php.ini-production /etc/php.ini
編輯apache配置文件httpd.conf,以apache支持php
vim /etc/httpd/httpd.conf
1、添加如下二行
AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps
2、定位至DirectoryIndex index.html
修改為:
DirectoryIndex index.php index.html
而後重新啟動httpd,或讓其重新載入配置文件即可測試php是否已經可以正常使用。
測試頁面index.php示例如下:
<?php
phpinfo();
?>
<?php
$link = mysqli_connect(‘127.0.0.1‘,‘root‘,‘123‘);
if ($link)
echo "Success...";
else
echo "Failure...";
mysql_close();
?>
重啟httpd之後進行驗證
apachectl stop
apachectl start
完結撒花~
centos7.4編譯安裝lamp