Last active
January 19, 2020 15:06
-
-
Save thinkycx/bd78072e35e833cd7538f9afaefc6086 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# author: thinkycx | |
# update: 20190119 | |
# tested on ubuntu 16.04 docker | |
# quit if the following commands has errors | |
set -e | |
# tools | |
sudo apt-get update && | |
sudo apt-get install lsof -y && | |
sudo apt-get install net-tools -y && # ifconfig | |
sudo apt-get install iputils-ping -y # ping | |
# ===================================================================== | |
# 1.nginx | |
sudo apt-get install nginx -y | |
# nginx start | |
# sudo /etc/init.d/nginx start | |
# sudo service nginx start | |
# nginx show | |
# dpkg -S nginx | |
# nginx see which conf used | |
# nginx -t | |
# reference | |
# https://blog.csdn.net/STFPHP/article/details/53492723 | |
# ===================================================================== | |
# uninstall old php related files | |
# sudo apt-get purge `dpkg -l | grep php| awk '{print $2}' |tr "\n" " "`\ | |
# install add-apt-repository | |
# 2 install php7 | |
# php7.0 default at ubuntu16.04 20200119 | |
sudo apt-get install php-fpm -y | |
sudo apt-get install php-mysql | |
# service php7.0-fpm start | |
# 2 install php5.6 | |
sudo apt-get install software-properties-common -y && | |
export LC_ALL=C.UTF-8 # fix error: 'ascii' codec can't decode byte 0xc5 in position 92: ordinal not in range(128) | |
sudo add-apt-repository ppa:ondrej/php -y | |
# maybe need to fix | |
# apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 4F4EA0AAE5267A6C | |
# see https://blog.csdn.net/think_ycx/article/details/84198255 | |
sudo apt-get update -y && | |
sudo apt-get install php5.6 -y | |
sudo apt-get install php5.6-fpm | |
sudo apt-get install php5.6-mysql # php and mysql connect | |
# optional php modules | |
# sudo apt-get install php5.6-mbstring php5.6-mcrypt php5.6-mysql php5.6-xml | |
# sudo service php-fpm start | |
# check status | |
# $ netstat -ano |grep fpm | |
# unix 2 [ ACC ] STREAM LISTENING 186389 /run/php/php5.6-fpm.sock | |
# ===================================================================== | |
# update php-fpm : /etc/nginx/sites-enabled/default | |
# add php5.6 | |
: ' | |
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000 | |
# | |
# location ~ \.php$ { | |
# include snippets/fastcgi-php.conf; | |
# | |
# # With php7.0-cgi alone: | |
# fastcgi_pass 127.0.0.1:9000; | |
# # With php7.0-fpm: | |
# fastcgi_pass unix:/run/php/php7.0-fpm.sock; | |
# } | |
# php 5.6 20181118 by thinkycx | |
location ~ \.php$ { | |
include snippets/fastcgi-php.conf; | |
fastcgi_pass unix:/run/php/php5.6-fpm.sock; | |
} | |
' | |
# references | |
# Installing PHP 5.6 on Xenial (16.04) [duplicate] https://askubuntu.com/questions/756181/installing-php-5-6-on-xenial-16-04 | |
# ===================================================================== | |
# 3. mysql | |
# mysql install | |
sudo apt-get install mysql-server -y # enter root password | |
sudo apt install mysql-client -y | |
sudo apt install libmysqlclient-dev #Connector/C (libmysqlclient) is a client library for C development. | |
# service mysql start | |
# mysql see if is running | |
# netstat -tap | grep mysql | |
# ===================================================================== | |
# 4. test php | |
# echo "<?php\n phpinfo(); " > /var/www/html/1.php | |
# curl http://localhost/1.php | |
# reference | |
# 1. https://blog.csdn.net/dengjiexian123/article/details/53358452 | |
# ===================================================================== | |
# 5. test php-mysql | |
# test db | |
curl localhost/db.php | |
: ' | |
$ cat db.php | |
<?php | |
$servername = 'localhost'; | |
$username = 'root'; | |
$password = 'root'; | |
$database='mysql'; | |
$conn = new mysqli($servername, $username, $password,$database); | |
if ($conn->connect_error) { | |
die("Connection failed: " . $conn->connect_error); | |
} | |
echo "Connected successfully"; | |
' | |
# ===================================================================== | |
# 6. install ssh | |
sudo apt-get install openssh-server -y | |
sudo vim /etc/ssh/sshd_config | |
service ssh start | |
# passwd change password | |
# ssh-copy-id -i ~/.ssh/id_rsa_docker.pub root@localhost -p<PORT> | |
# ssh -o "StrictHostKeyChecking no" -D 10000 -f -C -N root@localhost -p 10022 | |
# ===================================================================== | |
# how to change php version for nginx | |
# 1. change nginx log | |
vim /etc/nginx/sites-enabled/default | |
# change fastcgi_pass unix:/run/php/php7.0-fpm.sock; | |
# change fastcgi_pass unix:/run/php/php5.6-fpm.sock; | |
# 2. restart nginx php-fpm mysql | |
service nginx start && service php5.6-fpm start && service mysql start | |
service nginx start && service php7.0-fpm start && service mysql start |
mysql cannot start
- chown -R mysql:mysql /var/lib/mysql /var/run/mysqld && service mysql start
change mysql listen on 0.0.0.0
- vim /etc/mysql/mysql.conf.d/mysqld.cnf
- change 127.0.0.1 to 0.0.0.0
allow mysql to be connected by root from any ip
use mysql;
update user set host = '%' where user = 'root';
mysql> use mysql;
Database changed
mysql> select host from user where user = 'root';
+-----------+
| host |
+-----------+
| localhost |
+-----------+
1 row in set (0.00 sec)
mysql> update user set host = '%' where user = 'root';
Query OK, 1 row affected (0.00 sec)
Rows matched: 1 Changed: 1 Warnings: 0
mysql> select host, user from user;
+-----------+------------------+
| host | user |
+-----------+------------------+
| % | root |
| localhost | debian-sys-maint |
| localhost | mysql.session |
| localhost | mysql.sys |
+-----------+------------------+
4 rows in set (0.00 sec)
have a look here at first
https://lnmp.org/download.html
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
nginx常见用法: