服务器首先要安装sshd服务,然后使用xshell等客户端连接,操作就比较方便了。
环境的安装有点麻烦的,失败的原因往往是版本问题,依赖安装不全。
多多操作几次,有问题再搜素整理即可。
安装sshd
http://blog.csdn.net/caijunfen/article/details/70599138
输入 rpm -qa |grep ssh
或者 yum list installed | grep ssh
查看当前系统是否已经安装ssh
安装 yum install sshd
或者 yum install openssh-server
重启服务不再通过 service 操作,而是通过 systemctl操作:
systemctl start xxx.service // 启动xxx服务
systemctl enable xxx.service // 设置开机自动启动
systemctl status xxx.service // 查看xxx服务启动状态
systemctl restart xxx.service // 重启xxx服务
systemctl stop xxx.service // 停止xxx服务
安装数据库MariaDb(Mysql)
http://www.thinkphp.cn/topic/45616.html
yum install mariadb-server mariadb //安装
systemctl start mariadb.service //启动
cp /usr/share/mysql/my-huge.cnf /etc/my.cnf //配置
mysql_secure_installation //修改root密码
mysql -u root -p //登录
source /tmp/xxx.sql //导入数据,可能事先需要create database xxx;use xxx;
安装php7
http://www.cnblogs.com/719907411hl/p/6891061.html
yum remove php* //卸载已有的php
yum简单安装:没有找到pfm
yum -y install epel-release //安装epel-release
rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm //修改php7的yum源
yum install php70w.x86_64 php70w-cli.x86_64 php70w-common.x86_64 php70w-gd.x86_64 php70w-ldap.x86_64 php70w-mbstring.x86_64 php70w-mcrypt.x86_64 php70w-mysql.x86_64 php70w-pdo.x86_64 //安装php7和组件,其中X86_64可以省略
编译安装
http://www.jianshu.com/p/246ffcd5e77d
去 http://php.net/downloads.php 查找最新稳定版,找中国源
wget -O php7.tar.gz http://cn2.php.net/get/php-7.0.22.tar.gz/from/this/mirror //下载最新稳定版
tar -xvf php7.tar.gz //解压
cd php-7.0.22 //进入安装目录
yum install libxml2 libxml2-devel openssl openssl-devel bzip2 bzip2-devel libcurl libcurl-devel libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel gmp gmp-devel libmcrypt libmcrypt-devel readline readline-devel libxslt libxslt-devel //安装依赖包
如果内存不足,可以使用虚拟内存
http://blog.csdn.net/taiyang1987912/article/details/41695895
编译:
./configure \
--prefix=/usr/local/php \
--with-config-file-path=/etc \
--enable-fpm \
--with-fpm-user=nginx \
--with-fpm-group=nginx \
--enable-inline-optimization \
--disable-debug \
--disable-rpath \
--enable-shared \
--enable-soap \
--with-libxml-dir \
--with-xmlrpc \
--with-openssl \
--with-mcrypt \
--with-mhash \
--with-pcre-regex \
--with-sqlite3 \
--with-zlib \
--enable-bcmath \
--with-iconv \
--with-bz2 \
--enable-calendar \
--with-curl \
--with-cdb \
--enable-dom \
--enable-exif \
--enable-fileinfo \
--enable-filter \
--with-pcre-dir \
--enable-ftp \
--with-gd \
--with-openssl-dir \
--with-jpeg-dir \
--with-png-dir \
--with-zlib-dir \
--with-freetype-dir \
--enable-gd-native-ttf \
--enable-gd-jis-conv \
--with-gettext \
--with-gmp \
--with-mhash \
--enable-json \
--enable-mbstring \
--enable-mbregex \
--enable-mbregex-backtrack \
--with-libmbfl \
--with-onig \
--enable-pdo \
--with-mysqli=mysqlnd \
--with-pdo-mysql=mysqlnd \
--with-zlib-dir \
--with-pdo-sqlite \
--with-readline \
--enable-session \
--enable-shmop \
--enable-simplexml \
--enable-sockets \
--enable-sysvmsg \
--enable-sysvsem \
--enable-sysvshm \
--enable-wddx \
--with-libxml-dir \
--with-xsl \
--enable-zip \
--enable-mysqlnd-compression-support \
--with-pear \
--enable-opcache
make && make install //安装,等待一段时间(10分钟左右)
php -v //验证
php -m //查看php的组件(模块)
//配置环境变量
vim /etc/profile
//在末尾追加
PATH=$PATH:/usr/local/php/bin
export PATH
//执行命令改动生效
source /etc/profile
//配置php-fpm
cp php.ini-production /etc/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 sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
chmod +x /etc/init.d/php-fpm
//启动php-fpm
/etc/init.d/php-fpm start
vim /etc/php.ini
// 配置时区,把前面的分号去掉
;date.timezone => date.timezone = PRC
;cgi.fix_pathinfo=1 => cgi.fix_pathinfo=0
//添加sock路径
pdo_mysql.default_socket= /var/lib/mysql/mysql.sock
PHP连接MariaDB
确保PDO和pdo_mysql组件安装,编写pdo.php:
<?php
//修改密码、数据库、表等
try {
$pdo = new PDO("mysql:host=localhost;dbname=db_demo", "root", "password");
$rs = $pdo->query("select * from test");
while($row = $rs->fetch()) {
print_r($row);
}
} catch(\Exception $e) {
echo $e;
}
安装nginx
yum install nginx //安装
systemctl start nginx.service //启动服务
netstat -anpo|grep 80 //查看端口和进程
配置/etc/nginx/nginx.conf:
location / {
index index.php index.html index.htm;
}
location ~* \.php$ {
fastcgi_index index.php;
fastcgi_pass 127.0.0.1:9000;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param SCRIPT_NAME $fastcgi_script_name;
}
重启nginx
/usr/sbin/nginx -s reload
或者systemctl restart nginx.service
创建测试文件
cd /usr/share/nginx/html
echo "<?php phpinfo(); ?>" >> index.php
访问http://localhost 或者curl http://localhost
nginx其他配置参看:http://www.jianshu.com/p/d5114a2a2052