PHP开发快三年了,本地机器都是windows,安装集成环境,线上服务器我没有权限碰,以前也做一点,但是都比较乱,最近鼓足勇气,开始在虚拟机里搭建,经过两天的艰苦奋斗,终于跑起来了,也算是告一段落了,把这几天的东西整理了一下:
系统环境 Linux Ubuntu 15.04
准备工作:
安装系统组件、必备软件包等
sudo apt-get install build-essential gcc g++ autoconf libiconv-hook-dev libmcrypt-dev libxml2-dev libmysqlclient-dev libcurl4-openssl-dev libjpeg8-dev libpng12-dev libfreetype6-dev cmake libncurses5-dev bison libpcre3-dev wget
下载MySQL、PHP、nginx、openssl
wget http://www.openssl.org/source/openssl-1.0.0s.tar.gz
wget http://cn2.php.net/distributions/php-5.6.14.tar.gz
wget http://nginx.org/download/nginx-1.8.0.tar.gz
sudo wget http://mysql.mirror.kangaroot.net/Downloads/MySQL-5.6/mysql-5.6.26.tar.gz
安装openssl;(用sudo apt-get install openssl libssl-dev 后,编译PHP还是会报错找不到openssl)
tar -zxvf openssl-1.0.0s.tar.gz
cd openssl-1.0.0s
./config
sudo make
sudo make install
编译安装MySQL
先安装MySQL吧,装PHP的时候,会用到MySQL的安装路径
创建用户及组,
sudo groupadd mysql
sudo useradd -g mysql mysql -s /bin/false
创建安装目录和数据存放目录,并修改权限
sudo mkdir -p /usr/local/mysql/data
sudo chown -R mysql:mysql /usr/local/mysql
解压编译安装
tar -zxvf mysql-5.6.26.tar.gz
cd mysql-5.6.26/
存在这个文件就删除
rm CMakeCache.txt
cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_DATADIR=/usr/local/mysql/data -DMYSQL_UNIX_ADDR=/tmp/mysql.sock -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DWITH_DEBUG=0
sudo make
sudo make install
修改安装完成后文件的所有者和组
sudo chown -R mysql:mysql /usr/local/mysql
复制配置文件模板到/etc
sudo cp /usr/local/mysqlsupport-files/my-default.cnf /etc/my.cnf
修改配置文件
sudo vim /etc/my.cnf
basedir = /usr/local/mysql/
datadir = /usr/local/mysql/data
socket = /tmp/mysql.sock
将启动和cli脚本软连接到系统变量,方便使用
sudo ln -s /usr/local/mysql/bin/mysql /usr/bin
sudo ln -s /usr/local/mysql/bin/mysqladmin /usr/bin
sudo ln -s /usr/local/mysql/support-files/mysql.server /usr/bin
初始化数据库,创建基本数据库
sudo /usr/local/mysql/scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --no-defaults
为root用户创建密码
sudo /usr/local/mysql/bin/mysqladmin -u root password '123'
启动服务
sudo mysql.server start
查看启动进程
sudo netstat -lntup | grep 3306
登录MySQL服务器
mysql -uroot -p
编译安装PHP
cd ~
解压编译安装
tar -zxvf php-5.6.14.tar.gz
cd php-5.6.14
./configure —help(查看可编译参数的详细介绍)
./configure --prefix=/usr/local/php --with-config-file-path=/etc --enable-fpm --enable-cli --enable-pcntl --enable-sockets --enable-opcache --enable-sysvsem --enable-sysvmsg --enable-sysvshm --enable-shmop --enable-zip --enable-ftp --disable-rpath --disable-debug --with-pcre-regex --with-mcrypt --enable-xml --with-openssl --with-imap-ssl --enable-soap --with-iconv --with-curl --disable-fileinfo --with-xmlrpc --enable-fastcgi --enable-fastCGI --with-mhash --with-gd --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir=/usr --disable-rpath --enable-bcmath --enable-inline-optimization --enable-mbregex--enable-mbstring --enable-gd-native-ttf --with-ldap-sasl --enable-pdo --with-pdo-mysql --with-mysql=/usr/local/mysql --with-mysqli=/usr/bin/mysql_config --with-pear
(这些一般也就够用了)
sudo make
sudo make install
创建php配置文件
sudo cp ~/php-5.6.14/php.ini-development /etc/php.ini
创建php-fpm配置文件
sudo cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf
sudo cp /usr/local/php/etc/php-fpm.d/www.conf.default /usr/local/php/etc/php-fpm.d/www.conf
创建php-fpm的运行账户
sudo groupadd nobody
加入系统变量
sudo ln -s /usr/local/php/bin/php /usr/bin
sudo ln -s /usr/local/php/bin/phpize /usr/bin
sudo ln -s /usr/local/php/sbin/php-fpm /usr/bin
测试PHP和php-fpm运行
php -i
sudo php-fpm
编译安装Nginx
cd ~
解压编译安装
tar -zxvf nginx-1.8.0.tar.gz
cd nginx-1.8.0
./configure --prefix=/usr/local/nginx
sudo make
sudo make install
加入系统环境变量
sudo ln -s /usr/local/nginx/sbin/nginx /usr/bin/
修改nginx配置文件支持PHP
sudo vim /usr/local/nginx/conf/nginx.conf
65 location ~ \.php$ {
66 root html;
67 fastcgi_pass 127.0.0.1:9000;
68 fastcgi_index index.php;
69 fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
70 include fastcgi_params;
71 }
重新加载配置文件
sudo nginx / sudo nginx -s reload
Ubuntu15.04下搭建LNMP环境:http://www.linuxdiyf.com/linux/13025.html
CentOS/Debian/Ubuntu系统一键安装LNMP/LAMP/LNMPA网站环境:http://www.linuxdiyf.com/linux/13084.html
Ubuntu 14.04搭建LNMP:http://www.linuxdiyf.com/linux/11900.html
CentOS 7源码安装最新版LNMP环境:http://www.linuxdiyf.com/linux/10839.html
Ubuntu 14.04 LTS安装LNMP NginxPHP5(PHP-FPM)MySQL:http://www.linuxdiyf.com/linux/10659.html