php 必备linux环境搭建

我用的是阿里云 centos7.2

虽然说yum安装比较快,但是我更喜欢编译安装,这样比较能理解你的软件都安装到哪里去了。

配置的环境是 cenos7.2 + nginx1.12.2 + php7.1.11 + mysql5.7.20

第一波 目录创建

mkdir /alidata

mkdir /alidata/package

//运行程序所在的目录
mkdir –p /alidata/server

//网站根目录
mkdir –p /alidata/webapps
mkdir –p /alidata/logs

第二波 软件安装

make : yum -y install gcc automake autoconf libtool make

g++  : yum install gcc gcc-c++ glibc


php模块 : yum -y install libmcrypt-devel mhash-devel libxslt-devel libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel zlib zlib-devel glibc glibc-devel glib2 glib2-devel bzip2 bzip2-devel ncurses ncurses-devel curl curl-devel e2fsprogs e2fsprogs-devel krb5 krb5-devel libidn libidn-devel openssl openssl-devel


mysql必备 : yum install libaio*

第三波 软件下载

pcre : wget https://sourceforge.net/projects/pcre/files/pcre/8.41/pcre-8.41.tar.gz

zlib : wget https://sourceforge.net/projects/libpng/files/zlib/1.2.11/zlib-1.2.11.tar.gz

openssl : wget https://www.openssl.org/source/openssl-1.1.0b.tar.gz

nginx : wget http://nginx.org/download/nginx-1.12.2.tar.gz


php : wget http://cn2.php.net/distributions/php-7.1.11.tar.gz


cmake : wget https://cmake.org/files/v3.10/cmake-3.10.0-rc5.tar.gz

ncurses : wget http://ftp.gnu.org/gnu/ncurses/ncurses-6.0.tar.gz

第四波 添加用户组和用户

groupadd www
useradd -r -g www www

groupadd mysql
useradd -r -g mysql mysql

第五波 开始编译安装

//nginx的编译安装
./configure --prefix=/alidata/server/nginx-1.12.2 --sbin-path=/alidata/server/nginx-1.12.2/sbin/nginx --conf-path=/alidata/server/nginx-1.12.2/nginx.conf --pid-path=/alidata/server/nginx-1.12.2/nginx.pid --user=www --group=www --with-http_ssl_module --with-http_flv_module --with-http_mp4_module  --with-http_stub_status_module --with-select_module --with-poll_module --error-log-path=/alidata/logs/nginx/error.log --http-log-path=/alidata/logs/nginx/access.log  --with-pcre=/root/pcre-8.41 --with-zlib=/root/zlib-1.2.11 --with-openssl=/root/openssl-1.1.0b
make && make install


//php的编译安装
./configure --prefix=/alidata/server/php-7.1.11 --with-config-file-path=/alidata/server/php-7.1.11/etc --enable-fpm --with-mcrypt --enable-mbstring --enable-pdo --with-curl --disable-debug  --disable-rpath --enable-inline-optimization --with-bz2  --with-zlib --enable-sockets --enable-sysvsem --enable-sysvshm --enable-pcntl --enable-mbregex --with-mhash --enable-zip --with-pcre-regex --with-mysqli --with-gd --with-jpeg-dir --with-freetype-dir --enable-calendar
make && install


//cmake的编译安装
./configure --prefix=/alidata/package/cmake
make && install


//ncurses的编译安装
./configure --prefix=/alidata/package/ncurses
make && install

//mysql初始化
/alidata/server/mysql-5.7.20/bin/mysqld –initialize –user=mysql –basedir=/alidata/server/mysql-5.7.20/ –datadir=/alidata/server/mysql-5.7.20/data/

第六波 设置配置文件

//nginx多域名配置

//nginx.conf

user  www www;
worker_processes  2;

error_log  /alidata/logs/nginx/error.log crit;

pid        /alidata/server/nginx-1.12.2/logs/nginx.pid;
worker_rlimit_nofile 65535;

events {
    use epoll;
    worker_connections  65535;
}

