1. 程式人生 > >centos7原始碼編譯安裝LAMP

centos7原始碼編譯安裝LAMP

LAMP用到的軟體版本:

httpd-2.4.27.tar.gz mariadb-10.2.8-linux-x86_64.tar.gz php-7.1.10.tar.xz

安裝順序:
順序: mariadb–>httpd–>php
httpd和mariadb順序無所謂,PHP是最後,因為PHP編譯時要指明httpd的路徑

編譯安裝mariadb(二進位制)

tar xvf mariadb-10.2.8-linux-x86_64.tar.gz -C /usr/local
cd /usr/local
ls -sv mariadb-10.2.8-linux-x86_64 mysql
useradd -r -m -d /app/mydata -s /sbin/nologin mysql
mkdir /etc/mysql
cd mysql/
cp
support-files/my-large.cnf /etc/mysql/my.cnf vim /etc/mysql/my.cnf [mysqld]加三行 datadir =/mydata/data innodb_file_per_table = ON skip_name_resolve = ON scripts/mysql_install_db --user=mysql datadir=/app/mydata cp support-files/mysql.server /etc/rc.d/init.d/mysqld chkconfig --add mysqld chkconfig mysqld on service mysqld start /usr/local/mysql/bin/mysql #測試是否成功
vim /etc/profile.d/mysql.sh export PATH=/usr/local/mysql/bin/:$PATH /usr/local/mysql/bin/mysql_secure_installation #安全初始化資料庫

編譯安裝httpd2.4

yum install pcre-devel apr-devel apr-util-devel openssl-devel apr apr-util
tar xvf httpd-2.4.27.tar.gz
cd httpd-2.4.27
./configure --prefix=/app/httpd24 --enable-so --enable-ssl
--enable-rewrite --with-zlib --with-pcre --with-apr=/usr --with-apr-util=/usr --enable-modules=most --enable-mpms-shared=all --with-mpm=prefork make && make install cd /app/httpd24 cp bin/apachectl /etc/init.d/httpd chkconfig --add httpd chkconfig httpd on

編譯安裝PHP

tar xvf php-7.1.10.tar.xz
cd php-7.1.10
./configure --prefix=/app/php --enable-mysqlnd --with-mysqli=mysqlnd --with-openssl --with-pdomysql=mysqlnd --enable-mbstring --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir=/usr --enable-xml --enable-sockets --with-apxs2=/app/httpd24/bin/apxs --with-mcrypt --with-config-file-path=/etc --with-config-file-scan-dir=/etc/php.d --enable-maintainer-zts --disable-fileinfo
cp php.ini-production /etc/php.ini #為php提供配置檔案
vim /etc/httpd24/conf/httpd.conf #編輯apache配置檔案httpd.conf,以使apache支援php
AddType application/x-httpd-php .php #在最後新增兩行
AddType application/x-httpd-php-source .phps
#定位至DirectoryIndex index.html
修改為DirectoryIndex index.php index.html
systemctl start httpd

注意: php-7.0以上版本使用 –enable-mysqlnd –with-mysqli=mysqlnd ,原–with-mysql不再支援

測試

vi /app/httpd24/htdocs/index.php
<?php
$mysqli=new mysqli("localhost","root","123456");
if(mysqli_connect_errno()){
echo "連線資料庫失敗!";
$mysqli=null;
exit;
}
echo "連線資料庫成功!";
$mysqli->close();
?>

訪問網站,看是否能連通資料庫,記得要設定資料庫密碼,當然資料庫最好放在其他伺服器上。