Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/antick/vps-setup
Set up a dev environment on Ubuntu for PHP and node
https://github.com/antick/vps-setup
mysql php phpmyadmin
Last synced: 2 months ago
JSON representation
Set up a dev environment on Ubuntu for PHP and node
- Host: GitHub
- URL: https://github.com/antick/vps-setup
- Owner: antick
- License: mit
- Created: 2020-02-05T14:02:09.000Z (almost 5 years ago)
- Default Branch: master
- Last Pushed: 2023-12-09T09:44:34.000Z (about 1 year ago)
- Last Synced: 2024-11-11T02:07:14.675Z (2 months ago)
- Topics: mysql, php, phpmyadmin
- Language: Shell
- Homepage:
- Size: 27.3 KB
- Stars: 2
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# PHP Dev Env Setup for Laravel
Setup a dev environment on Ubuntu for PHP and node.
## Setup Dev Environment
Run the updates-
```bash
sudo apt updatesudo apt upgrade
```### Apache2
Install and start apache2-
```bash
sudo apt install apache2sudo systemctl enable apache2
sudo systemctl start apache2
```Check if the apache2 is running now or not-
```bash
sudo systemctl status apache2
```If it's not running then figure out the cause by checking its config-
```bash
apache2ctl configtest
```If you have upgraded your system and your PHP version was upgraded then this might cause the issue. You can fix that by disabling the old PHP and enable the new PHP in configuration. Do this only if this is the case otherwise skip this-
```bash
sudo a2dismod php7.3
sudo a2enmod php7.4
```Enable rewrite module in apache2-
```bash
sudo a2enmod rewritesudo systemctl restart apache2
```### MySQL
Install and setup database-
```bash
sudo apt install mysql-serversudo mysql_secure_installation
sudo systemctl status mysql
```Login into mysql-
```bash
mysql -u root -p
```If the above does not work then try logging in with sudo-
```bash
sudo mysql -u root
```Now set a password for root here in mysql terminal-
```bash
ALTER USER 'root'@'localhost' IDENTIFIED BY 'new_password';
```In case it still does not work then switch to mysql db in mysql terminal and check the user table. Make sure it uses the native password plugin.
```bash
mysql -uroot -p
SELECT user,authentication_string,plugin,host FROM mysql.user;
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'your_mysql_pass';
FLUSH PRIVILEGES;
SELECT user,authentication_string,plugin,host FROM mysql.user;
```Once this is enabled, you would be able to access PHPmyadmin. If you want to access database remotely then you will have to create a new user from phpmyadmin.
Make sure to comment bind address in this file so it can connect remotely-
`nano /etc/mysql/mysql.conf.d/mysqld.cnf`
### PHP
In case you have two PHP versions installed then you can remove the extra one by this command-
```bash
sudo apt purge php7.3*
```Install PHP 7.4-
```bash
sudo apt install php7.4 \
php7.4-bcmath \
php7.4-cli \
php7.4-common \
php7.4-curl \
php7.4-gd \
php7.4-intl \
php7.4-json \
php7.4-mbstring \
php7.4-mysql \
php7.4-opcache \
php7.4-soap \
php7.4-xml \
php7.4-zip
```Test the PHP-
```bash
cd /var/www/htmlsudo nano info.php
```Write this in info.php and run it to check if everything is working fine-
```php
#ServerName www.example.com
ServerAdmin webmaster@localhost
DocumentRoot /var/www
Options Indexes FollowSymLinks Includes
AllowOverride All
Order allow,deny
Allow from all
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combinedServerName 123.123.123.123
Alias /project-one /var/www/project-one/public
Alias /project-two /var/www/project-two/publicDocumentRoot /var/www/project-one/public
AllowOverride all
Order allow,deny
Allow from all
DocumentRoot /var/www/project-two/public
AllowOverride all
Order allow,deny
Allow from all
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined```
Change in your /var/www/project-one/public/.htaccess
```
RewriteEngine On
RewriteBase /project-one/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]```
### Virtual Host Setup in Local
```
ServerAdmin webmaster@localhost
ServerName localhost
DocumentRoot /var/www
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combinedServerAdmin webmaster@localhost
ServerName my-project.local
DocumentRoot /var/www/my-project/public
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined```
### Virutal Host Setup in Nginx
```
server {
listen 80;
server_name www.my-domain.com;
rewrite ^(.*) http://my-domain.com$1 permanent;
}server {
listen 80 default_server;
server_name my-domain.com;
root /var/www/my-project/public;
index index.php index.html index.htm;
location / {
try_files $uri $uri/ /index.php?$query_string;
}location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/run/php/php7.3-fpm.sock;
}location ~ /\.ht {
deny all;
}
}
```