http {
    include       mime.types;
default_type  application/octet-stream;

access_log  /alidata/logs/nginx/access.log;

server_names_hash_bucket_size 128;
client_header_buffer_size 32k;
large_client_header_buffers 4 32k;
client_max_body_size 8m;

sendfile        on;
tcp_nopush     on;

keepalive_timeout  65;

gzip  on;
gzip_min_length  1k;
gzip_buffers     4 16k;
gzip_http_version 1.0;
gzip_comp_level 2;
gzip_types       text/plain application/x-javascript text/css application/xml;
gzip_vary on;

tcp_nodelay on;

fastcgi_connect_timeout 300;
fastcgi_send_timeout 300;
fastcgi_read_timeout 300;
fastcgi_buffer_size 64k;
fastcgi_buffers 4 64k;
fastcgi_busy_buffers_size 128k;
fastcgi_temp_file_write_size 128k;

log_format '$remote_addr - $remote_user [$time_local] "$request" '
              '$status $body_bytes_sent "$http_referer" '
              '"$http_user_agent" "$http_x_forwarded_for"';

include /alidata/server/nginx-1.12.2/conf/vhosts/*.conf;
include /alidata/server/nginx-1.12.2/conf/proxy/*.conf;
}

//虚拟主机的配置文件 /alidata/server/nginx-1.12.2/conf/vhosts/default.conf
server {
        listen       80;
        server_name  localhost;
        index index.php index.htm index.html;
        root /alidata/webapps;
        location /
        {
           if (!-e $request_filename) {
               rewrite  ^(.*)$  /index.php?s=/$1  last;
               break;
            }
         }

        location ~ .*\.(php|php5)?$
        {
                #fastcgi_pass  unix:/tmp/php-cgi.sock;
                fastcgi_pass  127.0.0.1:9000;
                fastcgi_index index.php;
                include fastcgi.conf;
        }
        location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
        {
                expires 30d;
        }
        location ~ .*\.(js|css)?$
        {
                expires 1h;
        }
        # 配置页面静态化
        include /alidata/server/nginx-1.12.2/conf/rewrite/default.conf;
        access_log  /alidata/logs/nginx/access/default.log;
        error_log /alidata/logs/nginx/error/default.log;
}

// rewrite规则 /alidata/server/nginx-1.12.2/conf/rewrite/default.conf

rewrite ^(.*)-htm-(.*)$ $1.php?$2 last;
rewrite ^(.*)/simple/([a-z0-9\_]+\.html)$ $1/simple/index.php?$2 last;
rewrite ^(.*)/data/(.*)\.(htm|php)$ 404.html last;
rewrite ^(.*)/attachment/(.*)\.(htm|php)$ 404.html last;
rewrite ^(.*)/html/(.*)\.(htm|php)$ 404.html last;

//php配置文件

cp /root/php-7.1.11/php.ini-production /alidata/server/php-7.1.11/etc/php.ini
cd /alidata/server/php-7.1.11/etc
cp php-fpm.conf.default php-fpm.conf
cd /alidata/server/php-7.1.11/etc/php-fpm.d
cp www.conf.default www.conf

// vi www.conf 修改
user = www
group = www
listen = 127.0.0.1:9000
pm.max_children = 100
pm.start_servers = 20
pm.min_spare_servers = 5
pm.max_spare_servers = 35

//mysql配置文件
[client]
port = 3306
socket = /alidata/server/mysql-5.7.20/tmp/mysql.sock
[mysqld]
basedir=/alidata/server/mysql-5.7.20
datadir=/alidata/server/mysql-5.7.20/data
socket=/alidata/server/mysql-5.7.20/tmp/mysql.sock
risks
symbolic-links=0

log-error=/alidata/logs/mysql/error.log
pid-file=/alidata/logs/mysql/mysql.pid

[mysqld_safe]
log-error=/alidata/logs/mariadb/error.log
pid-file=/alidata/logs/mariadb/mariadb.pid


!includedir /etc/my.cnf.d


//my.cnf.d目录下名为mysql-clients.cnf
[mysql]

[mysql_upgrade]

[mysqladmin]

[mysqlbinlog]

[mysqlcheck]

[mysqldump]

[mysqlimport]

[mysqlshow]

[mysqlslap]

亲测可用,有问题可以留言交流

相关推荐