Category Archives: Linux
Change permission for PHP to write storage folder
Under /storage/app/public/ (laravel)
1 2 3 |
sudo find . -type f -exec chmod 664 {} + \ && sudo find . -type d -exec chmod 775 {} + \ && sudo chown -R www-data:www-data . |
New domain for Apache
Change permission:
1 2 3 4 |
#/var/www sudo find . -type f -exec chmod 664 {} + \ && sudo find . -type d -exec chmod 775 {} + \ && sudo chown -R www-data:www-data . |
Restart apache:
1 |
sudo service apache2 restart |
Crontab for Laravel (Scheduled Tasks)
1 2 |
#Example * * * * * /usr/bin/php /home/ubuntu/hello/artisan schedule:run >> /dev/null 2>&1 |
Reference:
- Official Doc:
https://laravel.com/docs/5.4/scheduling
Create a symlink (symbolic link)
Official (but sometimes not working)
1 |
php artisan storage:link |
Command:(在public資料夾下)
1 |
ln -s ../storage/app/public storage |
Windows:
1 |
mklink storage D:\www\Acer\abs_cms\storage\app\public |
Reference:
Change folder permission
1 |
sudo chmod -R 777 xstore |
Reference:
Linux commands
修改User權限:
1 |
sudo chown -R ec2-user:www uploads |
修改資料夾權限:
1 |
sudo chmod -R 775 uploads |
Others
1 2 3 |
chgrp :改變檔案所屬群組 chown :改變檔案擁有者 chmod :改變檔案的權限, SUID, SGID, SBIT等等的特性 |
http://linux.vbird.org/linux_basic/0210filepermission.php
切換為Super user:
1 |
sudo su |
檢視檔案和資料夾詳細資料:
1 |
ls -al |
顯示Server空間使用狀況
1 |
df -h |
檢視資料夾dir的size:
1 2 |
du -sh dir du -sh * |
修改Web User權限
1 2 3 |
sudo find . -type f -exec chmod 664 {} + \ && sudo find . -type d -exec chmod 775 {} + \ && sudo chown -R www-data:www-data . |
檢視檔案的大小(mb)
1 |
ls -lh |
檢視Server硬碟相關的用量
1 |
df -H |
https://www.cyberciti.biz/faq/linux-check-disk-space-command/
Scheduled Jobs in Linux using crontab (nano)
- Create crontab file: crontab -e
This command will enter VI - Edit crontab file
e..g */1 * * * * php /var/html/task.php
Execute task.php every minute. - Ctrl + C to enter VI command mode and enter :wq to exit VI
1 2 3 |
#Execute send_order_emails every 5 mins #and write warning/error/echo results in /tmp/stage_email.log */5 * * * * /usr/bin/php /var/www/stage/index.php /web/send_order_emails/a6aec3 >> /tmp/stage_email.log 2>&1 |
Line break for log:
1 |
echo $order->email . ': ' . print_r($result, true) . PHP_EOL; |
Nano commands:
Select: ALT + M + A
Copy: ALT + 6
Paste: CTRL + U
Note:
- Make sure use full path to use php. e.g. /usr/bin/php index.php
- PHP could execute URI of CodeIgniter
/usr/bin/php /var/www/test/index.php /home/some_action
Reference:
- https://kb.iu.edu/d/afiz
- http://linux.vbird.org/linux_basic/0430cron.php#crontab
- http://stackoverflow.com/questions/15470016/how-to-write-cron-job-in-aws-ec2-server
- Debug:
https://stackoverflow.com/questions/7397469/why-is-crontab-not-executing-my-php-script - Write logs:
https://askubuntu.com/questions/56683/where-is-the-cron-crontab-log - Usage of VI:
http://linux.vbird.org/linux_basic/0310vi/0310vi.php - Nano usage:
https://www.linuxquestions.org/questions/linux-newbie-8/how-to-copy-paste-a-line-in-nano-editor-548925/
Enable .htaccess on Apache2
- Enable rewrite module
http://stackoverflow.com/questions/869092/how-to-enable-mod-rewrite-for-apache-2-2
https://www.digitalocean.com/community/questions/how-to-active-sudo-a2enmod-rewrite-for-centos
Solution: Uncomment the mod_rewrite.so line in/etc/httpd/conf/httpd.conf
, restart apache, and you should be good to go. - Update directive in .conf (e.g. /etc/apache2/sites-available/000-default.conf)
https://help.ubuntu.com/community/EnablingUseOfApacheHtaccessFiles
123456789<Directory /var/www/html>Options Indexes FollowSymLinks MultiViewsAllowOverride AllOrder allow,denyallow from all# Uncomment this directive is you want to see apache2's# default start page (in /apache2-default) when you go to /#RedirectMatch ^/$ /apache2-default/</Directory>
Reset Mysql root password
https://help.ubuntu.com/community/MysqlPasswordReset
Sometimes MySql can’t be stopped, try this command:
1 |
mysqladmin -u root -p shutdown |
Reference: