#安裝PHP(5.6.26)
##先下載PHP源文件
wget http://cn2.php.net/distributions/php-5.6.26.tar.gz
##解壓:
tar -zxvf php-5.6.26.tar.gz
##安裝編譯用的環境:
yum install -y libxml2-devel openssl-devel libcurl-devel libjpeg-devel libpng-devel libicu-devel openldap-devel bzip2-devel
yum install gcc gcc-c++ #編譯工具
###安裝libmcrypt
如果想讓編譯的php支持mcrypt擴展,需安裝libmcrypt libmcrypt-devel 或者編譯安裝
####下載源文件:
Libmcrypt(libmcrypt-2.5.8.tar.gz):
wget https://sourceforge.net/projects/mcrypt/files/Libmcrypt/2.5.8/libmcrypt-2.5.8.tar.gz
mcrypt(mcrypt-2.6.8.tar.gz ):
wget https://sourceforge.net/projects/mcrypt/files/MCrypt/2.6.8/mcrypt-2.6.8.tar.gz
mhash(mhash-0.9.9.9.tar.gz):
wget https://sourceforge.net/projects/mhash/files/mhash/0.9.9.9/mhash-0.9.9.9.tar.gz
####依次解壓編譯安裝(類似)
#####先安裝Libmcrypt
#tar -zxvf libmcrypt-2.5.8.tar.gz
#cd libmcrypt-2.5.8
#./configure
#make
#make install
說明:libmcript默認安裝在/usr/local
安裝完後重啓機器
#####.再安裝mhash
#tar -zxvf mhash-0.9.9.9.tar.gz
#cd mhash-0.9.9.9
#./configure
#make
#make install
#####.最後安裝mcrypt
#tar -zxvf mcrypt-2.6.8.tar.gz
#cd mcrypt-2.6.8
#LD_LIBRARY_PATH=/usr/local/lib ./configure
#make
#make install
##進入PHP源碼文件夾:
cd php-5.6.26
執行下面命令並開始編譯:
#./configure --prefix=/usr/local/php --enable-fpm --enable-soap --with-libxml-dir --with-openssl --with-zlib --with-iconv --with-bz2 --with-curl --enable-dom --enable-exif --enable-fileinfo --with-pcre-dir --enable-ftp --enable-gd-jis-conv --with-gd --with-openssl-dir --with-jpeg-dir --with-png-dir --with-zlib-dir --with-mhash --enable-json --enable-mbstring --disable-mbregex --enable-pdo --with-pdo-mysql --with-pdo-sqlite --enable-session --with-zlib-dir --enable-simplexml --enable-sockets --enable-zip --with-mysqli
#make
#make install
再複製php的配置文件到對應的目錄:
cp php.ini-development /usr/local/php/lib/php.ini
配置php-fpm
cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf
配置完php-fpm後運行
php-fpm
安裝完成之後使用
php -v
查看是否安裝完成,如果編譯成功但是無法使用命令行請使用下面的命令添加環境變量進系統:
export PATH=/usr/local/php/bin:/usr/local/php/sbin:$PATH
#安裝Nginx
##下載rpm文件
wget http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm
##建立nginx的yum倉庫
# rpm -ivh nginx-release-centos-7-0.el7.ngx.noarch.rpm
##安裝nginx
yum install nginx
##啓動nginx服務
service nginx start
##nginx的配置
nginx的配置文件位置:/etc/nginx,更改一下(具體根據自己的配置更改):
/etc/nginx/nginx.conf文件內容如下:
user root root;
worker_processes 1;
error_log /var/log/nginx/error.log warn;
pid /var/run/nginx.pid;
events {
worker_connections 1024;
}
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log /var/log/nginx/access.log main;
sendfile on;
#tcp_nopush on;
keepalive_timeout 65;
#gzip on;
include /etc/nginx/conf.d/*.conf;
}
/etc/nginx/conf.d/default.conf文件中的內容改爲:
server {
listen 80;
server_name localhost 192.168.140.131;
root /usr/share/nginx/html;
index index.php index.html index.htm;
charset utf-8;
#charset koi8-r;
#access_log /var/log/nginx/log/host.access.log main;
location / {
root /usr/share/nginx/html;
index index.php index.html index.htm;
}
#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 /usr/share/nginx/html;
}
location ~ \.php$ {
root /usr/share/nginx/html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include /etc/nginx/fastcgi_params;
}
#配置Nginx的靜態資源訪問
location ~ .*\.(html|htm|gif|jpg|jpeg|bmp|png|ico|txt|js|css)$ {
expires 30d;
}
# 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$ {
# root html;
# fastcgi_pass 127.0.0.1:9000;
# fastcgi_index index.php;
# fastcgi_param SCRIPT_FILENAME /scripts$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;
#}
}
修改完成重啓nginx
service nginx restart
通過以上配置文件可見當前項目目錄在:
/usr/share/nginx/html中
於是上傳一個demo.php文件到此目錄下,即可運行。
#安裝mysql
參考網址:http://dev.mysql.com/doc/mysql-yum-repo-quick-guide/en/
##下載rpm文件:
wget http://dev.mysql.com/get/mysql57-community-release-el7-9.noarch.rpm
##建立mysql的yum倉庫
rpm -ivh mysql57-community-release-el7-9.noarch.rpm
##修改配置文件(指定安裝的mysql版本)
sudo vi /etc/yum.repos.d/mysql-community.repo
修改其中版本爲enable爲1或者0選擇安裝版本,這裏我們選擇mysql5.6
##安裝mysql
sudo yum install mysql-community-server
##mysql默認密碼(針對5.7)
會在/var/log/mysqld.log中保存一個初始密碼,使用這個初始密碼登錄後使用:
SET PASSWORD = PASSWORD('你的新密碼');
來修改密碼
##啓動mysql,並查看狀態
service mysqld start
service mysqld status
##安裝安全管理包(針對mysql5.6)
mysql_secure_installation
安完之後可以修改root密碼
##測試
安裝完成後使用命令行:
mysql -uroot -p
輸入剛纔設置的密碼登錄mysql
#以上