一. 源碼安裝php7.2php
選擇須要的php版本html
.tar.gz
的下載包,點擊進入,選擇中國的本地語言包,複製這個下載地址最後獲得的下載的地址就是:
http://cn2.php.net/get/php-7.2.0.tar.gz/from/this/mirror
(參照這個方法就能夠隨時獲取最新版本的PHP了)
2.下載php源碼mysql
cd /usr/src/
wget http://cn2.php.net/get/php-7.2.0.tar.gz/from/this/mirror
php-7.2.0.tar.gz
相似的壓縮文件,而是一個mirror的文件,很簡單,咱們給文件重命名就能夠了 mv mirror php-7.2.0.tar.gz
yum install gcc
yum install libxml2
yum install libxml2-devel yum install openssl openssl-devel yum -y install curl-devel yum install libjpeg.x86_64 libpng.x86_64 freetype.x86_64 libjpeg-devel.x86_64 libpng-devel.x86_64 freetype-devel.x86_64 -y yum install bzip2-devel.x86_64 -y yum install libXpm-devel yum install gmp-devel yum install -y icu libicu libicu-devel yum install php-mcrypt libmcrypt libmcrypt-devel yum install postgresql-devel yum install libxslt-devel
4.解壓編譯 tar -xzxvf php-7.2.0.tar.gz
cd php-7.2.0
設置編譯須要加載的模塊 ./configure --prefix=/usr/local/php --with-pdo-pgsql --with-zlib-dir --with-freetype-dir --enable-mbstring --with-libxml-dir=/usr --enable-soap --enable-calendar --with-curl --with-mcrypt --with-gd --with-pgsql --disable-rpath --enable-inline-optimization --with-bz2 --with-zlib --enable-sockets --enable-sysvsem --enable-sysvshm --enable-pcntl --enable-mbregex --enable-exif --enable-bcmath --with-mhash --enable-zip --with-pcre-regex --with-pdo-mysql --with-mysqli --with-jpeg-dir=/usr --with-png-dir=/usr --enable-gd-native-ttf --with-openssl --with-fpm-user=www-data --with-fpm-group=www-data --with-libdir=/lib/x86_64-linux-gnu/--enable-ftp --with-gettext --with-xmlrpc --with-xsl --enable-opcache --enable-fpm --with-iconv --with-xpm-dir=/usr
linux
編譯: make clean && make && make install
5. 複製配置文件 cp php.ini-development /usr/local/php/lib/php.ini
6. 設置全局的php命令 vim /etc/profile
在文件最後添加:nginx
PATH=$PATH:/usr/local/php/bin export PATH
而後執行 命令 source /etc/profile
此時php就是全局命令了,能夠經過php -v
查看php版本信息或者php -m
看看剛剛編譯加載的模塊了sql
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 /usr/src/php-7.2.0/sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm chmod +x /etc/init.d/php-fpm
新建www-data 用戶組:vim
groupadd www-data useradd -g www-data www-data
啓動php-fpm /etc/init.d/php-fpm start
(可選)配置php-fpm自啓動,若是存在這個文件,這步省略
建立php-fpm啓動腳本api
vim /etc/init.d/php-fpm
插入以下內容:ruby
#!/bin/sh # chkconfig: 2345 15 95 # description: PHP-FPM (FastCGI Process Manager) is an alternative PHP FastCGI implementation \ # with some additional features useful for sites of any size, especially busier sites. # DateTime: 2016-09-20 # Source function library. . /etc/rc.d/init.d/functions # Source networking configuration. . /etc/sysconfig/network # Check that networking is up. [ "$NETWORKING" = "no" ] && exit 0 phpfpm="/usr/local/php/sbin/php-fpm" prog=$(basename ${phpfpm}) lockfile=/var/lock/subsys/phpfpm start() { [ -x ${phpfpm} ] || exit 5 echo -n $"Starting $prog: " daemon ${phpfpm} retval=$? echo [ $retval -eq 0 ] && touch $lockfile return $retval } stop() { echo -n $"Stopping $prog: " killproc $prog -QUIT retval=$? echo [ $retval -eq 0 ] && rm -f $lockfile return $retval } restart() { configtest || return $? stop start } reload() { configtest || return $? echo -n $"Reloading $prog: " killproc ${phpfpm} -HUP RETVAL=$? echo } force_reload() { restart } configtest() { ${phpfpm} -t } rh_status() { status $prog } rh_status_q() { rh_status >/dev/null 2>&1 } case "$1" in start) rh_status_q && exit 0 $1 ;; stop) rh_status_q || exit 0 $1 ;; restart|configtest) $1 ;; reload) rh_status_q || exit 7 $1 ;; status) rh_status ;; *) echo $"Usage: $0 {start|stop|status|restart|reload|configtest}" exit 2 esac
添加到開機啓動項 chkconfig --add php-fpm
bash
此時也可使用service來啓動php-fpm了
service php-fpm start service php-fpm stop
2、yum安裝nginx
1. 執行yum安裝命令 yum install nginx
關於yum安裝nginx的一些位置說明:
http://www.javashuo.com/article/p-eepnkmbx-hr.html
2. 修改配置文件已支持php cd /etc/nginx/
刪掉本來的nginx.conf,複製一份nginx.conf.default的默認配置
rm -rf nginx.conf cp nginx.conf.default nginx.conf vim nginx.conf
server裏面的配置:
在location / 的中index增長index.php ,增長URL重寫讀取;
解開location ~ .php$的註釋,修改fastcgi的路徑,最終server部分配置內容爲:
server {
listen 80; server_name localhost; #charset koi8-r; #access_log logs/host.access.log main; location / { root html; # 修改1:這裏新增了index.php index index.html index.htm index.php; # 修改2:這裏新增url重寫(path) try_files $uri $uri/ /index.php$is_args$args; } #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 # #修改3:解開php支持的註釋 location ~ \.php$ { root html; #默認就使用php-fpm fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; #修改4:修改fastcig的路徑 fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; } # deny access to .htaccess files, if Apache's document root # concurs with nginx's one # #location ~ /\.ht { # deny all; #} }
保存配置文件。
3.啓動nginx service nginx start
4.(可選)設置nginx開機自啓動
建立nginx啓動命令腳本 vi /etc/init.d/nginx
插入如下內容:
#! /bin/bash # chkconfig: - 85 15 PATH=/usr/local/nginx DESC="nginx daemon" NAME=nginx DAEMON=$PATH/sbin/$NAME CONFIGFILE=$PATH/conf/$NAME.conf PIDFILE=$PATH/logs/$NAME.pid SCRIPTNAME=/etc/init.d/$NAME set -e [ -x "$DAEMON" ] || exit 0 do_start() { $DAEMON -c $CONFIGFILE || echo -n "nginx already running" } do_stop() { $DAEMON -s stop || echo -n "nginx not running" } do_reload() { $DAEMON -s reload || echo -n "nginx can't reload" } case "$1" in start) echo -n "Starting $DESC: $NAME" do_start echo "." ;; stop) echo -n "Stopping $DESC: $NAME" do_stop echo "." ;; reload|graceful) echo -n "Reloading $DESC configuration..." do_reload echo "." ;; restart) echo -n "Restarting $DESC: $NAME" do_stop do_start echo "." ;; *) echo "Usage: $SCRIPTNAME {start|stop|reload|restart}" >&2 exit 3 ;; esac exit 0
設置執行權限 chmod a+x /etc/init.d/nginx
註冊成服務 chkconfig --add nginx
設置開機啓動 chkconfig nginx on
重啓查看nginx服務是否自動啓動(!!! 請確保重啓不會影響現有業務,如不肯定請不要執行,後果自負)
shutdown -h 0 -r netstat -apn|grep nginx
配置nginx成服務還有一個好處就是能夠直接經過systemctl或者service直接啓動或中止nginx了,例如 systemctl stop nginx 或者 service nginx stop就能夠中止nginx了
3、編寫測試文件 vim /usr/share/nginx/html/phpinfo.php
好比編輯一個phpinfo
<?php phpinfo();
最後就能夠訪問剛剛這個文件了
4、yum安裝mysql5.7
如下內容轉載自:http://www.javashuo.com/article/p-ywzsdybe-bq.html
第一步:獲取mysql YUM源
進入mysql官網獲取RPM包下載地址
https://dev.mysql.com/downloads/repo/yum/
右擊 複製連接地址 https://dev.mysql.com/get/mysql57-community-release-el7-11.noarch.rpm
獲得這個 這個就是Yum倉庫的rpm包 其實就是一個下載地址
第二步:下載和安裝mysql源
先下載 mysql源安裝包
wget https://dev.mysql.com/get/mysql57-community-release-el7-11.noarch.rpm
安裝mysql源
yum -y localinstall mysql57-community-release-el7-11.noarch.rpm
第三步:在線安裝Mysql
yum -y install mysql-community-server
第四步:啓動Mysql服務
systemctl start mysqld
(service mysqld start 也行)
第五步:設置開機啓動
systemctl enable mysqld
systemctl daemon-reload
第六步:修改root本地登陸密碼
mysql安裝完成以後,在/var/log/mysqld.log文件中給root生成了一個臨時的默認密碼。
[root@localhost ~]# vi /var/log/mysqld.log
這裏的臨時密碼 eMV.R#mWe3ha
[root@localhost ~]# mysql -u root -p
Enter password:
輸入臨時密碼 進入mysql命令行;
mysql> ALTER USER ‘root’@’localhost’ IDENTIFIED BY ‘ZhipengWang2012@’;
Query OK, 0 rows affected (0.00 sec)
修改密碼爲 ZhipengWang2012@ (備註 mysql5.7默認密碼策略要求密碼必須是大小寫字母數字特殊字母的組合,至少8位)
第七步:設置容許遠程登陸
Mysql默認不容許遠程登陸,咱們須要設置下,而且防火牆開放3306端口;
mysql> GRANT ALL PRIVILEGES ON . TO ‘root’@’%’ IDENTIFIED BY ‘ZhipengWang2012@’ WITH GRANT OPTION;
Query OK, 0 rows affected, 1 warning (0.01 sec)
mysql> exit;
Bye
這裏其實最好新建一個用戶: GRANT ALL PRIVILEGES ON *.* TO 'adduser'@'%' IDENTIFIED BY 'zyytest12!' WITH GRANT OPTION;
開放3306端口 firewall-cmd --zone=public --add-port=3306/tcp --permanent
重啓防火牆 firewall-cmd --reload
第八步:配置默認編碼爲utf8
修改/etc/my.cnf配置文件,在[mysqld]下添加編碼配置,以下所示:
[mysqld]
character_set_server=utf8
init_connect=’SET NAMES utf8’ vi /etc/my.cnf
編輯保存完 重啓mysql服務; systemctl restart mysqld
end