在實際環境中咱們常常根據本身所處的公司環境進行配置,適合本身公司的配置。下面咱們來介紹如何進行編譯安裝php
在CentOS7 系統:html
關閉iptables
將selinux設置爲disabled
apr-1.6.2.tar.gz
httpd-2.4.27.tar.bz2
php-7.1.10.tar.xz
apr-util-1.6.0.tar.gz
mariadb-10.2.8-linux-x86_64.tar.gz wordpress-4.8.1-zh_CN.tar.gz
安裝工具包development tools
注意:這裏安裝須要按順序進行的mariadb-->httpd-->php,mariadb和httpd安裝順序沒有關係mysql
在以前的apache博客中講過爲何要安裝apr和apr-util包,若是不懂請查看apache博客。linux
[root@localhost/usr/local/src]#tar xvf apr-1.6.2.tar.gz
[root@localhost/usr/local/src/apr-1.6.2]#./configure --prefix=/app/apr
[root@localhost/usr/local/src/apr-1.6.2]#make && make install
web
[root@localhost/usr/local/src]#tar xf apr-util-1.6.0.tar.gz
[root@localhost apr-util-1.6.0]# yum install -y expat-devel
[root@localhost/usr/local/src/apr-util-1.6.0]#./configure --prefix=/app/apr-util --with-apr=/app/apr
[root@localhost/usr/local/src/apr-util-1.6.0]#make && make install
sql
首先確認系統上是否有apache用戶,若是沒有須要建立數據庫
[root@localhost/usr/local/src]#useradd -r -m -d /app/website -s /sbin/nologin apache
[root@localhost/usr/local/src]#tar xf httpd-2.4.27.tar.bz2
apache
在編譯安裝httpd以前須要安裝幾個依賴包vim
[root@localhost/usr/local/src/httpd-2.4.27]#yum install -y pcre-devel apr-devel apr-util-devel openssl-devel
centos
[root@localhost/usr/local/src/httpd-2.4.27]#./configure --prefix=/app/httpd24 --enable-so --enable-ssl --enable-cgi --enable-rewrite --with-zlib --with-pcre --with-apr=/app/apr/ --with-apr-util=/app/apr-util/ --enable-modules=most --enable-mpms-shared=all --with-mpm=prefork
[root@localhost/usr/local/src/httpd-2.4.27]#make -j 4 && make install
[root@localhost/etc/profile.d]#vim httpd24.sh
export PATH=/app/httpd24/bin:$PATH
[root@localhost/etc/profile.d]#source httpd24.sh
[root@localhost/etc]#vim /etc/man_db.conf
23 MANDATORY_MANPATH /app/httpd24/man
[root@localhost/app/httpd24]#cp bin/apachectl /etc/init.d/httpd24
已經監聽80端口說明能夠啓動
(1)二進制安裝mariadb
[root@localhost/usr/local]#useradd -r -m -d /app/mysqldb -s /sbin/nologin mysql
[root@localhost/usr/local/src]#tar xf mariadb-10.2.8-linux-x86_64.tar.gz -C /usr/local/
[root@localhost/usr/local]#ln -sv mariadb-10.2.8-linux-x86_64/ mysql
(2)添加環境變量
[root@localhost/etc/profile.d]#vim mysql.sh
PATH=/usr/local/mysql/bin:$PATH
(3)配置man手冊
[root@localhost/usr/local/mysql/bin]#vim /etc/man_db.conf
24 MANDATORY_MANPATH /usr/local/mysql/man
(4)建立啓動腳本
[root@localhost/usr/local/mysql]#cp support-files/mysql.server /etc/init.d/mysqld
[root@localhost/usr/local/mysql]#chkconfig --add mysqld
(5)配置主配置文件
[root@localhost/usr/local/mysql]#mkdir /etc/mysql
[root@localhost/usr/local/mysql]#cp support-files/my-large.cnf /etc/mysql/my.cnf
[root@localhost/usr/local/mysql]#vim /etc/mysql/my.cnf
27 [mysqld]
28 datadir = /app/mysqldb
(6)建立日誌目錄
[root@localhost/usr/local/mysql]#mkdir /var/log/mariadb
[root@localhost/usr/local/mysql]#setfacl -Rm u:mysql:rwx /var/log/mariadb/
(7)安裝數據庫
[root@localhost/usr/local/mysql]#scripts/mysql_install_db --user=mysql --datadir=/app/mysqldb
(8)初始化數據庫
[root@localhost~]#mysql_secure_installation
(9)測試數據庫是否安裝成功
[root@localhost~]#mysql -u root -p
MariaDB [(none)]> CREATE DATABASE wpdb;
Query OK, 1 row affected (0.00 sec)
MariaDB [(none)]> GRANT ALL ON wpdb.* TO 'joah'@'localhost' IDENTIFIED BY '123456';
Query OK, 0 rows affected (0.00 sec)
MariaDB [(none)]> GRANT ALL ON wpdb.* TO 'joah'@'127.0.0.1' IDENTIFIED BY '123456';
(1)解壓縮並編譯安裝
[root@localhost/usr/local/src/php-7.1.10]#yum install -y libxml2-devel bzip2-devel libmcrypt-devel
[root@localhost/usr/local/src/php-7.1.10]#./configure --prefix=/app/php --enable-mysqlnd -- with-mysqli=mysqlnd --with-openssl --with-pdo-mysql=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
[root@localhost/usr/local/src/php-7.1.10]#make && make install
(2)配置主配置文件
[root@localhost/usr/local/src/php-7.1.10]#cp php.ini-production /etc/php.ini
(3)修改/etc/httpd/conf/httpd.conf
259 <IfModule dir_module>
260 DirectoryIndex index.php index.html
261 </IfModule>
512 AddType Application/x-httpd-php .php
513 AddType Application/x-httpd-php-source .phps
(4)測試可否與httpd鏈接成功
[root@localhost/app/httpd24/htdocs]#vim index.php
1 <?php
2 phpinfo();
3 ?>
(5)測試是否可否能夠和mariadb鏈接成功
[root@localhost/app/httpd24/htdocs]#vim index.php
<?php
$mysqli=new mysqli("localhost","root","centos");
if(mysqli_connect_errno()){
echo "鏈接數據庫失敗!";
$mysqli=null;
exit;
}
echo "鏈接數據庫成功!";
$mysqli->close();
phpinfo();
?>
[root@localhost/usr/local/src]#tar xf wordpress-4.8.tar.gz -C /app/httpd24/htdocs
[root@localhost/app/httpd24/htdocs/wordpress]#cp wp-config-sample.php wp-config.php
[root@localhost/app/httpd24/htdocs/wordpress]#vim wp-config.php
23 define('DB_NAME', 'wpdb');
24
25 /** MySQL database username */
26 define('DB_USER', 'joah');
27
28 /** MySQL database password */
29 define('DB_PASSWORD', '123456');
30
31 /** MySQL hostname */
32 define('DB_HOST', 'localhost');
http://192.168.4.59/wordpress/wp-admin/setup-config.php
測試其性能如何
[root@localhost/app/httpd24/htdocs/wordpress]#ab -c 10 -n 100 http://192.168.4.60/wordpress/
HTML transferred: 5209700 bytes
Requests per second: 25.25 [#/sec] (mean) #在沒有加速器性能還不錯
Time per request: 396.061 [ms] (mean)
安裝前環境準備 apr-1.6.2.tar.gz
httpd-2.4.27.tar.bz2
php-5.6.31.tar.xz
xcache-3.2.0.tar.bz2 apr-util-1.6.0.tar.gz
mariadb-5.5.57-linux-x86_64.tar.gz wordpress-4.8.1-zh_CN.tar.gz
(1)二進制安裝mariadb
[root@localhost/usr/local]#useradd -r -m -d /app/mysqldb -s /sbin/nologin mysql
[root@localhost/usr/local/src]#tar xf mariadb-10.2.8-linux-x86_64.tar.gz -C /usr/local/
[root@localhost/usr/local]#ln -sv mariadb-10.2.8-linux-x86_64/ mysql
(2)添加環境變量
[root@localhost/etc/profile.d]#vim mysql.sh
PATH=/usr/local/mysql/bin:$PATH
(3)配置man手冊
[root@localhost/usr/local/mysql/bin]#vim /etc/man_db.conf
24 MANDATORY_MANPATH /usr/local/mysql/man
(4)建立啓動腳本
[root@localhost/usr/local/mysql]#cp support-files/mysql.server /etc/init.d/mysqld
[root@localhost/usr/local/mysql]#chkconfig --add mysqld
(5)配置主配置文件
[root@localhost/usr/local/mysql]#mkdir /etc/mysql
[root@localhost/usr/local/mysql]#cp support-files/my-large.cnf /etc/mysql/my.cnf
[root@localhost/usr/local/mysql]#vim /etc/mysql/my.cnf
27 [mysqld]
28 datadir = /app/mysqldb
(6)建立日誌目錄
[root@localhost mysql]# touch /var/log/mysqld.log
(7)安裝數據庫
[root@localhost/usr/local/mysql]#scripts/mysql_install_db --user=mysql --datadir=/app/mysqldb
(8)初始化數據庫
[root@localhost~]#mysql_secure_installation
(9)測試數據庫是否安裝成功
[root@localhost~]#mysql -u root -p
MariaDB [(none)]> CREATE DATABASE wpdb;
Query OK, 1 row affected (0.00 sec)
MariaDB [(none)]> GRANT ALL ON wpdb.* TO 'joah'@'localhost' IDENTIFIED BY '123456';
Query OK, 0 rows affected (0.00 sec)
MariaDB [(none)]> GRANT ALL ON wpdb.* TO 'joah'@'127.0.0.1' IDENTIFIED BY '123456';
(1)解壓縮httpd源碼包
[root@localhost httpd-2.4.27]# yum install -y apr-devel apr-util-devel openssl-devel pcre-devel
[root@localhost httpd-2.4.27]# tar xf apr-1.6.2.tar.gz
[root@localhost httpd-2.4.27]# tar xf apr-util-1.6.0.tar.gz
[root@localhost httpd-2.4.27]# mv apr-1.6.2 httpd-2.4.27/srclib/
[root@localhost httpd-2.4.27]# mv apr-util-1.6.0 httpd-2.4.27/srclib/apr-util
[root@localhost httpd-2.4.27]# ./configure --prefix=/app/httpd24 --enable-so --enable-ssl --enable-rewrite --with-zlib --with-pcre --with-included-apr --enable-modules=most --enable-mpms-shared=all --with-mpm=prefork
[root@localhost httpd-2.4.27]# make && make install
(2)配置環境變量
[root@localhost httpd24]# vim /etc/profile.d/httpd24.sh
PATH=/app/httpd24/bin:$PATH
(3)配置啓動腳本
[root@localhost httpd24]# cp /etc/init.d/httpd /etc/init.d/httpd24
[root@localhost httpd24]# vim /etc/init.d/httpd24
apachectl=/app/httpd24/bin/apachectl
httpd=${HTTPD-/app/httpd24/bin/apachectl}
prog=httpd
pidfile=${PIDFILE-/app/httd24/logshttpd.pid}
lockfile=${LOCKFILE-/var/lock/subsys/httpd24}
RETVAL=0
STOP_TIMEOUT=${STOP_TIMEOUT-10}
(4)測試是否配置成功
[root@localhost httpd24]# service httpd24 start
(1)解壓縮並編譯安裝
[root@localhost php-5.6.4]#yum install libxml2-devel bzip2-devel libmcrypt-devel
[root@localhost php-5.6.31]# ./configure --prefix=/app/php --with-mysql=/usr/local/mysql --with-openssl --with-mysqli=/usr/local/mysql/bin/mysql_config --enable-mbstring --with-png-dir --with-jpeg-dir --with-freetype-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 --with-bz2
[root@localhost php-5.6.4]# make && make install
(2)配置主配置文件
[root@localhost php-5.6.31]# cp php.ini-production /etc/php.ini
(3)在httpd.conf中配置
259 <IfModule dir_module>
260 DirectoryIndex index.php index.html
261 </IfModule>
512 AddType Application/x-httpd-php .php
513 AddType Application/x-httpd-php-source .phps
接下的步驟和CentOS 7中的配置相似,請參考上述配置。
(4)配置環境變量
[root@localhost php]# vim /etc/profile.d/php.sh
PATH=/app/php/bin:$PATH
[root@localhost php]# source /etc/profile.d/php.sh
(5)測試是否能夠與apache通訊
[root@localhost htdocs]# vim index.php
?>
(6)測試是否能夠與mysql通訊
<?php
$msyqli=new mysqli("192.168.4.132","root","123456");
if(mysqli_connect_errno()){
echo "failure";
$mysqli=null;
exit;
}
echo "ok";
$mysqli->close;
phpinfo();
?>
(7)安裝wordpress
步驟和CentOS7安裝同樣能夠參考
(8)源碼編譯安裝加速器
[root@localhost xcache-3.2.0]# phpize
#生成configure
[root@localhost xcache-3.2.0]# ./configure --enable-xcache --with-php-config=/app/php/bin/php-config
[root@localhost xcache-3.2.0]# make && make install
[root@localhost php-5.6.31]# ./configure --prefix=/app/php5 --with-mysql=/usr/local/mysql --with-openssl --with-mysqli=/usr/local/mysql/bin/mysql_config --enable-mbstring --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir=/usr --enable-xml --enable-sockets --enable-fpm --with-mcrypt --with-config-file-path=/etc/php5 --with-config-file-scan-dir=/etc/php5.d --with-bz2
[root@localhost php-5.6.31]# make && make install
(2)準備啓動腳本文件
[root@localhost php-5.6.31]# cp sapi/fpm/init.d.php-fpm.in /etc/rc.d/init.d/php-fpm
[root@localhost php-5.6.31]# chmod +x /etc/rc.d/init.d/php-fpm
[root@localhost php-5.6.31]# chkconfig --add php-fpm
(3)配置環境變量
[root@localhost php-5.6.31]# vim /etc/profile.d/php-fpm.sh
[root@localhost php-5.6.31]# source /etc/profile.d/php-fpm.sh
(4)建立主配置文件
[root@localhost etc]# mkdir /etc/php5
[root@localhost etc]# cp /usr/local/src/php-5.6.31/php.ini-production /etc/php5/php.ini
(5)準備服務配置文件
[root@localhost etc]# cp php-fpm.conf.default php-fpm.conf
(6)編輯/app/httpd24/conf/httpd.conf
取消註釋,啓用此模塊
LoadModule proxy_module modules/mod_proxy.so
LoadModule proxy_fcgi_module modules/mod_proxy_fcgi.so
在配置文件末尾追加以下
AddType Application/x-httpd-php .php
AddType Application/x-httpd-php-source .phps
ProxyRequests off
ProxyPassMatch ^/(.*\.php)$ fcgi://127.0.0.1:9000/app/httpd24/htdocs/$1
(7)啓動php-fpm服務
[root@localhost etc]# service php-fpm start
(8)測試是否能夠與mysql和httpd鏈接成功
(9)安裝wordpress
安裝過程和CentOS 7中安裝同樣,能夠參考上述過程
(10)測試性能如何
Requests per second: 579.84 [#/sec] (mean)Time per request: 17.246 [ms] (mean)Time per request: 1.725 [ms] (mean, across all concurrent requests)Transfer rate: 37900.46 [Kbytes/sec] received