PHP 开发环境搭建
一 . 开发环境搭建方式大致有两种,分别是,通过apt,dnf,yum安装和手动编译。
集成环境搭建挺简单,就像windows 安装普通软件一样简单。
windows 下常见的有这么几个 `phpstudy` `wamp` `xampp`等。
linux 也有 `phpstudy`,还有 `lnmp`。这些相对简单,不用故意去写笔记,就能安装成功。
集成环境 下载地址:
二 . 我在这里主要写linux 下的 手动编译安装步骤。
1. 首先我们要下载 源码包;
下载地址:
php : http://cn2.php.net/distributions/php-7.1.10.tar.gz
nginx :http://nginx.org/download/nginx-1.12.2.tar.gz
mysql:https://dev.mysql.com/downloads/mysql/
2. 首先我们要安装依赖包,我使用的centos :所以直接使用以下命令:
yum install -y cmake 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 mcrypt libmcrypt-devel mhash libxslt-devel libiconv-devel gd-devel zlib zlib-devel openssl* pcre*
上面包括了所有依赖,如果安装不上需要尝试换源,方法是:
适用于 centos 7
cp /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.bak
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
wget -P /etc/yum.repos.d/ http://mirrors.aliyun.com/repo/epel-7.repo
yum clean all
yum makecache
3. 安装nginx
创建运行时的用户身份
groupadd www
useradd -g www www
解压 nginx 到当前目录
tar xf nginx-1.12.2.tar.gz
进入nginx 目录
cd nginx.1.12.2
# 配置nginx
./configure \
--prefix=/usr/local/nginx \
--user=www --group=www \
--with-http_ssl_module \
--with-http_stub_status_module \
--with-pcre \
# 编译安装
make -j && make install
#nginx 配置文件
/usr/local/nginx/conf/nginx.conf
# 如果需要nginx 解析php 需要先安装 php 并且配置中的 server 中写入一下配置
location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
# 整个配置类似
server {
listen 3388;
server_name localhost;
root /home/www/laravel/public;
index index.html index.php;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
index index.html index.htm index.php;
try_files $uri $uri/ /index.php?$query_string;
}
#error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
# proxy_pass http://127.0.0.1;
#}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
安装nginx的时候遇到的问题:http://blog.xyj2156.top/posts/nginx_install
4. 安装PHP
解压 :tar xf /root/data/php-7.1.10.tar.gz
进入php目录 php-7.1.10
#配置
./configure --prefix=/usr/local/php \
--with-mcrypt=/usr/local/libmcryp \
--with-openssl \
--with-pcre-regex \
--with-kerberos \
--with-libdir=lib \
--with-libxml-dir \
--with-mysql-sock \
--with-mysqli \
--with-pdo-mysql \
--with-pdo-sqlite \
--with-gd \
--with-iconv \
--with-zlib \
--with-xmlrpc \
--with-xsl \
--with-pear \
--with-gettext \
--with-curl \
--with-png-dir \
--with-jpeg-dir \
--with-freetype-dir \
--with-fpm-user=www \
--with-fpm-group=www \
--enable-mysqlnd \
--enable-zip \
--enable-inline-optimization \
--enable-shared \
--enable-libxml \
--enable-xml \
--enable-bcmath \
--enable-shmop \
--enable-sysvsem \
--enable-mbregex \
--enable-mbstring \
--enable-ftp \
--enable-gd-native-ttf \
--enable-pcntl \
--enable-sockets \
--enable-soap \
--enable-session \
--enable-opcache \
--enable-fpm \
--enable-maintainer-zts \
--enable-fileinfo
# 配置 php-fpm
*** 复制 php.ini
cp php.ini-development /usr/local/php/lib/php.ini
*** 把管理 php-fpm 的工具复制到系统服务中
cp -R sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
chmod +x /etc/init.d/php-fpm
*** 使用默认配置文件
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
#启动 php-fpm
service php-fpm start
安装php的时候遇到的问题:http://blog.xyj2156.top/posts/php_install
5. 启动完成 如果配置了nginx 开发环境搭建好了。
编辑一个文件 index.php
内容是:
<?php phpinfo();
将 上面文件放入 网站根目录 默认是: /usr/local/nginx/html/
6. 访问网址就可以了。
php 开发当然离不开好伙伴 mysql了
下面是安装过程:
cmake 配置
cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mysql \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci \
-DENABLED_LOCAL_INFILE=ON \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_FEDERATED_STORAGE_ENGINE=1 \
-DWITH_BLACKHOLE_STORAGE_ENGINE=1 \
-DWITHOUT_EXAMPLE_STORAGE_ENGINE=1 \
-DWITH_PARTITION_STORAGE_ENGINE=1 \
-DWITH_PERFSCHEMA_STORAGE_ENGINE=1 \
-DCOMPILATION_COMMENT='MySQL Jief King' \
-DWITH_READLINE=ON \
-DWITH_BOOST=/root/data/mysql-5.7.20/boost \
-DSYSCONFDIR=/usr/local/mysql/data \
-DMYSQL_UNIX_ADDR=/usr/local/mysql/mysql.sock
编译安装
make -j `grep processor /proc/cpuinfo | wc -l` && make install
评论已关闭