sudo apt-get update && sudo apt-get upgrade
sudo apt-get install -y apache2
sudo apt-get install -y php libapache2-mod-php
sudo apt-get install -y php-curl php-gd php-json php-mbstring php-xml
sudo apt-get install -y mysql-server php-mysql
sudo service mysql restart
sudo mysql_secure_installation
#> Validate password component: N
#> New password: MyPassword
#> Remove anonymous users: Y
#> Disallow root login remotely: Y
#> Reload privilege tables now: Y
sudo service mysql stop
sudo usermod -d /var/lib/mysql mysql
sudo service mysql start
Allow remote root login
sudo mysql -u root -pMyPassword -e "UPDATE mysql.user SET plugin = 'mysql_native_password' WHERE User = 'root'; FLUSH PRIVILEGES;"
sudo apt-get install -y phpmyadmin
#> Use apache2
#> Configure db with dbconfig-common: Yes
#> Random password (leave password blank)
sudo service mysql restart && sudo service apache2 restart
Now you can login into phpmyadmin with username root
and password MyPassword
.
sudo mysql -u root -pMyPassword -e "UPDATE mysql.user SET plugin = 'auth_socket' WHERE User = 'root'; FLUSH PRIVILEGES;"
* If remotely login for root is disallowed then you need to create new MySql user, otherwise you will not be able to login into PhpMyAdmin.
cd ~ && touch .bash_aliases
echo 'alias lampstatus="sudo service apache2 status ; sudo service mysql status"' >> .bash_aliases
echo 'alias lampstart="sudo service mysql start ; sudo service apache2 start"' >> .bash_aliases
echo 'alias lampstop="sudo service mysql stop ; sudo service apache2 stop"' >> .bash_aliases
echo 'alias lamprestart="lampstop ; lampstart"' >> .bash_aliases
Now you need to logout/login and then you can use lampstatus
, lampstart
, lampstop
and lamprestart
for controling LAMP stack.
In this example document root will be changed from /var/www/html
to ~/www
cd ~
mkdir www
sudo sed -i "s;/var/www;$HOME/www;g" /etc/apache2/apache2.conf
sudo sed -i "s;/var/www/html;$HOME/www;g" /etc/apache2/sites-available/000-default.conf
Now you can go to ~/www
and create index.html
First with cd
go into your wordpress installation folder and then:
sudo touch .htaccess
sudo chown -v :www-data .htaccess
sudo chmod -v 664 .htaccess
sudo sed -i "s/AllowOverride None/AllowOverride All/g" /etc/apache2/apache2.conf
sudo a2enmod rewrite
sudo service apache2 restart
Now go to WpAdmin -> Settings -> Permalinks. Choose permalink structure and hit "Save Changes".
Now .htaccess
should be populated with wordpress rewrite rules and conditions.
NOTES --
MySQL:
1.
You may see:
"su: warning: cannot change directory to /nonexistent: No such file or directory"
after running sudo service mysql restart
when you run mysql_secure_installation, you may see:
“Failed! Error: SET PASSWORD has no significance for user ‘root’@’localhost'”
sudo killall -9 mysql_secure_installation
sudo mysql
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'YOUR_PASSWORD';
Allow remote login:
sudo mysql -u root -pMyPassword -e "UPDATE mysql.user SET plugin = 'mysql_native_password' WHERE User = 'root'; FLUSH PRIVILEGES;"
gave the following error/warning:
mysql: [Warning] Using a password on the command line interface can be insecure.
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)
what worked:
sudo mysql -u root -p [press enter, then enter password]
UPDATE mysql.user SET plugin = 'mysql_native_password' WHERE User = 'root'; FLUSH PRIVILEGES;
--- accessing phpmyadmin via web browser ---
copy the phpmyadmin.conf to apache's conf-available directory:
sudo cp /etc/phpmyadmin/apache.conf /etc/apache2/conf-available/phpmyadmin.conf
enable the configuration:
sudo a2enconf phpmyadmin
restart apache2:
sudo service apache2 restart
change the $dbserver value in config-db.php
sudo nano /etc/phpmyadmin/config-db.php
--- change:
$dbserver='localhost';
to
$dbserver='127.0.0.1';
restart apache2:
sudo service apache2 restart
go to localhost/phpmyadmin
you can now login with user: root and the password you set during the phpmyadmin setup