WordPress on LAMP... Linux Shell scripts...
Recently I was installing a WordPress website on Linux server using LAMP. I used WP after a long time and was very impressed by the newer versions. However, the Linux CLI work-flow is kind of demanding, compared to WAMP/XAMPP based installations in Windows. I thought it was a nice opportunity to revisit the unix/linux days: shell scripting ....
Step 1. Installing LAMP
- A standard Ubuntu installation prompts the software selection where one can select the LAMP server.
- It is also possible to access these options by tasksel as below. If you don't have tasksel, it can be installed:
sudo apt-get install tasksel sudo tasksel
- It is a good idea to keep a record of the mySQL password, the default user is root.
- As I did not have a GUI and a web browser, I used lynx (a CLI web browser!). Alternatively, one can navigate to the web page from a network computer.
Step 2. Creating a database for the WordPress from mySQL
This is where I thought of creating a bash shell script.
- Created bin directory in my account: mkdir bin | logged out and logged back in that refreshed my .bashrc and updated the $PATH variable.
- Got tired of the mysql -u root -p that you need to enter the mySQL CLI to do the databases. So added an alias in the .bashrc. So now just type go2mysql.
#ratan's aliases alias go2mysql='mysql -u root -p'
- But to help me create the db, I called an SQL script into a bash shell script as below.
#run_inmysql.sh !/bin/bash mysql --host=localhost --user=root --password=mypw -e "source /home/ratan/bin/db_script.sql" #Source in SQL allows you to run scripts---------------------------------- # db_script.sql----------------------------------not sure what's comment syntax in SQL CREATE DATABASE myweb DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci; GRANT ALL ON myweb.* TO 'ratan'@'localhost' IDENTIFIED by 'mypasswd'; FLUSH PRIVILEGES; show databases;
So, that did create the database. I will add rest of my steps to the script and share soon after testing it on my Linux VM. It'd be fun if I can also script into the WP installation!
Feel free to comment should you have queries / advise / or would like to share an alternative way.
Please note that the above is redundant if you have PHPMyAdmin (: sudo apt-get install phpmyadmin :), which offers a GUI via web browser. Here is a nice article. But the good thing about a shell script is that you can fairly automate the process.
I have summarized a major part of the work flow in the following BASH script.
#Ratan's WP installation
site_name='pluto'
myuser='ratan'
cd /tmp
curl -O https://wordpress.org/latest.tar.gz
tar xzvf latest.tar.gz
#mkdir -p $site_name/pg
mkdir $site_name
mv /tmp/wordpress /tmp/$site_name/
mv /tmp/$site_name/wordpress /tmp/$site_name/pg
touch /tmp/$site_name/pg/.htaccess
#move wp-config.php to a directory up
cp /tmp/$site_name/pg/wp-config-sample.php /tmp/$site_name/wp-config.php
mkdir /tmp/$site_name/pg/wp-content/upgrade
#copy to /var/www
sudo mv /tmp/$site_name /var/www/html/$site_name
# Assign ownership set permissions:
sudo chown -R $myuser:www-data /var/www/html
chown -R www-data:www-data your-wordpress-directory
#WordPress Directory Permissions: directory to 755 and files to 644
sudo find /var/www/html -type d -exec chmod 755 {} \;
sudo find /var/www/html -type f -exec chmod 644 {} \;
sudo chmod -R g+w /var/www/html/$site_name/pg/plugins
sudo chmod -R g+w /var/www/html/$site_name/pg/wp-content
cd
define('FS_METHOD', 'direct');