怎样快速安装PHP+MySQL

2019年10月10日 | 分类: 【技术】

安装 PHP 和 PHP-FPM :

参考:https://yq.aliyun.com/articles/5479467

yum -y install php php-fpm

打开php-fpm服务的配置文件 /etc/php-fpm.d/www.conf,修改用户和组为nginx:

user = nginx
group = nginx

重启php-fpm服务:

systemctl restart php-fpm

修改nginx配置文件,让nginx可以处理php脚本:

参考:https://blog.csdn.net/a7442358/article/details/81911915

user  nginx;

...

server	{
	listen 80;
	server_name stripe.wiki;
	location / {
		rewrite (.*) https://stripe.wiki$1 permanent;
		}
	}
 
server	{
	listen 443 ssl http2;
	server_name stripe.wiki;
	root /usr/local/nginx/html/stripe.wiki/portal;

	ssl_certificate /etc/letsencrypt/live/stripe.wiki/fullchain.pem;
	ssl_certificate_key /etc/letsencrypt/live/stripe.wiki/privkey.pem;
	ssl_session_timeout 5m;
	ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4;
	ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
	ssl_prefer_server_ciphers on;

	location / {
		index index.php;
		}
 	location ~ \.php(.*)$ {
		fastcgi_pass 127.0.0.1:9000;
		fastcgi_split_path_info  ^(.+\.php)(.*)$;
		fastcgi_index index.php;
		fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
		fastcgi_param PATH_INFO $fastcgi_path_info;
		include fastcgi_params;
		}
	}

创建 index.php ,放置于 /usr/local/nginx/html/stripe.wiki/portal :

<?php
echo phpinfo();
?>

在浏览器中打开:https://stripe.wiki/ ,发现输出 PHP INFO 信息。

升级PHP:

参考:https://www.jianshu.com/p/b6555d65544
参考:https://wiki.centos.org/zh-tw/HowTos/php7?highlight=%28php7%29

删除旧版本php:

yum remove php-common

升级安装PHP:

参考:https://blog.csdn.net/qq_32080545/article/details/78894792
参考:http://amon.org/php73

yum install gcc libxml2 libxml2-devel curl curl-devel libjpeg libpng freetype libjpeg-devel libpng-devel freetype-devel bzip2-devel libXpm-devel gmp-devel icu libicu libicu-devel php-mcrypt libmcrypt libmcrypt-devel postgresql-devel libxslt-devel libjpeg-devel
wget http://us2.php.net/distributions/php-7.3.9.tar.xz && tar -xvf php-7.3.9.tar.xz && cd php-7.3.9
./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=nginx --with-fpm-group=nginx --enable-ftp --with-gettext --with-xmlrpc --with-xsl --enable-opcache --enable-fpm --with-iconv --with-xpm-dir=/usr
make clean && make && make install

查看 PHP 版本:

/usr/local/php/bin/php -v

输出:

PHP 7.3.9 (cli) (built: Oct  1 2019 20:26:33) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.3.9, Copyright (c) 1998-2018 Zend Technologies

创建软连接:

ln -s /usr/local/php/bin/php /usr/local/bin/ && ln -s /usr/local/php/bin/phpize /usr/local/bin/ && ln -s /usr/local/php/bin/php-config /usr/local/bin/

php 配置文件:

cp /root/php-7.3.9/php.ini-production /usr/local/php/etc/php.ini

php-fpm 配置文件:

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

打开php-fpm服务的配置文件 /usr/local/php/etc/php-fpm.d/www.conf ,修改用户和组为nginx:

user = nginx
group = nginx

查看版本:

php -v

输出:

PHP 7.3.9 (cli) (built: Oct  1 2019 20:26:33) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.3.9, Copyright (c) 1998-2018 Zend Technologies

配置PHP-fpm :

cp /root/php-7.3.9/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

添加到开机启动项:

chkconfig --add php-fpm

此时也可以使用service来启动php-fpm了

service php-fpm start
service php-fpm stop

重启nginx:

/usr/local/nginx/sbin/nginx -s reload

【3. 安装 MySQL 】

参考:http://amon.org/mysql
参考:https://blog.csdn.net/qq_32080545/article/details/78894792

下载:https://dev.mysql.com/downloads/repo/yum/

安装 MySQL :

wget https://dev.mysql.com/get/mysql57-community-release-el7-11.noarch.rpm
yum -y localinstall mysql57-community-release-el7-11.noarch.rpm
yum -y install mysql-community-server

启动 Mysql 服务 :

service mysqld start

设置开机启动:

systemctl enable mysqld && systemctl daemon-reload

修改root本地登录密码:

mysql安装完成之后,在 /var/log/mysqld.log 文件中给root生成了一个临时密码。

2019-10-02T10:29:03.086789Z 1 [Note] A temporary password is generated for root@localhost: -fUW+wtif6</

使用临时密码 进入mysql命令行;

mysql -u root -p
mysql> set password for 'root'@'localhost'=password('C5FV4k1dP2z#8UM');

安装 phpmyadmin :

wget https://files.phpmyadmin.net/phpMyAdmin/4.9.1/phpMyAdmin-4.9.1-all-languages.zip && unzip phpMyAdmin-4.9.1-all-languages.zip

设置 phpmyadmin :

...
$cfg['blowfish_secret'] = 'anywordsthatjumpintoyourmind';
...
$cfg['Servers'][$i]['host'] = '127.0.0.1';
...

否则报错:

mysqli::real_connect(): (HY000/2002): No such file or directory