注意:使用 su 或者 sudo 超級(jí)管理員權(quán)限
PHP
# 下載 php 源碼包
[root@VM_77_151_centos ~]# wget http://php.net/get/php-7.1.1.tar.gz/from/a/mirror
[root@VM_77_151_centos ~]# tar -zxvf mirror
#安裝依賴
[root@VM_77_151_centos ~]# yum install gcc gcc++ libxml2-devel
[root@VM_77_151_centos ~]# cd php-7.1.1
# --with-config-file-path=path 指定配置路徑
[root@VM_77_151_centos php-7.1.1]# ./configure --prefix=/usr/local/php \
--enable-mysqlnd --enable-opcache --enable-sockets --enable-sysvmsg \
--enable-sysvsem --enable-sysvshm --enable-shmop --enable-zip \
--enable-ftp --enable-soap --enable-xml --enable-mbstring --disable-rpath \
--disable-debug --disable-fileinfo \
--with-pdo-mysql=mysqlnd --with-pcre-regex \
--with-iconv --with-zlib --with-openssl --with-xmlrpc \
--with-curl --with-imap-ssl --with-freetype-dir --enable-fpm \
--enable-pcntl --with-mhash
[root@VM_77_151_centos php-7.1.1]# make
[root@VM_77_151_centos php-7.1.1]# make install
# 拷貝 php.ini-development 或 php.ini-production 文件 更名為到/usr/local/php7/lib目錄 更名為 php.ini
[root@VM_77_151_centos php-7.1.1]# cp php.ini-development /usr/local/php7/lib/php.ini
MySQL
# 下載 mysql 源碼包
[root@VM_77_151_centos ~]# wget https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.17.tar.gz
[root@VM_77_151_centos ~]# tar -zxvf mysql-5.7.17.tar.gz
# 安裝依賴和工具
[root@VM_77_151_centos ~]# yum install cmake gcc-c++ ncurses-devel perl-Data-Dump boost boost-doc boost-devel
[root@VM_77_151_centos ~]# cd mysql-5.7.17
[root@VM_77_151_centos mysql-5.7.17]# cmake \
-DCMAKE_INSTALL_PREFIX=/usr/local/mysql \
-DMYSQL_DATADIR=/mydata/mysql/data \
-DSYSCONFDIR=/etc \
-DMYSQL_USER=mysql \
-DWITH_MYISAM_STORAGE_ENGINE=1 \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_ARCHIVE_STORAGE_ENGINE=1 \
-DWITH_MEMORY_STORAGE_ENGINE=1 \
-DWITH_READLINE=1 \
-DMYSQL_UNIX_ADDR=/var/run/mysql/mysql.sock \
-DMYSQL_TCP_PORT=3306 \
-DENABLED_LOCAL_INFILE=1 \
-DENABLED_DOWNLOADS=1 \
-DWITH_PARTITION_STORAGE_ENGINE=1 \
-DEXTRA_CHARSETS=all \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci \
-DWITH_DEBUG=0 \
-DMYSQL_MAINTAINER_MODE=0 \
-DWITH_SSL:STRING=bundled \
-DWITH_ZLIB:STRING=bundled \
-DDOWNLOAD_BOOST=1 \
-DWITH_BOOST=/usr/share/doc/boost-doc-1.59.0/ \
-DOWNLOAD_BOOST_TIMEOUT=3600
# 或者
[root@VM_77_151_centos mysql-5.7.17]# wget http://sourceforge.net/projects/boost/files/boost/1.59.0/boost_1_59_0.tar.gz
[root@VM_77_151_centos mysql-5.7.17]# mkdir /usr/share/doc/boost-doc-1.59.0
[root@VM_77_151_centos mysql-5.7.17]# cp ./boost_1_59_0.tar.gz /usr/share/doc/boost-doc-1.59.0/
[root@VM_77_151_centos mysql-5.7.17]# make
# 如果編譯過(guò)程出現(xiàn)以下錯(cuò)誤,內(nèi)存不足壤蚜,可以建立swap分區(qū)解決
c++: internal compiler error: Killed (program cc1plus)
Please submit a full bug report,
with preprocessed source if appropriate.
See <http://bugzilla.redhat.com/bugzilla> for instructions.
make[2]: *** [sql/CMakeFiles/sql.dir/item_geofunc.cc.o] Error 4
make[1]: *** [sql/CMakeFiles/sql.dir/all] Error 2
make: *** [all] Error 2
[root@VM_77_151_centos mysql-5.7.17]# make
[100%] Built target my_safe_process
[root@VM_77_151_centos mysql-5.7.17]# make install
# 創(chuàng)建 mysql 用戶和 mysql 用戶組
[root@VM_77_151_centos ~]# groupadd -r mysql && useradd -r -g mysql -s /bin/false -M mysql
# 創(chuàng)建數(shù)據(jù)庫(kù)存放目錄,以及權(quán)限修改
[root@VM_77_151_centos mysql]# mkdir -p /usr/local/mysql/data && chown -R root:mysql /usr/local/mysql/
[root@VM_77_151_centos mysql]# chown -R mysql:mysql /usr/local/mysql/data/
[root@VM_77_151_centos mysql]# chmod -R go-rwx /usr/local/mysql/data/
# 初始化 MySQL 數(shù)據(jù)庫(kù)
[root@VM_77_151_centos bin]# /usr/local/mysql/bin/mysqld --initialize-insecure --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data
# 啟動(dòng)
[root@VM_77_151_centos bin]# /usr/local/mysql/support-files/mysql.server start
[root@VM_77_151_centos lib]# echo "/usr/local/mysql/lib" > /etc/ld.so.conf.d/mysql.conf
Apache
[root@VM_77_151_centos ~]# wget http://mirror.bit.edu.cn/apache//httpd/httpd-2.4.25.tar.gz
[root@VM_77_151_centos ~]# tar -zxvf httpd-2.4.25.tar.gz
# 安裝依賴 apr apr-util pcre
[root@VM_77_151_centos ~]# wget http://archive.apache.org/dist/apr/apr-1.5.2.tar.gz
[root@VM_77_151_centos ~]# wget http://archive.apache.org/dist/apr/apr-util-1.5.4.tar.gz
[root@VM_77_151_centos ~]# tar -zxvf apr-1.5.2.tar.gz
[root@VM_77_151_centos ~]# tar -zxvf apr-util-1.5.4.tar.gz
[root@VM_77_151_centos ~]# mv apr-1.5.2 apr
[root@VM_77_151_centos ~]# mv apr-util-1.5.4 apr-util
[root@VM_77_151_centos ~]# mv apr apr-util httpd-2.4.25/srclib/
[root@VM_77_151_centos ~]# wget https://fossies.org/linux/misc/pcre-8.39.tar.gz
[root@VM_77_151_centos ~]# tar pcre-8.39.tar.gz
[root@VM_77_151_centos ~]# cd pcre-8.39
[root@VM_77_151_centos pcre-8.39]# ./configure --prefix=/usr/local/pcre-8.39
# 編譯 安裝
[root@VM_77_151_centos ~]# cd ~./httpd-2.4.25
[root@VM_77_151_centos httpd-2.4.25]# ./configure --prefix=/usr/local/apache -with-pcre=/usr/local/pcre-8.39/bin/pcre-config -with-included-apr --with-apxs2=/usr/local/apache/bin/apxs
[root@VM_77_151_centos httpd-2.4.25]# make
[root@VM_77_151_centos httpd-2.4.25]# make install
[root@VM_77_151_centos httpd-2.4.25]# cd /usr/local/apache/bin
[root@VM_77_151_centos bin]# ./apachectl -k start
# 防火墻啟動(dòng)80端口
[root@VM_77_151_centos bin]# firewall-cmd --zone=public --add-port=80/tcp --permanent
[root@VM_77_151_centos bin]# systemctl restart firewalld.service
Nginx
[root@VM_77_151_centos ~]# wget http://nginx.org/download/nginx-1.10.3.tar.gz
[root@VM_77_151_centos ~]# tar -zxvf 1.10.3.tar.gz
[root@VM_77_151_centos ~]#cd nginx-1.10.3/
[root@VM_77_151_centos nginx-1.10.3]# ./configure --prefix=/usr/local/nginx --with-pcre=../pcre-8.39
[root@VM_77_151_centos nginx-1.10.3]# make
[root@VM_77_151_centos nginx-1.10.3]# make install
[root@VM_77_151_centos nginx-1.10.3]# cd /usr/local/nginx/
# 啟動(dòng) Nginx 前先將 Apache 的進(jìn)程關(guān)閉
[root@VM_77_151_centos nginx]# ./sbin/nginx
配置PHP
# 拷貝默認(rèn)配置
[root@VM_77_151_centos sbin]# cd /usr/local/php7/etc/
[root@VM_77_151_centos etc]# cp php-fpm.conf.default php-fpm.conf
[root@VM_77_151_centos etc]# cd php-fpm.d
[root@VM_77_151_centos php-fpm.d]# cp www.conf.default www.conf
# 啟動(dòng) php-fpm
[root@VM_77_151_centos php-fpm.d]# cd /usr/local/php7/sbin/
安裝Swoole插件
#安裝依賴
[root@VM_77_151_centos ~]# yum install pcre-devel
[root@VM_77_151_centos ~]# yum install autoconf
# 下載 swoole 源碼包
tar zxf v4.2.12.tar.gz
[root@VM_77_151_centos ~]# wget https://github.com/swoole/swoole-src/archive/v4.2.12.tar.gz
[root@VM_77_151_centos ~]# tar -zxvf v4.2.12.tar.gz
# 生成 configure 文件
[root@VM_77_151_centos ~]# cd swoole-src-4.2.12
[root@VM_77_151_centos swoole-src-4.2.12]# phpize
# --with-php-config=path 指定配置文件
[root@VM_77_151_centos swoole-src-4.2.12]# ./configure --with-php-config=/usr/local/php/bin/php-config
[root@VM_77_151_centos swoole-src-4.2.12]# make
[root@VM_77_151_centos swoole-src-4.2.12]# make install
# 配置 php.ini 添加 extension=swoole
[root@VM_77_151_centos swoole-src-4.2.12]# vim /usr/local/php/lib/php.ini
extension=swoole
# 重啟 php-fpm
[root@VM_77_151_centos swoole-src-4.2.12]# ps aux | grep php-fpm
root 10040 0.0 0.1 163436 3428 ? Ss 11:08 0:00 php-fpm: master process (/usr/local/php7/etc/php-fpm.conf)
nobody 10041 0.0 0.1 163436 3036 ? S 11:08 0:00 php-fpm: pool www
nobody 10042 0.0 0.1 163436 3036 ? S 11:08 0:00 php-fpm: pool www
root 10056 0.0 0.0 112704 976 pts/5 S+ 11:10 0:00 grep --color=auto php-fpm
# kill 掉 master 主進(jìn)程 pid
[root@VM_77_151_centos swoole-src-4.2.12]# kill -USR2 10040
配置 Nginx 解析 .php 文件
[root@VM_77_151_centos nginx]# vim conf/nginx.conf
# 添加如下配置
#http {
# server {
# location ~ \.php$ {
# fastcgi_pass 127.0.0.1:9000;
# fastcgi_index index.php;
# include /usr/local/nginx/conf/fastcgi_params;
# #include fastcgi_params;
# fastcgi_split_path_info ^(.+\.php)(/.+)$;
# fastcgi_param PATH_INFO $fastcgi_path_info;
# fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info;
# fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
# }
# }
#}
# 重啟 Nginx
[root@VM_77_151_centos nginx]# sbin/nginx -s reload
參考
swap分區(qū):http://blog.csdn.net/tongyijia/article/details/50783083
參考:http://www.imooc.com/learn/703
https://typecodes.com/web/centos7compilemysql.html?utm_source=tuicool&utm_medium=referral