VPS ubuntu apache server - web page - php

I bought a VPS server, where I installed apache, mysql, php and phpmyadmin. I created database (like in my local project).
So, now I want to migrate a local project to my server and please, tell me I am right:
Files .php has to be in folder var/www on my apache server? (here is index.html too) and from this folder connect with database?
I have to download NPM on ubuntu
I have to download GIT on ubuntu
Download repo from my github where I've got whole code (webpack dist files, node modules, src and whole config) to /var/www catalog
index.html has to be in top-level directory (just in var/www not for example var/www/src
Please help me and tell if I am thinking right.

Files .php has to be in folder var/www on my apache server? (here is index.html too) and from this folder connect with database?
It depends on what you set in /etc/apache2/sites-available/000-default.conf. I assume that you installed with default configuration from apt-get.
index.html has to be in top-level directory (just in var/www not for example var/www/src
If for example your source codes are in /var/www/src instead of /var/www, the just modify the 000-default.conf. Example:
<VirtualHost *:80>
ServerAdmin webmaster#localhost
ServerName your_domain_name.com
DocumentRoot /var/www/src/
<Directory />
Options FollowSymLinks
AllowOverride None
Options -Indexes
</Directory>
<Directory /var/www/src>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Require all granted
Options -Indexes
</Directory>
ErrorLog /var/log/your_log_file.log
LogLevel warn
CustomLog /var/log/your_access_log_file.log combined
</VirtualHost>
Restart Apache and try open in your browser to see if it works.
As for the database, since you have phpmyadmin, just export the sql data from your local machine and import it into the VPS phpmyadmin.

Related

XAMPP - How can I execute PHP files from home directory?

I've installed XAMPP on my Linux computer and server and database are running. Now I have a question how to execute my existing PHP-Files from /home path?
So far I have saved all of my PHP files in ./home directory (e.g. /home/Path-to-PHP-Files/Development_01/....php) and until now I have uploaded them with FTP to server. In order to save myself from constant uploading, I thought that usage with XAMPP is faster and more elegant.
I found out that XAMPP apparently wants to save the PHP files in /opt/lampp/htdocs directory. Unfortunately I can neither call my PHP files from .home-directory in browser nor can I copy them to /opt/lampp/htdocs because this path is read-only.
How can I configure XAMPP to make my PHP files run in /home directory?
Change the DocumentRoot in your virtual hosts file, then restart XAMPP. Here is an example:
<VirtualHost *:80>
ServerAdmin webmaster#dummy-host.example.com
DocumentRoot "/home/Path-to-PHP-Files/Development_01/"
ServerName dummy-host.example.com
ServerAlias www.dummy-host.example.com
ErrorLog "logs/dummy-host.example.com-error_log"
CustomLog "logs/dummy-host.example.com-access_log" common
<Directory C:/home/Path-to-PHP-Files/Development_01/> # or a linux path
Order allow,deny
Allow from all
</Directory>
</VirtualHost>

Downloaded Files Are Not Working on Apache DocumentRoot

I'm serving my pages with Apache 2.4 on a Ubuntu Mate OS. I've been building a system that allows my clients to download many files from a directory which has been created by each one of them at the moment they sign in.
Apache DocumentRoot is /var/www/public_html and Downloads process works fine in it but by the time I create a folder CLIENTS (absolute path: /var/www/public_html/CLIENTS/) file downloads arent working as they should. There`s just a message saying "Failed - No File" on incoming files.
I've already changed Directory permissions with chown on Linux, changed masks as well as checked Apache configuration using Directory directives but no results! Apache settings below:
VIRTUAL HOST CONFIGURATION
<Directory /var/www/public_html/CLIENTS/>
Options -Indexes +FollowSymLinks +Multiviews
AllowOverride None
Order allow,deny
allow from all
Require all granted
</Directory>
APACHE2.CONF
<Directory /var/www/public_html/CLIENTS/>
Options Indexes FollowSymLinks
AllowOverride None
Require all granted
</Directory>
LINUX PERMISSIONS
drwxrwxrwx 3 www-data www-data public_html

Dynamic subdomain with .htaccess (centOS)

I have a dedicated server, on which I'm running several project. Lets say this is example.ro.
The server is running CentOS 6.
I've created a unix user 'dev' and a subdomain: dev.example.ro.
Lets say that I want to work on a project called 'cpl', and I have to test it live on this server (it is a php project).
I would like to use the subdomain dev.cpl.example.ro, and on the filesystem it would be under /home/dev/public_html/cpl folder.
How should I modify my .htaccess in the public_html folder in order to dynamically use subdomains?
I don't think you need to edit the .htaccess file to achieve this. But you have to create a separate site in Apache server. To demonstrate I am using am ubuntu lamp server but I think you can do the same on your CentOS.
Create a virtual site in Apache
sudo nano -w /etc/apache2/sites-available/example.conf
paste the following into the file and make necessary changes
<VirtualHost *:80>
ServerName cpl.example.ro
ServerAlias *.cpl.example.ro
DocumentRoot /home/dev/public_html/cpl
<Directory />
#Options FollowSymLinks
Options Indexes FollowSymLinks Includes ExecCGI
AllowOverride All
Require all granted
</Directory>
</VirtualHost>
Save the file. After that you need to enable the newly site.
sudo a2ensite example
service apache2 restart
Edit the host file to resolve the dev.cpl.example.ro
sudo nano -w /etc/hosts
add the following line to the end and save the file
127.0.0.1 dev.cpl.example.ro

MySQL not working with virtualhost

I'm working locally on my Macbook Pro using XAMPP and I'm trying to setup virtualhosts so that I can work on multiple projects more easily.
Everything appears to be working fine except I can't connect to MySQL through PHPMyAdmin and on the XAMPP control panel it says MySQL isn't running. However, I can access MySQL through an application I have in my htdocs folder. When I access phpmyadmin through localhost/phpmyadmin the CSS is loaded and PHPMyAdmin appears to be located, but MySQL can't connect so I'm not quite sure where the issue lies (considering I can connect through my application)
Upon going to localhost/phpmyadmin I get the following error
#2002 - No such file or directory
The server is not responding (or the local server's socket is not correctly configured).
The thing is, I can access the database just fine through the application. I can log in, save and do any other sort of interactions with the database.
Here's what I have in my httpd-vhosts.conf file
NameVirtualHost *:80
<VirtualHost *:80>
DocumentRoot "/Applications/XAMPP/xamppfiles/htdocs/test1"
ServerName localhost
<Directory /Applications/XAMPP/xamppfiles/htdocs/test1>
Options Indexes FollowSymLinks Includes ExecCGI
AllowOverride All
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
<VirtualHost *:80>
ServerName pma
DocumentRoot "/Applications/XAMPP/xamppfiles/phpmyadmin"
<Directory /Applications/XAMPP/xamppfiles/phpmyadmin>
Options FollowSymLinks
DirectoryIndex index.php
<IfModule mod_php5.c>
AddType application/x-httpd-php .php
php_flag magic_quotes_gpc Off
php_flag track_vars On
php_flag register_globals Off
php_value include_path .
</IfModule>
</Directory>
</VirtualHost>
Now for a summary
I set up virtualhosts for apache on my Macbook
The virtualhost setup appears to be working fine for the application I have in my htodcs folder, and it can connect to the database. I can log in, save data and all that stuff.
When I browse to localhost/phpmyadmin I get a MySQL connection error. If I browse to pma/phpmyadmin (the virtualhost I tried to create) Chrome and Firefox just search google for it instead of recognizing the alias (is that the correct term?)
I ran into the same thing with a WAMP server. I solved it by putting back the original "out of the box" server settings:
<VirtualHost *:80>
ServerAdmin webmaster#dummy-host.example.com
DocumentRoot "c:/Apache2/docs/dummy-host.example.com"
ServerName dummy-host.example.com
ServerAlias www.dummy-host.example.com
ErrorLog "logs/dummy-host.example.com-error.log"
CustomLog "logs/dummy-host.example.com-access.log" common
</VirtualHost>
And then for each project used code such as:
<VirtualHost *:80>
ServerAdmin admin#localhost
DocumentRoot "C:/wamp/projectname"
ServerName localhost
ServerAlias projectname.here
<Directory "C:/wamp/projectname">
Options Indexes FollowSymLinks Includes ExecCGI
AllowOverride None
Order allow,deny
Allow from all # <-- used for Apache 2.2
#Require all granted #<-- used for Apache 2.4+
</Directory>
</VirtualHost>
For different projects, just duplicate the last set of code for each project, renaming the DocumentRoot, ServerAlias and Directory path. You will notice the "ServerAlias" line; this is what made Apache serve up the project when entering the alias in the web browser. I found the explanation here which ironically was in the httpd-vhosts.conf file.
Also, please note that my research recommends for higher versions of Apache to use Require all granted in place of Allow from all as commented in the code above.
All of this code is in the httpd-vhosts.conf file, which on my Windows 7 installation is at c:\wamp\bin\apache\Apache2.2.21\conf\extra directory. Since you are using a Macbook and have already identified the location, I just put this in for other's reference.

XAMPP for Mac rewriting issue when using virtual hosts

I'm not sure what's going on here, I'm far more used to a Windows XAMPP environment, so this is all a bit new to me. Long story short, I'm having some trouble getting a virtual host on XAMPP to correctly show the document root's contents.
I set the httpd.conf in the XAMPP folder to include the extra/httpd-vhosts.conf file, and I set my virtual host as follows:
<VirtualHost 127.0.0.1>
ServerName spacexstats
DocumentRoot "/Volumes/PATRIOT 32/spacexstats”
<Directory "/Volumes/PATRIOT 32/spacexstats”>
Options Indexes FollowSymLinks Includes ExecCGI AddType text/shtml .shtml
AddOutputFilter INCLUDES .shtml
AllowOverride All
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
From here, I added this to my hosts list in etc/hosts by setting:
127.0.0.1 spacexstats
Upon restarting XAMPP, I attempt to navigate to spacexstats in my browser (have cleared the cache), but instead of being delivered my expected index.php file, I'm redirected to spacexstats/xampp which is essentially the XAMPP splash screen.
Any ideas?

Categories