Skip to content

Instantly share code, notes, and snippets.

@huzaifa-a
Last active August 30, 2022 14:08
Show Gist options
  • Save huzaifa-a/377c95e94824c3d8cbd7ec544da6d659 to your computer and use it in GitHub Desktop.
Save huzaifa-a/377c95e94824c3d8cbd7ec544da6d659 to your computer and use it in GitHub Desktop.
Setup apache2 on Ubuntu

Apache2

sudo apt-get update
sudo apt-get install apache2

reinstall apache2

sudo apt-get --purge remove apache2*
sudo apt-get --purge autoremove
sudo apt-get install apache2

Check to make sure you have mod_rewrite enabled.

sudo a2enmod rewrite
sudo cp /etc/apache2/sites-available/000-default.conf /etc/apache2/sites-available/subdomain.conf
sudo gedit /etc/apache2/sites-available/subdomain.conf

# $HOME$/www dir permision
sudo usermod -a -G www-data (your username)
sudo chgrp www-data /home/huzaifa/www
sudo chmod g+rwxs /home/huzaifa/www
<VirtualHost *:80>
   ServerAdmin admin@localhost
   ServerName  localhost
   DocumentRoot /home/huzaifa/www
	<Directory /home/huzaifa/www/>
		Options Indexes FollowSymLinks
		AllowOverride All
		Require all granted
	</Directory>
</VirtualHost>
<VirtualHost *:80>
	ServerAdmin admin@localhost
	ServerName longnameyoullneveruse.blabla.localhost
	ServerAlias *.*
	DocumentRoot /home/huzaifa/www

	<Directory /home/huzaifa/www/>
		Options Indexes FollowSymLinks
		AllowOverride All
		Require all granted
	</Directory>


	ErrorLog ${APACHE_LOG_DIR}/error.log
	CustomLog ${APACHE_LOG_DIR}/access.log combined
	RewriteEngine On
	RewriteMap lowercase int:tolower
	RewriteCond %{HTTP_HOST} ^(.*)\.(localhost|test)$
	RewriteRule ^(.*)$ "/home/huzaifa/www/${lowercase:%1}/$1"
	# you should use all lowercase for subfolders' name

</VirtualHost>
# vim: syntax=apache ts=4 sw=4 sts=4 sr noet
sudo a2ensite subdomain.conf
sudo a2dissite 000-default.conf
sudo systemctl restart apache2
sudo service apache2 restart

Enable dnsmasq in NetworkManager

Edit the file /etc/NetworkManager/NetworkManager.conf, and add the line dns=dnsmasq to the [main] section, it will look like this :

[main]
plugins=ifupdown,keyfile
dns=dnsmasq

[ifupdown]
managed=false

[device]
wifi.scan-rand-mac-address=no
Let NetworkManager manage /etc/resolv.conf

sudo rm /etc/resolv.conf ; sudo ln -s /var/run/NetworkManager/resolv.conf /etc/resolv.conf
Configure test

echo 'address=/.test/127.0.0.1' | sudo tee /etc/NetworkManager/dnsmasq.d/example.com-wildcard.conf
Reload NetworkManager and testing

NetworkManager should be reloaded for the changes to take effect.

sudo systemctl reload NetworkManager
Then we can verify that we can reach some usual site :

dig askubuntu.com +short
151.101.129.69
151.101.65.69
151.101.1.69
151.101.193.69
And lastly verify that the test and subdomains are resolved as 127.0.0.1:

dig test askubuntu.test a.b.c.d.test +short
127.0.0.1
127.0.0.1
127.0.0.1
 

Php

Add multiple php repository

sudo add-apt-repository ppa:ondrej/php
apt update

#install php sudo apt install php7.2 php7.1 php5.6

php extensions

sudo apt-get install php5.6-curl php5.6-mbstring php5.6-mcrypt php5.6-xml php5.6-zip php5.6-mysql
sudo apt-get install php7.1-curl php7.1-mbstring php7.1-mcrypt php7.1-xml php7.1-zip php7.1-mysql
sudo apt-get install php7.2-curl php7.2-mbstring php7.2-xml php7.2-zip php7.2-mysql



//Setting up xdebug
sudo apt-get install php5.6-xdebug
php -i | grep xdebug
php -m | grep xdebug

//edit xdebug ini file
sudo gedit /etc/php/5.6/cli/conf.d/20-xdebug.ini

[xdebug]
zend_extension="/usr/local/opt/php71-xdebug/xdebug.so"
xdebug.remote_autostart=1
xdebug.default_enable=1
xdebug.remote_port=9001
xdebug.remote_host=127.0.0.1
xdebug.remote_connect_back=1
xdebug.remote_enable=1
xdebug.idekey=PHPSTORM


//PHPstorm setting
Language $ Frameworks > PHP > Debug
Check Break at first linne in PHP scripts
Debug port: 9001

Language $ Frameworks > PHP > Debug > DBGp Proxy
IDE Key: PHPSTORM
//Start listning to PHP debug connection
BashCopy

Change php version through cmd

touch custom_bash.sh sudo gedit custom_bash.sh

#!/bin/bash

php_env () {
sudo a2dismod php*

sudo a2enmod php$1

sudo update-alternatives --set php /usr/bin/php$1
sudo systemctl restart apache2
}

sudo gedit .bashrc //past source ~/custom_bash.sh

source .bashrc //run command php_env 7.2

Mysql //install mysql sudo apt-get install mariadb-server //mysql -uroot without sudo

sudo mysql -uroot
MariaDB [(none)]> use mysql
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
MariaDB [mysql]> update user set plugin='' where User='root';
Query OK, 1 row affected (0.00 sec)
Rows matched: 1  Changed: 1  Warnings: 0

MariaDB [mysql]> flush privileges;
Query OK, 0 rows affected (0.00 sec)

MariaDB [mysql]> \q
SQLCopy
 

Composer
//remove previous composer
sudo apt-get purge --auto-remove composer

//install composer with php5.6 so you can run valet-linux in php5.6
curl -sS https://getcomposer.org/installer | sudo php -- --install-dir=/usr/local/bin --filename=composer
sudo chown -R $USER ~/.composer/

//Speed up composer
composer global require "squizlabs/php_codesniffer=*" -vvv
composer config --global repo.packagist composer https://packagist.org

//composer env variable
echo 'export PATH="$PATH:$HOME/.composer/vendor/bin"' >> ~/.bashrc
source ~/.bashrc
BashCopy

Phpmyadmin

composer create-project phpmyadmin/phpmyadmin https://docs.phpmyadmin.net/en/latest/setup.html#installing-using-composer

gedit ~/www/phpmyadmin/libraries/config.default.php
$cfg['Servers'][$i]['AllowNoPassword'] = true;
$cfg['ExecTimeLimit'] = 3600;
$cfg['Servers'][$i]['auth_type'] = 'config';
 

Wordpress cli

curl -O https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar
php wp-cli.phar --info
chmod +x wp-cli.phar
sudo mv wp-cli.phar /usr/local/bin/wp
wp --info
@ans1
Copy link

ans1 commented Mar 17, 2021

What a documentation. I have to create like this one.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment