参考
https://zhuanlan.zhihu.com/p/337374474
https://help.aliyun.com/zh/ecs/use-cases/build-a-lamp-stack-on-a-centos-7-instance
安装Nginx
yum -y install nginx
systemctl start nginx 启动nginx服务
systemctl enable nginx 设置nginx服务开机自启动
常用功能
- 检查nginx服务启动状态
systemctl status nginx- 检查nginx监听端口
netstat -antpul | grep nginx- 查看nginx版本
nginx -v- 默认nginx配置文件位置
/etc/nginx/nginx.conf- 默认站点目录
/usr/share/nginx/html
安装Mysql
wget http://dev.mysql.com/get/mysql57-community-release-el7-10.noarch.rpm && yum -y install mysql57-community-release-el7-10.noarch.rpm && yum -y install mysql-community-server --nogpgcheck
systemctl start mysqld 启动数据库服务
sudo systemctl enable mysqld 开机启动
sudo systemctl daemon-reload 重新加载systemd的配置文件
常用功能
- 查看版本
mysql -V- 检查数据库服务端口
netstat -antpul | grep mysqld- 查看数据库初始密码
grep "password" /var/log/mysqld.log- 配置mysql安全设置以及root管理员用户密码
mysql_secure_installation- 测试数据库连接
mysql -uroot -h localhost -p
安装php
rpm -ivh --nodeps https://rpms.remirepo.net/enterprise/remi-release-8.rpm 添加源
sed -i 's/PLATFORM_ID="platform:al8"/PLATFORM_ID="platform:el8"/g' /etc/os-release
yum -y module install php:remi-7.4
yum -y install php php-curl php-dom php-exif php-fileinfo php-fpm php-gd php-hash php-json php-mbstring php-mysqli php-openssl php-pcre php-xml libsodium 安装组件
sed -i 's/PLATFORM_ID="platform:el8"/PLATFORM_ID="platform:al8"/g' /etc/os-release
配置php
- 修改conf文件
位置:/etc/php-fpm.d/www.conf
egrep '^(user|group)' /etc/nginx/nginx.conf 查看用户组,得到user(如:nginx)
修改文件
user = nginx (注意这里,没设置的话,后面设置laravel权限的时候)
group = nginx
;listen.owner = nginx
;listen.group = nginx
;listen.mode = 0660
env[HOSTNAME] = $HOSTNAME
env[PATH] = /usr/local/bin:/usr/bin:/bin
env[TMP] = /tmp
env[TMPDIR] = /tmp
env[TEMP] = /tmp- 修改php.ini
;修改时区,否则代码里获取的时间和linux系统不一样
php.ini date.timezone ="PRC"
;增加上传文件限制
upload_max_filesize = 1024M
memory_limit = 1024M
post_max_size = 1024M
systemctl start php-fpm 启动php服务
systemctl enable php-fpm 设置开机启动
常用功能
cp /etc/nginx/nginx.conf /etc/nginx/nginx.conf.bak 备份配置文件
vim /etc/nginx/nginx.conf
添加下列配置信息。
http {
client_max_body_size 1024M; # 设置请求实体大小限制,解决403 request entity too large
proxy_connect_timeout 5m;
proxy_send_timeout 5m;
proxy_read_timeout 5m;
fastcgi_connect_timeout 300; #设置请求超时时间,否则带宽太小,上传一个文件要好久
fastcgi_send_timeout 300;
fastcgi_read_timeout 300;
fastcgi_buffer_size 64k;
fastcgi_buffers 4 64k;
fastcgi_busy_buffers_size 128k;
fastcgi_temp_file_write_size 128k;
server {
location / {
index index.php index.html index.htm;
}
#添加下列信息,配置Nginx通过fastcgi方式处理您的PHP请求。
location ~ .php$ {
root /usr/share/nginx/html; #将/usr/share/nginx/html替换为您的网站根目录,本文使用/usr/share/nginx/html作为网站根目录。
fastcgi_pass 127.0.0.1:9000; #Nginx通过本机的9000端口将PHP请求转发给PHP-FPM进行处理。
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params; #Nginx调用fastcgi接口处理PHP请求。
}
#设置字体文件的访问权限和跨域访问
location ~* \.(ttf|ttc|otf|eot|woff|woff2|font.css)$ {
add_header Access-Control-Allow-Origin *;
}
}
}
systemctl restart nginx
sudo systemctl enable nginx 开机启动
创建php测试文件
echo "<?php phpinfo(); ?>" > /usr/share/nginx/html/phpinfo.php
systemctl enable php-fpm 设置开机启动
9000端口没有自动监听
开放端口命令添加开机自启
cd /etc/rc.d/init.d/
vim php-fpm-start.sh
#!/bin/sh
#chkconfig: 2345 80 90
#description:开机自动启动的脚本程序
# 开启php-fpm服务 端口为9000
php-cgi -b 127.0.0.1:9000 &
设置为可执行文件
chmod +x php-fpm-start.sh
添加脚本到开机自动启动项目中
chkconfig --add php-fpm-start.sh
chkconfig php-fpm-start.sh on
测试 8.140.30.231/phpinfo.php
安装Laravel
sudo yum install git 安装git,否则无法下载laravel
安装composer(https://docs.phpcomposer.com/00-intro.html)
curl -sS https://getcomposer.org/installer | php
mv composer.phar /usr/local/bin/composer
cd /var/www/
sudo /usr/local/bin/composer create-project laravel/laravel laravel
将Laravel Web根目录的所有者更改为“nginx”用户,并使用以下命令将存储目录的权限更改为755。注意,php里面要配置用户,否则这个会有权限问题
chown -R nginx:root /var/www/laravel
chmod 755 -R /var/www/laravel/storage
创建一个新的虚拟主机
cd /etc/nginx
vim conf.d/laravel.conf
server {
listen 8080;
# Log files for Debugging
access_log /var/log/nginx/laravel-access.log;
error_log /var/log/nginx/laravel-error.log;
# Webroot Directory for Laravel project
root /var/www/laravel/public;
index index.php index.html index.htm;
# Your Domain Name
server_name 8.140.30.231;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
location ~* \.(ttf|ttc|otf|eot|woff|woff2|font.css)$ {
add_header Access-Control-Allow-Origin *;
}
# PHP-FPM Configuration Nginx
location ~ \.php$ {
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
# fastcgi_pass unix:/run/php-fpm/php-fpm.sock; # webtatic
fastcgi_pass unix:/run/php-fpm/www.sock; # remi
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
location ~ /\.ht {
deny all;
}
}
注意:server_name是域名,如果有域名的话就换掉,没有就用公网ip
fastcgi_pass unix:/run/php-fpm/www.sock; 这个路径要注意,安装的php版本不同,这里的要改,具体路径一般在/run/php-fpm中可以找到,保险一点,/etc/php-fpm.d/路径下有配置文件(例:www.conf),打开搜索一下listen(例:listen = /run/php-fpm/www.sock)
测试配置是否正确,不正确的话会报错
nginx -t
重启Nginx
sudo systemctl restart nginx
cd /var/www/laravel
composer install 安装依赖包,完事会生成一个composer.lock 文件
创建一个新的数据库用户,并授予该用户对 laravel 数据库的访问权限
mysql -u root -p
Yzt20220408
CREATE DATABASE laravel;
CREATE USER 'laraveltest'@'localhost' IDENTIFIED BY 'Yzt20220408*';
GRANT ALL PRIVILEGES ON laravel.* TO 'laraveltest'@'localhost';
FLUSH PRIVILEGES;
修改项目的.env
DB_USERNAME=laraveltest
DB_PASSWORD=Yzt20220408*
php artisan migrate 数据库迁移
安装bsdiff
上传bsdiff-4.3.tar.gz到root目录
解压 cd bsdiff-4.3
修改makefile文件,去掉ifdef 和 end 前面的点
yum search bzip2 查看版本
yum -y install bzip2-devel.x86_64 安装bzip2,没安装编译不过
make
cp bsdiff /usr/local/sbin/ 拷贝文件,方便在系统的任何位置被调用
cp bspatch /usr/local/sbin/
测试
可以通过 ./bsdiff app_old1.apk app_new1.apk app_patch1.patch 直接测试是否可行
在tests文件夹下添加一个测试文件MyTest.php
<?php
use Illuminate\Foundation\Testing\WithoutMiddleware;
use Illuminate\Foundation\Testing\DatabaseMigrations;
use Illuminate\Foundation\Testing\DatabaseTransactions;
class MyTest extends TestCase
{
/**
* A basic functional test example.
*
* @return void
*/
public function testBsdiff()
{
$old_file = '/mnt/data/myproject/lxstore_center/tests/测试_v1.00.07.apk';
$new_file = '/mnt/data/myproject/lxstore_center/tests/测试_v1.00.08.apk';
$diff_file = '/mnt/data/myproject/lxstore_center/tests/测试_07_08.diff';
exec("/usr/local/sbin/bsdiff " . " $old_file $new_file $diff_file");
}
}
通过vendor/bin/phpunit --filter MyTest::testBsdiff测试
安装redis
yum install redis
systemctl start redis
设置开机启动
vim /etc/systemd/system/redis.service
[Unit]
Description=Redis Server
After=network.target
[Service]
ExecStart=/usr/local/bin/redis-server /etc/redis.conf
ExecStop=/usr/local/bin/redis-cli shutdown
Restart=always
[Install]
WantedBy=multi-user.target
systemctl daemon-reload
systemctl enable redis.service
安装扩展
yum install php-redis
systemctl restart php-fpm
测试reids
在Laravel项目的test文件夹中添加文件
<?php
use Illuminate\Foundation\Testing\DatabaseTransactions;
use Illuminate\Support\Facades\Redis;
use Tests\TestCase;
class RedisTest extends TestCase
{
use DatabaseTransactions;
public function testRedisSetAndGet()
{
$key = 'test_key';
$value = 'test_value';
Redis::set($key, $value);
$result = Redis::get($key);
$this->assertEquals($value, $result);
}
}
php artisan test tests/RedisTest.php
redis 查找进程
ps -ef|grep
测试
redis-cli ping 返回结果为 "PONG",则表示 Redis 已成功安装并正在运行
添加定时任务
crontab -e
* * * * * cd /var/www/laravel && php artisan schedule:run >> /dev/null 2>&1