阿里雲一臺服務器出現問題!php
我估計是一鍵安裝包環境的緣由,因此打算從新搭建下環境!html
首先,固然是先作好快照!安全第一!mysql
對系統盤作更換系統操做,裝上純淨版的centos。nginx
裝好後,進入系統web
1、掛載數據盤正則表達式
df -h
只有系統盤了,掛載上原來的數據盤sql
fdisk -l
看到數據盤了/dev/vdb1json
掛載上這個數據盤,vim
mkdir /data0 mount /dev/vdb1 /data0
而後寫入分區:centos
echo '/dev/vdb1 /data0 ext4 defaults 0 0' >> /etc/fstab
不寫入分區表,重啓後又要掛載的。
怎麼知道分區類型是ext4,用這個命令:
df -hT
好的成功了!
2、安裝nginx
首先更新系統軟件
# yum update
安裝nginx
1.安裝nginx源
# yum localinstall http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm
2.安裝nginx
# yum install nginx
3.啓動nginx
# service nginx start
Redirecting to /bin/systemctl start nginx.service
4.訪問http://你的ip/
若是成功安裝會出來nginx默認的歡迎界面
3、安裝MySQL5.7.*
1.安裝mysql源
# yum localinstall http://dev.mysql.com/get/mysql57-community-release-el7-7.noarch.rpm
2.安裝mysql
# yum install mysql-community-server
3.安裝mysql的開發包,之後會有用
# yum install mysql-community-devel
4.啓動mysql
# service mysqld start
Redirecting to /bin/systemctl start mysqld.service
5.查看mysql啓動狀態
# service mysqld status
出現pid
證實啓動成功
6.獲取mysql默認生成的密碼
# grep 'temporary password' /var/log/mysqld.log
選中的就是密碼。
7.換成本身的密碼
# mysql -uroot -p
Enter password:輸入上頁的密碼,進入mysql
8. 更換密碼
1
|
mysql> ALTER USER
'root'
@
'localhost'
IDENTIFIED BY
'MyNewPasdfs4!'
;
|
這個密碼必定要足夠複雜,否則會不讓你改,提示密碼不合法;
9.退出mysql並試用下新密碼
mysql> quit; mysql -uroot -p
確認密碼正確
4、編譯安裝php7.0.0
1.下載php7源碼包
# cd /root & wget -O php7.tar.gz http://cn2.php.net/get/php-7.0.1.tar.gz/from/this/mirror
2.解壓源碼包
# tar -xvf php7.tar.gz
3.進入目錄
# cd php-7.0.1
4.安裝php依賴包
# 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
5.編譯配置,這裏若是上一步的某些依賴包沒有安裝好,就會遇到不少configure error,咱們一一解決,安裝上相關軟件開發包就能夠
# ./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
configure error:
1.configure: error: xml2-config not found. Please check your libxml2 installation.
解決:
1
|
<span style=
"color: #ff0000"
># yum
install
libxml2 libxml2-devel<
/span
>
|
2.configure: error: Cannot find OpenSSL's <evp.h>
解決:
1
|
<span style=
"color: #ff0000"
># yum
install
openssl openssl-devel<
/span
>
|
3.configure: error: Please reinstall the BZip2 distribution
解決:
1
|
<span style=
"color: #ff0000"
># yum
install
bzip2
bzip2
-devel<
/span
>
|
4.configure: error: Please reinstall the libcurl distribution - easy.h should be in <curl-dir>/include/curl/
解決:
1
|
<span style=
"color: #ff0000"
># yum
install
libcurl libcurl-devel<
/span
>
|
5.If configure fails try --with-webp-dir=<DIR> configure: error: jpeglib.h not found.
解決:
1
|
<span style=
"color: #ff0000"
># yum
install
libjpeg libjpeg-devel<
/span
>
|
6.If configure fails try --with-webp-dir=<DIR>
checking for jpeg_read_header in -ljpeg... yes
configure: error: png.h not found.
解決:
1
|
<span style=
"color: #ff0000"
># yum
install
libpng libpng-devel<
/span
>
|
7.If configure fails try --with-webp-dir=<DIR>
checking for jpeg_read_header in -ljpeg... yes
checking for png_write_image in -lpng... yes
If configure fails try --with-xpm-dir=<DIR>
configure: error: freetype-config not found.
解決:
1
|
<span style=
"color: #ff0000"
># yum
install
freetype freetype-devel<
/span
>
|
8.configure: error: Unable to locate gmp.h
解決:
1
|
<span style=
"color: #ff0000"
># yum
install
gmp gmp-devel<
/span
>
|
9.configure: error: mcrypt.h not found. Please reinstall libmcrypt.
解決:
# yum install libmcrypt libmcrypt-devel
10.configure: error: Please reinstall readline - I cannot find readline.h
解決:
1
|
<span style=
"color: #ff0000"
># yum
install
readline readline-devel<
/span
>
|
11.configure: error: xslt-config not found. Please reinstall the libxslt >= 1.1.0 distribution
解決:
1
|
<span style=
"color: #ff0000"
># yum
install
libxslt libxslt-devel<
/span
>
|
6.編譯與安裝
# make && make install
這裏要make很久,要耐心一下
7.添加 PHP 命令到環境變量
# vim /etc/profile
在末尾加入
PATH=$PATH:/usr/local/php/bin
export PATH
要使改動當即生效執行
# source /etc/profile
查看環境變量
# echo $PATH
查看php版本
# php -v
8.配置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
9.啓動php-fpm
# /etc/init.d/php-fpm start
5、配置nginx虛擬機,綁定域名
# vim /etc/nginx/conf.d/php7.aaa.com.conf
這裏能夠把php7.aaa.com.conf改爲本身的域名
把下面的內容複製到php7.aaa.com.conf裏
server{ listen 80; server_name php7.aaa.com; root /var/www/html/php7.aaa.com; # 該項要修改成你準備存放相關網頁的路徑 location / { index index.php index.html index.htm; #若是請求既不是一個文件,也不是一個目錄,則執行一下重寫規則 if (!-e $request_filename) { #地址做爲將參數rewrite到index.php上。 rewrite ^/(.*)$ /index.php/$1; #如果子目錄則使用下面這句,將subdir改爲目錄名稱便可。 #rewrite ^/subdir/(.*)$ /subdir/index.php/$1; } } #proxy the php scripts to php-fpm location ~ \.php { include fastcgi_params; ##pathinfo支持start #定義變量 $path_info ,用於存放pathinfo信息 set $path_info ""; #定義變量 $real_script_name,用於存放真實地址 set $real_script_name $fastcgi_script_name; #若是地址與引號內的正則表達式匹配 if ($fastcgi_script_name ~ "^(.+?\.php)(/.+)$") { #將文件地址賦值給變量 $real_script_name set $real_script_name $1; #將文件地址後的參數賦值給變量 $path_info set $path_info $2; } #配置fastcgi的一些參數 fastcgi_param SCRIPT_FILENAME $document_root$real_script_name; fastcgi_param SCRIPT_NAME $real_script_name; fastcgi_param PATH_INFO $path_info; ###pathinfo支持end fastcgi_intercept_errors on; fastcgi_pass 127.0.0.1:9000; } location ^~ /data/runtime { return 404; } location ^~ /application { return 404; } location ^~ /simplewind { return 404; } }
2.重啓nginx
# service nginx reload
3.
# vim /var/www/html/php7.aaa.com/index.php
把下面的代碼複製到這個文件 裏
<?php
phpinfo();
4.查看訪問http://php7.aaa.com
ok!收工!