centos7安装lnmp环境(php版本比较老)

683 阅读2分钟

一.系统初始化

1.1 更新系统(以前在这步不是必须,因为内核漏洞的问题,该步骤必须)

yum -y update
reboot

1.2 系统初始化(包括防火墙,iptables,部分其他初始设置)

echo SELINUX=disabled>/etc/selinux/config
echo SELINUXTYPE=targeted>>/etc/selinux/config
echo "*               soft   nofile            65535" >> /etc/security/limits.conf
echo "*               hard   nofile            65535" >> /etc/security/limits.conf
yum install -y iptables-services
systemctl  stop  firewalld
systemctl disable firewalld.service
systemctl enable iptables.service
iptables -F
iptables-save >/etc/sysconfig/iptables

1.3 安装工具软件

yum install -y iproute rsync epel-release vim-enhanced wget curl screen net-tools

二.安装最新稳定版nginx

rpm -ivh http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm
yum -y install nginx
systemctl enable nginx
systemctl start nginx
nginx -v

三.安装mysql 5.6

wget http://repo.mysql.com/mysql-community-release-el7-5.noarch.rpm
rpm -ivh mysql-community-release-el7-5.noarch.rpm
yum repolist all | grep mysql
yum install -y mysql-community-server mysql-community-devel
##修复默认的2个警告
echo "LimitNOFILE=65535" >>  /usr/lib/systemd/system/mysqld.service
#增加一行
#"explicit_defaults_for_timestamp=true" 到/etc/my.cnf mysqld下面
systemctl daemon-reload
systemctl enable mysqld 
systemctl start mysqld 

四.安装php5.3

4.1 安装php

yum install -y gcc zlib-devel freetype-devel gd-devel libmcrypt-devel curl-devel libtool libxml2-devel gdbm-devel libjpeg-devel libpng-devel curl-devel libc-client libtidy pcre-devel openssl-devel net-snmp net-snmp-devel net-snmp-utils net-snmp-libs libevent-devel mhash-devel patch  libtool-ltdl-devel

wget https://www.php.net/distributions/php-5.3.29.tar.gz
tar xvf php-5.3.29.tar.gz
cd php-5.3.29
./configure --prefix=/usr/local/php-5.3.29 --with-libdir=lib64 --with-png-dir --with-jpeg-dir --with-gd --with-freetype-dir --with-mcrypt --with-config-file-path=/etc --disable-debug --enable-sockets --enable-calendar --enable-ftp --enable-gd-native-ttf --with-gdbm --with-gettext --with-iconv --enable-mbstring --with-openssl --with-curl --enable-bcmath --enable-exif --with-pdo-mysql --with-snmp --with-mysqli --enable-zip --with-zlib --with-mhash --enable-xml --with-xmlrpc --with-mysql --enable-fpm --with-fpm-user=nginx --with-fpm-group=nginx
make
make install

4.2设置php开机启动

ln -s /usr/local/php-5.3.29/ /usr/local/php
cat <<EOF >  /usr/lib/systemd/system/php-fpm.service 
[Unit]
Description=The PHP FastCGI Process Manager
After=network.target

[Service]
Type=forking
ExecStart=/usr/local/php/sbin/php-fpm
PrivateTmp=true

[Install]
WantedBy=multi-user.target

EOF
mv /usr/local/php/etc/php-fpm.conf.default  /usr/local/php/etc/php-fpm.conf
systemctl daemon-reload
systemctl enable php-fpm
systemctl start php-fpm

五.重启验证

netstat -lnp|egrep  "80|3306|9000"
ps -ef |egrep "php-fpm|nginx|mysql"