For each website:
- Each user must have read/write permission
- Each user's group must have read/write permission (reseller access)
- Apache must have read access
- Would be nice if admins had read/write as well
Web development all-around, including PHP, CSS, HTML, Hosting, MySQL, Symfony, Drupal and Wordpress.
{{LOG_DIR=/var/log/apache2}} {{RUN_DIR=/var/run/php-fpm}} {{FCGI=$RUN_DIR/$DOMAIN.fcgi}} {{SOCKET=$RUN_DIR/$DOMAIN.sock}} {{EMAIL=$USER@$DOMAIN}} {{DOC_ROOT=/home/$USER/sites/$DOMAIN/htdocs}} <VirtualHost *:80> ServerAdmin {{EMAIL}} ServerName {{DOMAIN}} ServerAlias www.{{DOMAIN}} DocumentRoot "{{DOC_ROOT}}" <Directory "{{DOC_ROOT}}"> AllowOverride All Order allow,deny Allow From All </Directory> AddHandler php-script .php Action php-script /php5.fastcgi virtual Alias /php5.fastcgi {{FCGI}} FastCGIExternalServer {{FCGI}} -socket {{SOCKET}} LogLevel warn CustomLog {{LOG_DIR}}/{{DOMAIN}}.access.log combined ErrorLog {{LOG_DIR}}/{{DOMAIN}}.error.log </VirtualHost>
We all have our nice little bashrc that we are proud of. It tests for files, programs and terminal features, detect your OS version, builds a PATH, etc. For all of our OS and different setups, various solutions exist.
Pros:
Cons:
Pros:
Cons:
Pros:
Cons:
So, what does a good bashrc have?
Should have:
Yes, you read right, reduce tests AND do a lot of feature detection. You don't want to do Java specific configuration or set an empty variable if Java is not even installed, but you do want Java to be automatically detected.
Let's face it, you will install or remove Java way less often then you will start a new shell. Why then test for Java at each new shell?
This is where I introduce the Dotfiles Builder. The script runs in Bash and outputs the wanted bashrc.
This way, instead of doing:
if [ -d "$HOME/bin" ]; then PATH="$HOME/bin:$PATH" fi
You would do:
if [ -d "$HOME/bin" ]; then echo "PATH=\"$HOME/bin:$PATH\"" fi
And the result would simply be
PATH="$HOME/bin:$PATH"
But constructing PATH is a rather common task and you want to make sure the folder is not already on your PATH. Why not wrap it up ?
Take a look at the alpha version:
https://github.com/lavoiesl/dotfiles-builder/
As well as the example output.
This is a very alpha version of the intended program, but I still want to share what I have and maybe get some feedback and collaborators along the way. Currently, it only generates a bashrc, but expect more to come.
Quite a usual task is to dump a database to do backups. You may even want to do this in a cronjob to snapshots, etc.
A very bad solution is to hardcode the root password in the cronjob or in your backup script; doing so have a very high chance of exposing your password.
You could create an account with read-only access to all your databases and use it to to your backups. This is indeed better but can lead to the same issues mentioned above
The safest way to use passwords on the command line is to store them in a file and have a script load them when needed. You then just need to make sure those files have the correct permissions
As it turns out, installations of dbconfig on Debian/Ubuntu creates a user called debian-sys-maintainer. It is used to do MySQL management, mainly through the package manager. Well, this user has all the needed privileges to backup your database and you are sure it will always work. Unless, of course, you manually change the password without updating the file.
This script uses sudo so it will ask your password even if you forgot to prepend sudo.
$ export-database.sh my_database [mysqldump options] | gzip > /tmp/my_database.sql.gz
wordpress-change-url.php http://old-domain.com https://new-domain.com < database.orig.sql > database.new.sql
wordpress-change-url.php database.orig.sql https://new-domain.com > database.new.sql
This is in no way a robust solution for deploying a real web hosting infrastructure, but sometimes, you just need basic templates. I use this simple template on my dev server.
One of the most annoying things with being able to see all files in the terminal is that… you see all the files. That includes backups, swap and temp files.
Well, it’s a rather good thing, it remembers you to remove them once in a while.