centOS 编译搭建php7.2 nginx mysql
第一步先更新centOs
yum update //必须在root下
安装编译需要的库
yum install -y gcc gcc-c++ make zlib zlib-devel pcre pcre-devel libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2
libxml2-devel glibc glibc-devel glib2 glib2-devel bzip2 bzip2-devel ncurses ncurses-devel curl curl-devel e2fsprogs e2fsprogs-devel krb5 krb5-devel openssl openssl-devel openldap openldap-devel nss_ldap openldap-clients openldap-servers perl* httpd-devel postgresql-devel
libxslt-devel
cd /usr/local/src/ 把下载的包放在下面
开始搭建环境
1. 下载编译php7.2 nginx mgsql5.7
下载php7.2
wget http://cn2.php.net/distributions/php-7.2.0.tar.gz
下载nginx最新版
wget http://nginx.org/download/nginx-1.13.7.tar.gz
下载mysql5.7
wget https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.20-linux-glibc2.12-x86_64.tar.gz
2.下载pcre(支持nginx 伪静态)
wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.41.tar.gz
tar -xzvf pcre-8.41.tar.gz
cd pcre-8.41
./configure --prefix=/usr/local/pcre #配置
make && make install #编译安装
3.安装cmake (用于编译c++)
wget https://cmake.org/files/v3.10/cmake-3.10.1.tar.gz
tar -xzvf cmake-3.10.1.tar.gz
cd cmake-3.10.1
./bootstrap
gmake && gmake install
解压php nginx mysql
4.开始安装php7.20
./configure --prefix=/usr/local/php
\
--with-curl \
--with-freetype-dir \
--with-gd \
--with-gettext \
--with-iconv-dir \
--with-kerberos \
--with-libdir=lib64 \
--with-libxml-dir \
--with-mysqli \
--with-openssl \
--with-pcre-regex \
--with-pdo-mysql \
--with-pdo-sqlite \
--with-pear \
--with-png-dir \
--with-xmlrpc \
--with-xsl \
--with-zlib \
--enable-fpm \
--enable-bcmath \
--enable-libxml \
--enable-inline-optimization \
--enable-gd-native-ttf \
--enable-mbregex \
--enable-mbstring \
--enable-opcache \
--enable-pcntl \
--enable-shmop \
--enable-soap \
--enable-sockets \
--enable-sysvsem \
--enable-xml \
--enable-zip
这说明php环境已经检测通过了,下面开始安装php
make &&make install 编译安装 (我们就静静地等待吧)
这样就成功了!!!!!!!
cp php.ini-development /usr/local/php/lib/php.ini
cp/usr/local/php/etc/php-fpm.conf.default
/usr/local/php/etc/php-fpm.conf
cp /usr/local/php/etc/php-fpm.d/www.conf.default /usr/local/php/etc/php-fpm.d/www.conf
cp -R /usr/local/src/php-7.2.0/sapi/fpm/php-fpm /etc/init.d/php-fpm
#把pid
改成 /run/php-fpm.pid
vim /usr/local/php7/etc/php-fpm.conf添加服务
vim /etc/systemd/system/php-fpm.service[Unit]
Description=The PHP FastCGI Process Manager
After=syslog.target network.target
[Service]
Type=simple
PIDFile=/run/php-fpm.pid
ExecStart=/usr/local/php/sbin/php-fpm --nodaemonize --fpm-config /usr/local/php/etc/php-fpm.conf
ExecReload=/bin/kill -USR2 $MAINPID
ExecStop=/bin/kill -SIGINT $MAINPID
[Install]
WantedBy=multi-user.target
启动php-fpm
systemctl start php-fpm.service
systemctl status php-fpm.service
这样php就编译成功了
添加到开机启动
systemctl enable php-fpm.service
修改 php.ini 文件 设置 expose_php = Off vim /usr/local/php/lib/php.ini 找到 expose_php = On 改为 expose_php = Off
5. 下面编译nginx
cd /usr/local/src/nginx-1.13.7
同样执行 make && make install
vi /etc/init.d/nginx
#!
/bin/bash
#
chkconfig: - 85 15
PATH=/usr/local/nginx
DESC=
"nginx
daemon"
NAME=nginx
DAEMON=
$PATH
/sbin/
$NAME
CONFIGFILE=
$PATH
/conf/
$NAME
.conf
PIDFILE=
$PATH
/logs/
$NAME
.pid
SCRIPTNAME=/etc/init.d/
$NAME
set
-e
[
-x
"$DAEMON"
] || exit 0
do_start()
{
$DAEMON
-c
$CONFIGFILE
||
echo
-n
"nginx already running"
}
do_stop()
{
$DAEMON
-s
stop ||
echo
-n
"nginx not running"
}
do_reload()
{
$DAEMON
-s
reload ||
echo
-n
"nginx can't reload"
}
case
"$1"
in
start)
echo
-n
"Starting $DESC: $NAME"
do_start
echo
"."
;;
stop)
echo
-n
"Stopping $DESC: $NAME"
do_stop
echo
"."
;;
reload|graceful)
echo
-n
"Reloading $DESC configuration..."
do_reload
echo
"."
;;
restart)
echo
-n
"Restarting $DESC: $NAME"
do_stop
do_start
echo
"."
;;
*)
echo
"Usage: $SCRIPTNAME {start|stop|reload|restart}"
>&2
exit
3
;;
esac
exit
0
chmod a+x /etc/init.d/nginx
注册服务
chkconfig
--add nginx
设置开机启动
chkconfig nginx on
#启动nginx服务
systemctl start nginx.service
#停止nginx服务
systemctl stop nginx.service
#重启nginx服务
systemctl restart nginx.service
#重新读取nginx配置(这个最常用, 不用停止nginx服务就能使修改的配置生效)
systemctl reload nginx.service
这样nginx 也成功了
报错: [21-Dec-2017 16:08:42] ERROR: [pool www] please specify user and group other than root
解决 : adduser nginx # 添加用户
groupadd nginx #添加用户组
useradd -g nginx nginx #新建用户同时增加工作组
vim vim /usr/local/php/etc/php-fpm.d/www.conf #修改
user = nginx
group = nginx 然后保存
========安装mysql
groupadd
-r mysql
useradd -g mysql -r -s /sbin/nologin mysql #添加mysql 用户
mv mysql-5.7.20-linux-glibc2.12-x86_64 /usr/local/mysql #移动
./bin/mysqld --user=mysql
--basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --initialize
Note:是我们的临时密码;
cp support-files/mysql.server /etc/init.d/mysqld #加入系统进程
echo 'PATH=/usr/local/mysql/bin/:$PATH' >> /etc/profile #写入环境变量
source /etc/profile #让配置生效
chkconfig mysqld on #开机启动
mysql -u root -p #进入数据库
update
mysql.
user
set
authentication_string=
password
(
'123qwe'
)
where
user
=
'root'
and
Host
=
'localhost'
; #修改密码
flush
privileges
;
#立刻生效
quit; 退出