再談centOS7.2 LAMP源碼安裝及注意要點

以前在另外一篇文章裏介紹過《centOS7 LAMP安裝及注意要點》,用的是yum自帶安裝。php

一個朋友在阿里雲上買了ECS雲主機,選擇是最新的centos7.2 64位操做系統,幫忙配置一下環境。在這裏作一下記錄:html

1、安裝apache2.4node

cd 
mkdir lamp
cd lamp
wget http://apache.fayea.com/httpd/httpd-2.4.37.tar.gz
tar -zxvf httpd-2.4.37.tar.gz
./configure --prefix=/usr/local/apache2 --enable-modules=all --enable-cache=static --enable-mem-cache=static --enable-file-cache=static --enable-disk-cache=static --enable-ssl=satic --enable-deflate=static --enable-expires=static --enable-rewrite=static --enable-so --with-apr=/usr/local/apr/ --with-apr-util=/usr/local/apr-util/ --with-pcre=/usr/local/pcre

 

#若是想配置SSL:mysql

#openssl
wget https://www.openssl.org/source/openssl-1.0.2n.tar.gz
tar -zxvf openssl-1.0.2n.tar.gz
cd openssl-1.0.2n
./config -fPIC --prefix=/usr/local/openssl/ enable-shared
make
make install

ln -s /usr/local/openssl/lib/*.so.* /usr/lib64  
ln -s /usr/local/openssl/lib/*.so.* /usr/lib

sed -i 's:#LoadModule ssl_module modules/mod_ssl.so:LoadModule ssl_module modules/mod_ssl.so:' /usr/local/apache2/conf/httpd.conf  
sed -i 's:#LoadModule socache_shmcb_module modules/mod_socache_shmcb.so:LoadModule socache_shmcb_module modules/mod_socache_shmcb.so:' /usr/local/apache2/conf/httpd.conf  
sed -i 's:#Include conf/extra/httpd-ssl.conf:Include conf/extra/httpd-ssl.conf:' /usr/local/apache2/conf/httpd.conf


下面的命令能夠被用來產生一個自簽名的證書。(來自網絡)

首先,生成2048位的加密私鑰
/usr/local/openssl/bin/openssl genrsa -out server.key 2048

而後,生成證書籤名請求(CSR),這裏須要填寫許多信息,如國家,省市,公司等
/usr/local/openssl/bin/openssl req -new -key server.key -out server.csr

最後,生成類型爲X509的自簽名證書。有效期設置3650天,即有效期爲10年
/usr/local/openssl/bin/openssl x509 -req -days 3650 -in server.csr -signkey server.key -out server.crt

cp server.* /usr/local/apache2/conf/


sed -i 's:#SSLCertificateChainFile "/usr/local/apache2/conf/server.crt":SSLCertificateChainFile "/usr/local/apache2/conf/server.crt":' /usr/local/apache2/conf/extra/httpd-ssl.conf 


#apache
./configure --prefix=/usr/local/apache2 --enable-modules=all --enable-cache=static --enable-mem-cache=static --enable-file-cache=static --enable-disk-cache=static --enable-ssl=static --enable-deflate=static --enable-expires=static  --enable-rewrite=static --enable-so --with-apr=/usr/local/apr/ --with-apr-util=/usr/local/apr-util/ --with-pcre=/usr/local/pcre --with-ssl=/usr/local/openssl

這時候會報錯:linux

error: Bundled APR requested but not found at ./srclib/. Download and unpack the corresponding apr and apr-util packages to ./srclib/.

如何解決了, 原來它依賴apr和apr-util包;咱們先安裝它的依賴包吧c++

一、aprsql

cd lamp
wget http://apache.fayea.com/apr/apr-1.6.5.tar.gz
tar -zxvf apr-1.6.5.tar.gz
cd apr-1.6.5
#在configure前,要先安裝apr的依賴
yum install -y autoconf libtool
./buildconf
./configure --prefix=/usr/local/apr
make
make install

我在configure的時候,也報了一個錯:數據庫

executing libtool commands rm: cannot remove 'libtoolT': No such file ordirectory

如何解決了,在網上google一下,去configure裏的文件$RM "$cfgfile"註釋掉apache

vim configure
$RM "$cfgfile" 
#前面加一個」#「,就能夠~

而後再./configure 、make、make installvim

二、apr-util

cd lamp
wget http://apache.fayea.com/apr/apr-util-1.6.1.tar.gz
tar -zxvf apr-util-1.6.1.tar.gz
cd apr-util-1.6.1
./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr
make
make install

這樣apr-util就安裝完畢了

可能會報的錯:

apr-util make: *** [all-recursive] 錯誤 1

解決辦法:

安裝  expat-devel

yum install -y expat-devel

三、pcre

這個pcre也要安裝一下,否則編譯的時候也會報錯。

cd lamp
wget https://excellmedia.dl.sourceforge.net/project/pcre/pcre/8.39/pcre-8.39.zip
yum install -y unzip #默認沒有zip解壓工具,先安裝
unzip pcre-8.39.zip
cd pcre-8.39
./configure --prefix=/usr/local/pcre
make
make install

好了,這個時候再編譯apache就不會再報錯了,同時指定 --with-apr等目錄就能夠了。

可能報錯1:把apr和apr-util拷貝到apache/srclib裏。

cp -fr apr-util-1.5.4 ./httpd-2.4.23/srclib/apr-util
cp -rf apr-1.5.2 ./httpd-2.4.23/srclib/apr

可能報錯2:

error: mod_deflate has been requested but can not be built due to prerequisite failures

解決方法:

yum install zlib-devel

安裝zlib就能夠解決~

可能報錯3:

configure: error: You need a C++ compiler for C++ support

解決方法:

yum install -y gcc gcc-c++

四、測試apache

vi /usr/local/apache2/conf/httpd.conf
#把servename改爲如下
ServerName localhost:80

啓動apache並測試:

/usr/local/apache2/bin/apachectl start
curl localhost

應該能夠看到 it works,表示安裝成功。

2、Mysql5.7

centos7.2默認的數據庫:mariadb;收購免難免費,先不討論。習慣了mysql,咱們就安裝最新版的。

先卸載:mariadb

#查看是否存在
rpm -qa | grep mariadb
#卸載
rpm -e --nodeps mariadb-libs-5.5.44-2.el7.centos.x86_64

下載mysql:(若是是centos6,請下載el6版本的)

cd lamp
wget http://cdn.mysql.com//Downloads/MySQL-5.7/mysql-community-common-5.7.14-1.el7.x86_64.rpm
wget http://cdn.mysql.com//Downloads/MySQL-5.7/mysql-community-libs-5.7.14-1.el7.x86_64.rpm
wget http://cdn.mysql.com//Downloads/MySQL-5.7/mysql-community-client-5.7.14-1.el7.x86_64.rpm
wget http://cdn.mysql.com//Downloads/MySQL-5.7/mysql-community-server-5.7.14-1.el7.x86_64.rpm

再安裝一下mysql須要的擴展:

yum install -y libaio

rpm安裝mysql:

rpm -ivh mysql-community-common-5.7.14-1.el7.x86_64.rpm --nosignature
rpm -ivh mysql-community-libs-5.7.14-1.el7.x86_64.rpm --nosignature
rpm -ivh mysql-community-client-5.7.14-1.el7.x86_64.rpm --nosignature
rpm -ivh mysql-community-server-5.7.14-1.el7.x86_64.rpm --nosignature
cd /usr/bin
mysqld --initialize-insecure --user=mysql #初始化
chown mysql:mysql -R /var/lib/mysql #修改權限
systemctl start mysqld #啓動
mysqladmin -u root password #設置mysql 密碼
mysql -u root -p #測試登陸

可能出現的錯:

libnuma.so.1()(64bit) is needed by mysql-community-server-5.7.14-1.el6.x86_64

解決方法:

wget http://mirror.centos.org/centos/6/os/x86_64/Packages/numactl-2.0.9-2.el6.x86_64.rpm
rpm -ivh numactl-2.0.9-2.el6.x86_64.rpm

Mysql5.7安裝完畢。

3、PHP7.0.10安裝

cd lamp
wget http://tw1.php.net/distributions/php-7.3.0.tar.gz
tar -zxvf php-7.3.0.tar.gz
cd php-7.3.0

在編譯以前,先安裝一些PHP擴展依賴:

yum -y install libxml2 libxml2-devel openssl openssl-devel curl-devel libjpeg-devel libpng-devel freetype-devel libmcrypt-devel bzip2 bzip2-devel libxslt-devel

安裝完畢後,接着安裝PHP:

./configure  --prefix=/usr/local/php7 --with-config-file-path=/usr/local/php7/etc --with-apxs2=/usr/local/apache2/bin/apxs --enable-fileinfo --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --with-iconv-dir --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir=/usr --enable-xml --disable-rpath --enable-bcmath --enable-shmop --enable-sysvsem --enable-sysvshm --enable-inline-optimization --with-curl --enable-mbregex --enable-mbstring --with-gd --with-openssl --with-mhash --enable-pcntl --enable-sockets --enable-calendar --with-xsl --enable-ctype --with-kerberos --enable-exif --with-xmlrpc --enable-ftp --with-gettext --enable-zip --enable-soap --disable-ipv6 --disable-debug --with-bz2 --enable-opcache 
make
make install

可能出錯的出錯1:

編譯zlib時提示 
configure: error: Please reinstall the libzip distributio 
或  configure: error: system libzip must be upgraded to version >= 0.11。使用Yum最新版只到0.10,不足以達到要求。

先刪除libzip  和   libzip-devel

yum remove libzip -y


安裝
wget https://nih.at/libzip/libzip-1.2.0.tar.gz
tar -zxvf libzip-1.2.0.tar.gz
cd libzip-1.5.1
./configure
make && make install
上面這種在實際操做上不成功,
或安裝
wget https://libzip.org/download/libzip-1.5.1.tar.gz
tar -zxvf libzip-*
cd libzip*
mkdir build && cd build && cmake .. && make && make install

若是提示cmake: command not found,須要先yum install cmake(默認安裝是2.8的,仍是會報錯)
手動編譯更高版本
先移除:
yum remove cmake
安裝
wget https://cmake.org/files/v3.10/cmake-3.10.2-Linux-x86_64.tar.gz
tar -zxvf cmake-3.10.2-Linux-x86_64.tar.gz
vim /etc/profile.d/cmake.sh
加下面內容
export CMAKE_HOME=/root/soft/cmake-3.10.2-Linux-x86_64
export PATH=$PATH:$CMAKE_HOME/bin

source /etc/profile
cmake -version 查看版本


再編PHP ./configure .....

可能報錯2:

configure: error: off_t undefined; check your library configuration

在終端下輸入下:
echo '/usr/local/lib64

/usr/local/lib

/usr/lib

/usr/lib64'>>/etc/ld.so.conf&&ldconfig -v


再編PHP ./configure .....

安裝完畢,如今要使apache支持php:

vim /usr/local/apache2/conf/httpd.conf
#找到DirectoryIndex
DirectoryIndex index.html index.htm default.html index.php default.php
#找到AddType 
AddType application/x-httpd-php .php
#重啓apache
/usr/local/apache2/bin/apachectl -k restart

整個安裝完畢。

4、問題

在配置虛擬主機的時候,要使得外網能訪問,得先防火牆80端口打開:

firewall-cmd --zone=public --add-port=80/tcp --permanent
firewall-cmd --reload  #重啓防火牆
#阿里雲,默認selinux是關閉的,因此不用擔憂

一些注意細節,能夠參考個人另外一篇《centOS7 LAMP安裝及注意要點》

最後設置一下apache開機自啓動:

cd /lib/systemd/system
vim httpd.service
[Unit]
Description=ApacheServer
After=network.target

[Install]
WantedBy=multi-user.target

[Service]
Type=forking
ExecStart=/usr/local/apache2/bin/apachectl -k start
ExecReload=/usr/local/apache2/bin/apachectl -k restart
ExecStop=/usr/local/apache2/bin/apachectl -k stop
PrivateTmp=true

#保存退出

#設置開機自啓動
systemctl enable httpd.service

由於我用的是「SecureCRT」,因此安裝一下lrzsz,這樣方便上傳和下載文件

yum install lrzsz
rz #本地到服務器
sz #服務器到本地

整篇介紹完畢,你們在安裝過程當中有什麼問題,歡迎留言~

相關文章
相關標籤/搜索